* [gentoo-commits] proj/portage:plugin-sync commit in: pym/portage/tests/sync/
@ 2014-10-22 12:11 Zac Medico
0 siblings, 0 replies; 4+ messages in thread
From: Zac Medico @ 2014-10-22 12:11 UTC (permalink / raw
To: gentoo-commits
commit: a8fcba31e0eada1048d69d0f8c507e6362614af2
Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Wed Oct 22 12:10:53 2014 +0000
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Wed Oct 22 12:10:53 2014 +0000
URL: http://sources.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=a8fcba31
Test sync with rsync and git, using file:// uri
---
pym/portage/tests/sync/__init__.py | 2 +
pym/portage/tests/sync/__test__.py | 0
pym/portage/tests/sync/test_sync_local.py | 186 ++++++++++++++++++++++++++++++
3 files changed, 188 insertions(+)
diff --git a/pym/portage/tests/sync/__init__.py b/pym/portage/tests/sync/__init__.py
new file mode 100644
index 0000000..7cd880e
--- /dev/null
+++ b/pym/portage/tests/sync/__init__.py
@@ -0,0 +1,2 @@
+# Copyright 2014 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
diff --git a/pym/portage/tests/sync/__test__.py b/pym/portage/tests/sync/__test__.py
new file mode 100644
index 0000000..e69de29
diff --git a/pym/portage/tests/sync/test_sync_local.py b/pym/portage/tests/sync/test_sync_local.py
new file mode 100644
index 0000000..ace3918
--- /dev/null
+++ b/pym/portage/tests/sync/test_sync_local.py
@@ -0,0 +1,186 @@
+# Copyright 2014 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+import subprocess
+import sys
+import textwrap
+import time
+
+import portage
+from portage import os, shutil
+from portage import _unicode_decode
+from portage.const import PORTAGE_PYM_PATH, TIMESTAMP_FORMAT
+from portage.process import find_binary
+from portage.tests import TestCase
+from portage.tests.resolver.ResolverPlayground import ResolverPlayground
+from portage.util import ensure_dirs
+
+class SyncLocalTestCase(TestCase):
+ """
+ Test sync with rsync and git, using file:// sync-uri.
+ """
+
+ def _must_skip(self):
+ if find_binary("rsync") is None:
+ return "rsync: command not found"
+ if find_binary("git") is None:
+ return "git: command not found"
+
+ def testSyncLocal(self):
+ debug = False
+
+ skip_reason = self._must_skip()
+ if skip_reason:
+ self.portage_skip = skip_reason
+ self.assertFalse(True, skip_reason)
+ return
+
+ repos_conf = textwrap.dedent("""
+ [test_repo]
+ location = %(EPREFIX)s/var/repositories/test_repo
+ sync-type = %(sync-type)s
+ sync-uri = file:/%(EPREFIX)s/var/repositories/test_repo_sync
+ auto-sync = yes
+ """)
+
+ profile = {
+ "eapi": ("5",),
+ "package.use.stable.mask": ("dev-libs/A flag",)
+ }
+
+ ebuilds = {
+ "dev-libs/A-0": {}
+ }
+
+ playground = ResolverPlayground(ebuilds=ebuilds,
+ profile=profile, user_config={}, debug=debug)
+ settings = playground.settings
+ eprefix = settings["EPREFIX"]
+ eroot = settings["EROOT"]
+ homedir = os.path.join(eroot, "home")
+ distdir = os.path.join(eprefix, "distdir")
+ repo = settings.repositories["test_repo"]
+ metadata_dir = os.path.join(repo.location, "metadata")
+
+ cmds = {}
+ for cmd in ("emerge", "emaint"):
+ cmds[cmd] = (portage._python_interpreter,
+ "-b", "-Wd", os.path.join(self.bindir, cmd))
+
+ git_binary = find_binary("git")
+ git_cmd = (git_binary,)
+
+ committer_name = "Gentoo Dev"
+ committer_email = "gentoo-dev@gentoo.org"
+
+ def change_sync_type(sync_type):
+ env["PORTAGE_REPOSITORIES"] = repos_conf % \
+ {"EPREFIX": eprefix, "sync-type": sync_type}
+
+ sync_cmds = (
+ (homedir, cmds["emerge"] + ("--sync",)),
+ (homedir, cmds["emaint"] + ("sync", "-A")),
+ )
+
+ rename_repo = (
+ (homedir, lambda: os.rename(repo.location,
+ repo.location + "_sync")),
+ )
+
+ delete_sync_repo = (
+ (homedir, lambda: shutil.rmtree(
+ repo.location + "_sync")),
+ )
+
+ git_repo_create = (
+ (repo.location, git_cmd +
+ ("config", "--global", "user.name", committer_name,)),
+ (repo.location, git_cmd +
+ ("config", "--global", "user.email", committer_email,)),
+ (repo.location, git_cmd + ("init-db",)),
+ (repo.location, git_cmd + ("add", ".")),
+ (repo.location, git_cmd +
+ ("commit", "-a", "-m", "add whole repo")),
+ )
+
+ sync_type_git = (
+ (homedir, lambda: change_sync_type("git")),
+ )
+
+ pythonpath = os.environ.get("PYTHONPATH")
+ if pythonpath is not None and not pythonpath.strip():
+ pythonpath = None
+ if pythonpath is not None and \
+ pythonpath.split(":")[0] == PORTAGE_PYM_PATH:
+ pass
+ else:
+ if pythonpath is None:
+ pythonpath = ""
+ else:
+ pythonpath = ":" + pythonpath
+ pythonpath = PORTAGE_PYM_PATH + pythonpath
+
+ env = {
+ "PORTAGE_OVERRIDE_EPREFIX" : eprefix,
+ "DISTDIR" : distdir,
+ "GENTOO_COMMITTER_NAME" : committer_name,
+ "GENTOO_COMMITTER_EMAIL" : committer_email,
+ "HOME" : homedir,
+ "PATH" : os.environ["PATH"],
+ "PORTAGE_GRPNAME" : os.environ["PORTAGE_GRPNAME"],
+ "PORTAGE_USERNAME" : os.environ["PORTAGE_USERNAME"],
+ "PORTAGE_REPOSITORIES" : repos_conf %
+ {"EPREFIX": eprefix, "sync-type": "rsync"},
+ "PYTHONPATH" : pythonpath,
+ }
+
+ if os.environ.get("SANDBOX_ON") == "1":
+ # avoid problems from nested sandbox instances
+ env["FEATURES"] = "-sandbox -usersandbox"
+
+ dirs = [homedir, metadata_dir]
+ try:
+ for d in dirs:
+ ensure_dirs(d)
+
+ timestamp_path = os.path.join(metadata_dir, 'timestamp.chk')
+ with open(timestamp_path, 'w') as f:
+ f.write(time.strftime('%s\n' % TIMESTAMP_FORMAT, time.gmtime()))
+
+ if debug:
+ # The subprocess inherits both stdout and stderr, for
+ # debugging purposes.
+ stdout = None
+ else:
+ # The subprocess inherits stderr so that any warnings
+ # triggered by python -Wd will be visible.
+ stdout = subprocess.PIPE
+
+ for cwd, cmd in rename_repo + sync_cmds + \
+ delete_sync_repo + git_repo_create + sync_type_git + \
+ rename_repo + sync_cmds:
+
+ if hasattr(cmd, '__call__'):
+ cmd()
+ continue
+
+ abs_cwd = os.path.join(repo.location, cwd)
+ proc = subprocess.Popen(cmd,
+ cwd=abs_cwd, env=env, stdout=stdout)
+
+ if debug:
+ proc.wait()
+ else:
+ output = proc.stdout.readlines()
+ proc.wait()
+ proc.stdout.close()
+ if proc.returncode != os.EX_OK:
+ for line in output:
+ sys.stderr.write(_unicode_decode(line))
+
+ self.assertEqual(os.EX_OK, proc.returncode,
+ "%s failed in %s" % (cmd, cwd,))
+
+
+ finally:
+ playground.cleanup()
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [gentoo-commits] proj/portage:plugin-sync commit in: pym/portage/tests/sync/
@ 2014-10-22 13:36 Zac Medico
0 siblings, 0 replies; 4+ messages in thread
From: Zac Medico @ 2014-10-22 13:36 UTC (permalink / raw
To: gentoo-commits
commit: 85b4c59acc08931239681ef79b0bef939ffd9f8e
Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Wed Oct 22 13:35:07 2014 +0000
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Wed Oct 22 13:35:07 2014 +0000
URL: http://sources.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=85b4c59a
Test sync with rsync and git, using file:// uri
---
pym/portage/tests/sync/__init__.py | 2 +
pym/portage/tests/sync/test_sync_local.py | 189 ++++++++++++++++++++++++++++++
2 files changed, 191 insertions(+)
diff --git a/pym/portage/tests/sync/__init__.py b/pym/portage/tests/sync/__init__.py
new file mode 100644
index 0000000..7cd880e
--- /dev/null
+++ b/pym/portage/tests/sync/__init__.py
@@ -0,0 +1,2 @@
+# Copyright 2014 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
diff --git a/pym/portage/tests/sync/test_sync_local.py b/pym/portage/tests/sync/test_sync_local.py
new file mode 100644
index 0000000..65c20f8
--- /dev/null
+++ b/pym/portage/tests/sync/test_sync_local.py
@@ -0,0 +1,189 @@
+# Copyright 2014 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+import subprocess
+import sys
+import textwrap
+import time
+
+import portage
+from portage import os, shutil
+from portage import _unicode_decode
+from portage.const import PORTAGE_PYM_PATH, TIMESTAMP_FORMAT
+from portage.process import find_binary
+from portage.tests import TestCase
+from portage.tests.resolver.ResolverPlayground import ResolverPlayground
+from portage.util import ensure_dirs
+
+class SyncLocalTestCase(TestCase):
+ """
+ Test sync with rsync and git, using file:// sync-uri.
+ """
+
+ def _must_skip(self):
+ if find_binary("rsync") is None:
+ return "rsync: command not found"
+ if find_binary("git") is None:
+ return "git: command not found"
+
+ def testSyncLocal(self):
+ debug = False
+
+ skip_reason = self._must_skip()
+ if skip_reason:
+ self.portage_skip = skip_reason
+ self.assertFalse(True, skip_reason)
+ return
+
+ repos_conf = textwrap.dedent("""
+ [test_repo]
+ location = %(EPREFIX)s/var/repositories/test_repo
+ sync-type = %(sync-type)s
+ sync-uri = file:/%(EPREFIX)s/var/repositories/test_repo_sync
+ auto-sync = yes
+ """)
+
+ profile = {
+ "eapi": ("5",),
+ "package.use.stable.mask": ("dev-libs/A flag",)
+ }
+
+ ebuilds = {
+ "dev-libs/A-0": {}
+ }
+
+ playground = ResolverPlayground(ebuilds=ebuilds,
+ profile=profile, user_config={}, debug=debug)
+ settings = playground.settings
+ eprefix = settings["EPREFIX"]
+ eroot = settings["EROOT"]
+ homedir = os.path.join(eroot, "home")
+ distdir = os.path.join(eprefix, "distdir")
+ repo = settings.repositories["test_repo"]
+ metadata_dir = os.path.join(repo.location, "metadata")
+
+ cmds = {}
+ for cmd in ("emerge", "emaint"):
+ cmds[cmd] = (portage._python_interpreter,
+ "-b", "-Wd", os.path.join(self.bindir, cmd))
+
+ git_binary = find_binary("git")
+ git_cmd = (git_binary,)
+
+ committer_name = "Gentoo Dev"
+ committer_email = "gentoo-dev@gentoo.org"
+
+ def change_sync_type(sync_type):
+ env["PORTAGE_REPOSITORIES"] = repos_conf % \
+ {"EPREFIX": eprefix, "sync-type": sync_type}
+
+ sync_cmds = (
+ (homedir, cmds["emerge"] + ("--sync",)),
+ (homedir, lambda: self.assertTrue(os.path.exists(
+ os.path.join(repo.location, "dev-libs", "A")
+ ), "dev-libs/A expected, but missing")),
+ (homedir, cmds["emaint"] + ("sync", "-A")),
+ )
+
+ rename_repo = (
+ (homedir, lambda: os.rename(repo.location,
+ repo.location + "_sync")),
+ )
+
+ delete_sync_repo = (
+ (homedir, lambda: shutil.rmtree(
+ repo.location + "_sync")),
+ )
+
+ git_repo_create = (
+ (repo.location, git_cmd +
+ ("config", "--global", "user.name", committer_name,)),
+ (repo.location, git_cmd +
+ ("config", "--global", "user.email", committer_email,)),
+ (repo.location, git_cmd + ("init-db",)),
+ (repo.location, git_cmd + ("add", ".")),
+ (repo.location, git_cmd +
+ ("commit", "-a", "-m", "add whole repo")),
+ )
+
+ sync_type_git = (
+ (homedir, lambda: change_sync_type("git")),
+ )
+
+ pythonpath = os.environ.get("PYTHONPATH")
+ if pythonpath is not None and not pythonpath.strip():
+ pythonpath = None
+ if pythonpath is not None and \
+ pythonpath.split(":")[0] == PORTAGE_PYM_PATH:
+ pass
+ else:
+ if pythonpath is None:
+ pythonpath = ""
+ else:
+ pythonpath = ":" + pythonpath
+ pythonpath = PORTAGE_PYM_PATH + pythonpath
+
+ env = {
+ "PORTAGE_OVERRIDE_EPREFIX" : eprefix,
+ "DISTDIR" : distdir,
+ "GENTOO_COMMITTER_NAME" : committer_name,
+ "GENTOO_COMMITTER_EMAIL" : committer_email,
+ "HOME" : homedir,
+ "PATH" : os.environ["PATH"],
+ "PORTAGE_GRPNAME" : os.environ["PORTAGE_GRPNAME"],
+ "PORTAGE_USERNAME" : os.environ["PORTAGE_USERNAME"],
+ "PORTAGE_REPOSITORIES" : repos_conf %
+ {"EPREFIX": eprefix, "sync-type": "rsync"},
+ "PYTHONPATH" : pythonpath,
+ }
+
+ if os.environ.get("SANDBOX_ON") == "1":
+ # avoid problems from nested sandbox instances
+ env["FEATURES"] = "-sandbox -usersandbox"
+
+ dirs = [homedir, metadata_dir]
+ try:
+ for d in dirs:
+ ensure_dirs(d)
+
+ timestamp_path = os.path.join(metadata_dir, 'timestamp.chk')
+ with open(timestamp_path, 'w') as f:
+ f.write(time.strftime('%s\n' % TIMESTAMP_FORMAT, time.gmtime()))
+
+ if debug:
+ # The subprocess inherits both stdout and stderr, for
+ # debugging purposes.
+ stdout = None
+ else:
+ # The subprocess inherits stderr so that any warnings
+ # triggered by python -Wd will be visible.
+ stdout = subprocess.PIPE
+
+ for cwd, cmd in rename_repo + sync_cmds + \
+ delete_sync_repo + git_repo_create + sync_type_git + \
+ rename_repo + sync_cmds:
+
+ if hasattr(cmd, '__call__'):
+ cmd()
+ continue
+
+ abs_cwd = os.path.join(repo.location, cwd)
+ proc = subprocess.Popen(cmd,
+ cwd=abs_cwd, env=env, stdout=stdout)
+
+ if debug:
+ proc.wait()
+ else:
+ output = proc.stdout.readlines()
+ proc.wait()
+ proc.stdout.close()
+ if proc.returncode != os.EX_OK:
+ for line in output:
+ sys.stderr.write(_unicode_decode(line))
+
+ self.assertEqual(os.EX_OK, proc.returncode,
+ "%s failed in %s" % (cmd, cwd,))
+
+
+ finally:
+ playground.cleanup()
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [gentoo-commits] proj/portage:plugin-sync commit in: pym/portage/tests/sync/
@ 2014-12-01 21:50 Michał Górny
0 siblings, 0 replies; 4+ messages in thread
From: Michał Górny @ 2014-12-01 21:50 UTC (permalink / raw
To: gentoo-commits
commit: cd5a733bfe61c2814730771d1e6b5b3ba4508a37
Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Wed Oct 22 13:35:07 2014 +0000
Commit: Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Mon Dec 1 21:49:42 2014 +0000
URL: http://sources.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=cd5a733b
Test sync with rsync and git, using file:// uri
---
pym/portage/tests/sync/__init__.py | 2 +
pym/portage/tests/sync/test_sync_local.py | 189 ++++++++++++++++++++++++++++++
2 files changed, 191 insertions(+)
diff --git a/pym/portage/tests/sync/__init__.py b/pym/portage/tests/sync/__init__.py
new file mode 100644
index 0000000..7cd880e
--- /dev/null
+++ b/pym/portage/tests/sync/__init__.py
@@ -0,0 +1,2 @@
+# Copyright 2014 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
diff --git a/pym/portage/tests/sync/test_sync_local.py b/pym/portage/tests/sync/test_sync_local.py
new file mode 100644
index 0000000..65c20f8
--- /dev/null
+++ b/pym/portage/tests/sync/test_sync_local.py
@@ -0,0 +1,189 @@
+# Copyright 2014 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+import subprocess
+import sys
+import textwrap
+import time
+
+import portage
+from portage import os, shutil
+from portage import _unicode_decode
+from portage.const import PORTAGE_PYM_PATH, TIMESTAMP_FORMAT
+from portage.process import find_binary
+from portage.tests import TestCase
+from portage.tests.resolver.ResolverPlayground import ResolverPlayground
+from portage.util import ensure_dirs
+
+class SyncLocalTestCase(TestCase):
+ """
+ Test sync with rsync and git, using file:// sync-uri.
+ """
+
+ def _must_skip(self):
+ if find_binary("rsync") is None:
+ return "rsync: command not found"
+ if find_binary("git") is None:
+ return "git: command not found"
+
+ def testSyncLocal(self):
+ debug = False
+
+ skip_reason = self._must_skip()
+ if skip_reason:
+ self.portage_skip = skip_reason
+ self.assertFalse(True, skip_reason)
+ return
+
+ repos_conf = textwrap.dedent("""
+ [test_repo]
+ location = %(EPREFIX)s/var/repositories/test_repo
+ sync-type = %(sync-type)s
+ sync-uri = file:/%(EPREFIX)s/var/repositories/test_repo_sync
+ auto-sync = yes
+ """)
+
+ profile = {
+ "eapi": ("5",),
+ "package.use.stable.mask": ("dev-libs/A flag",)
+ }
+
+ ebuilds = {
+ "dev-libs/A-0": {}
+ }
+
+ playground = ResolverPlayground(ebuilds=ebuilds,
+ profile=profile, user_config={}, debug=debug)
+ settings = playground.settings
+ eprefix = settings["EPREFIX"]
+ eroot = settings["EROOT"]
+ homedir = os.path.join(eroot, "home")
+ distdir = os.path.join(eprefix, "distdir")
+ repo = settings.repositories["test_repo"]
+ metadata_dir = os.path.join(repo.location, "metadata")
+
+ cmds = {}
+ for cmd in ("emerge", "emaint"):
+ cmds[cmd] = (portage._python_interpreter,
+ "-b", "-Wd", os.path.join(self.bindir, cmd))
+
+ git_binary = find_binary("git")
+ git_cmd = (git_binary,)
+
+ committer_name = "Gentoo Dev"
+ committer_email = "gentoo-dev@gentoo.org"
+
+ def change_sync_type(sync_type):
+ env["PORTAGE_REPOSITORIES"] = repos_conf % \
+ {"EPREFIX": eprefix, "sync-type": sync_type}
+
+ sync_cmds = (
+ (homedir, cmds["emerge"] + ("--sync",)),
+ (homedir, lambda: self.assertTrue(os.path.exists(
+ os.path.join(repo.location, "dev-libs", "A")
+ ), "dev-libs/A expected, but missing")),
+ (homedir, cmds["emaint"] + ("sync", "-A")),
+ )
+
+ rename_repo = (
+ (homedir, lambda: os.rename(repo.location,
+ repo.location + "_sync")),
+ )
+
+ delete_sync_repo = (
+ (homedir, lambda: shutil.rmtree(
+ repo.location + "_sync")),
+ )
+
+ git_repo_create = (
+ (repo.location, git_cmd +
+ ("config", "--global", "user.name", committer_name,)),
+ (repo.location, git_cmd +
+ ("config", "--global", "user.email", committer_email,)),
+ (repo.location, git_cmd + ("init-db",)),
+ (repo.location, git_cmd + ("add", ".")),
+ (repo.location, git_cmd +
+ ("commit", "-a", "-m", "add whole repo")),
+ )
+
+ sync_type_git = (
+ (homedir, lambda: change_sync_type("git")),
+ )
+
+ pythonpath = os.environ.get("PYTHONPATH")
+ if pythonpath is not None and not pythonpath.strip():
+ pythonpath = None
+ if pythonpath is not None and \
+ pythonpath.split(":")[0] == PORTAGE_PYM_PATH:
+ pass
+ else:
+ if pythonpath is None:
+ pythonpath = ""
+ else:
+ pythonpath = ":" + pythonpath
+ pythonpath = PORTAGE_PYM_PATH + pythonpath
+
+ env = {
+ "PORTAGE_OVERRIDE_EPREFIX" : eprefix,
+ "DISTDIR" : distdir,
+ "GENTOO_COMMITTER_NAME" : committer_name,
+ "GENTOO_COMMITTER_EMAIL" : committer_email,
+ "HOME" : homedir,
+ "PATH" : os.environ["PATH"],
+ "PORTAGE_GRPNAME" : os.environ["PORTAGE_GRPNAME"],
+ "PORTAGE_USERNAME" : os.environ["PORTAGE_USERNAME"],
+ "PORTAGE_REPOSITORIES" : repos_conf %
+ {"EPREFIX": eprefix, "sync-type": "rsync"},
+ "PYTHONPATH" : pythonpath,
+ }
+
+ if os.environ.get("SANDBOX_ON") == "1":
+ # avoid problems from nested sandbox instances
+ env["FEATURES"] = "-sandbox -usersandbox"
+
+ dirs = [homedir, metadata_dir]
+ try:
+ for d in dirs:
+ ensure_dirs(d)
+
+ timestamp_path = os.path.join(metadata_dir, 'timestamp.chk')
+ with open(timestamp_path, 'w') as f:
+ f.write(time.strftime('%s\n' % TIMESTAMP_FORMAT, time.gmtime()))
+
+ if debug:
+ # The subprocess inherits both stdout and stderr, for
+ # debugging purposes.
+ stdout = None
+ else:
+ # The subprocess inherits stderr so that any warnings
+ # triggered by python -Wd will be visible.
+ stdout = subprocess.PIPE
+
+ for cwd, cmd in rename_repo + sync_cmds + \
+ delete_sync_repo + git_repo_create + sync_type_git + \
+ rename_repo + sync_cmds:
+
+ if hasattr(cmd, '__call__'):
+ cmd()
+ continue
+
+ abs_cwd = os.path.join(repo.location, cwd)
+ proc = subprocess.Popen(cmd,
+ cwd=abs_cwd, env=env, stdout=stdout)
+
+ if debug:
+ proc.wait()
+ else:
+ output = proc.stdout.readlines()
+ proc.wait()
+ proc.stdout.close()
+ if proc.returncode != os.EX_OK:
+ for line in output:
+ sys.stderr.write(_unicode_decode(line))
+
+ self.assertEqual(os.EX_OK, proc.returncode,
+ "%s failed in %s" % (cmd, cwd,))
+
+
+ finally:
+ playground.cleanup()
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [gentoo-commits] proj/portage:plugin-sync commit in: pym/portage/tests/sync/
2014-12-04 20:16 [gentoo-commits] proj/portage:master " Brian Dolbec
@ 2014-12-04 20:04 ` Brian Dolbec
0 siblings, 0 replies; 4+ messages in thread
From: Brian Dolbec @ 2014-12-04 20:04 UTC (permalink / raw
To: gentoo-commits
commit: 007a97b0330ce7b6f8ad60246114251ea46a2221
Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Wed Oct 22 13:35:07 2014 +0000
Commit: Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
CommitDate: Thu Dec 4 19:56:36 2014 +0000
URL: http://sources.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=007a97b0
Test sync with rsync and git, using file:// uri
---
pym/portage/tests/sync/__init__.py | 2 +
pym/portage/tests/sync/test_sync_local.py | 189 ++++++++++++++++++++++++++++++
2 files changed, 191 insertions(+)
diff --git a/pym/portage/tests/sync/__init__.py b/pym/portage/tests/sync/__init__.py
new file mode 100644
index 0000000..7cd880e
--- /dev/null
+++ b/pym/portage/tests/sync/__init__.py
@@ -0,0 +1,2 @@
+# Copyright 2014 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
diff --git a/pym/portage/tests/sync/test_sync_local.py b/pym/portage/tests/sync/test_sync_local.py
new file mode 100644
index 0000000..65c20f8
--- /dev/null
+++ b/pym/portage/tests/sync/test_sync_local.py
@@ -0,0 +1,189 @@
+# Copyright 2014 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+import subprocess
+import sys
+import textwrap
+import time
+
+import portage
+from portage import os, shutil
+from portage import _unicode_decode
+from portage.const import PORTAGE_PYM_PATH, TIMESTAMP_FORMAT
+from portage.process import find_binary
+from portage.tests import TestCase
+from portage.tests.resolver.ResolverPlayground import ResolverPlayground
+from portage.util import ensure_dirs
+
+class SyncLocalTestCase(TestCase):
+ """
+ Test sync with rsync and git, using file:// sync-uri.
+ """
+
+ def _must_skip(self):
+ if find_binary("rsync") is None:
+ return "rsync: command not found"
+ if find_binary("git") is None:
+ return "git: command not found"
+
+ def testSyncLocal(self):
+ debug = False
+
+ skip_reason = self._must_skip()
+ if skip_reason:
+ self.portage_skip = skip_reason
+ self.assertFalse(True, skip_reason)
+ return
+
+ repos_conf = textwrap.dedent("""
+ [test_repo]
+ location = %(EPREFIX)s/var/repositories/test_repo
+ sync-type = %(sync-type)s
+ sync-uri = file:/%(EPREFIX)s/var/repositories/test_repo_sync
+ auto-sync = yes
+ """)
+
+ profile = {
+ "eapi": ("5",),
+ "package.use.stable.mask": ("dev-libs/A flag",)
+ }
+
+ ebuilds = {
+ "dev-libs/A-0": {}
+ }
+
+ playground = ResolverPlayground(ebuilds=ebuilds,
+ profile=profile, user_config={}, debug=debug)
+ settings = playground.settings
+ eprefix = settings["EPREFIX"]
+ eroot = settings["EROOT"]
+ homedir = os.path.join(eroot, "home")
+ distdir = os.path.join(eprefix, "distdir")
+ repo = settings.repositories["test_repo"]
+ metadata_dir = os.path.join(repo.location, "metadata")
+
+ cmds = {}
+ for cmd in ("emerge", "emaint"):
+ cmds[cmd] = (portage._python_interpreter,
+ "-b", "-Wd", os.path.join(self.bindir, cmd))
+
+ git_binary = find_binary("git")
+ git_cmd = (git_binary,)
+
+ committer_name = "Gentoo Dev"
+ committer_email = "gentoo-dev@gentoo.org"
+
+ def change_sync_type(sync_type):
+ env["PORTAGE_REPOSITORIES"] = repos_conf % \
+ {"EPREFIX": eprefix, "sync-type": sync_type}
+
+ sync_cmds = (
+ (homedir, cmds["emerge"] + ("--sync",)),
+ (homedir, lambda: self.assertTrue(os.path.exists(
+ os.path.join(repo.location, "dev-libs", "A")
+ ), "dev-libs/A expected, but missing")),
+ (homedir, cmds["emaint"] + ("sync", "-A")),
+ )
+
+ rename_repo = (
+ (homedir, lambda: os.rename(repo.location,
+ repo.location + "_sync")),
+ )
+
+ delete_sync_repo = (
+ (homedir, lambda: shutil.rmtree(
+ repo.location + "_sync")),
+ )
+
+ git_repo_create = (
+ (repo.location, git_cmd +
+ ("config", "--global", "user.name", committer_name,)),
+ (repo.location, git_cmd +
+ ("config", "--global", "user.email", committer_email,)),
+ (repo.location, git_cmd + ("init-db",)),
+ (repo.location, git_cmd + ("add", ".")),
+ (repo.location, git_cmd +
+ ("commit", "-a", "-m", "add whole repo")),
+ )
+
+ sync_type_git = (
+ (homedir, lambda: change_sync_type("git")),
+ )
+
+ pythonpath = os.environ.get("PYTHONPATH")
+ if pythonpath is not None and not pythonpath.strip():
+ pythonpath = None
+ if pythonpath is not None and \
+ pythonpath.split(":")[0] == PORTAGE_PYM_PATH:
+ pass
+ else:
+ if pythonpath is None:
+ pythonpath = ""
+ else:
+ pythonpath = ":" + pythonpath
+ pythonpath = PORTAGE_PYM_PATH + pythonpath
+
+ env = {
+ "PORTAGE_OVERRIDE_EPREFIX" : eprefix,
+ "DISTDIR" : distdir,
+ "GENTOO_COMMITTER_NAME" : committer_name,
+ "GENTOO_COMMITTER_EMAIL" : committer_email,
+ "HOME" : homedir,
+ "PATH" : os.environ["PATH"],
+ "PORTAGE_GRPNAME" : os.environ["PORTAGE_GRPNAME"],
+ "PORTAGE_USERNAME" : os.environ["PORTAGE_USERNAME"],
+ "PORTAGE_REPOSITORIES" : repos_conf %
+ {"EPREFIX": eprefix, "sync-type": "rsync"},
+ "PYTHONPATH" : pythonpath,
+ }
+
+ if os.environ.get("SANDBOX_ON") == "1":
+ # avoid problems from nested sandbox instances
+ env["FEATURES"] = "-sandbox -usersandbox"
+
+ dirs = [homedir, metadata_dir]
+ try:
+ for d in dirs:
+ ensure_dirs(d)
+
+ timestamp_path = os.path.join(metadata_dir, 'timestamp.chk')
+ with open(timestamp_path, 'w') as f:
+ f.write(time.strftime('%s\n' % TIMESTAMP_FORMAT, time.gmtime()))
+
+ if debug:
+ # The subprocess inherits both stdout and stderr, for
+ # debugging purposes.
+ stdout = None
+ else:
+ # The subprocess inherits stderr so that any warnings
+ # triggered by python -Wd will be visible.
+ stdout = subprocess.PIPE
+
+ for cwd, cmd in rename_repo + sync_cmds + \
+ delete_sync_repo + git_repo_create + sync_type_git + \
+ rename_repo + sync_cmds:
+
+ if hasattr(cmd, '__call__'):
+ cmd()
+ continue
+
+ abs_cwd = os.path.join(repo.location, cwd)
+ proc = subprocess.Popen(cmd,
+ cwd=abs_cwd, env=env, stdout=stdout)
+
+ if debug:
+ proc.wait()
+ else:
+ output = proc.stdout.readlines()
+ proc.wait()
+ proc.stdout.close()
+ if proc.returncode != os.EX_OK:
+ for line in output:
+ sys.stderr.write(_unicode_decode(line))
+
+ self.assertEqual(os.EX_OK, proc.returncode,
+ "%s failed in %s" % (cmd, cwd,))
+
+
+ finally:
+ playground.cleanup()
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-12-04 20:04 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-12-01 21:50 [gentoo-commits] proj/portage:plugin-sync commit in: pym/portage/tests/sync/ Michał Górny
-- strict thread matches above, loose matches on Subject: below --
2014-12-04 20:16 [gentoo-commits] proj/portage:master " Brian Dolbec
2014-12-04 20:04 ` [gentoo-commits] proj/portage:plugin-sync " Brian Dolbec
2014-10-22 13:36 Zac Medico
2014-10-22 12:11 Zac Medico
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox