commit: 267ff8e7bc695b9b681bb36ab3b47bc7e9e0e4e2
Author: Étienne Buira <etienne.buira <AT> gmail <DOT> com>
AuthorDate: Wed Jul 8 17:46:42 2015 +0000
Commit: Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Tue Jul 14 21:28:31 2015 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=267ff8e7
sync: Enable to set rsync extra opts per repository
man/portage.5 | 5 ++
pym/portage/package/ebuild/config.py | 2 +
pym/portage/repository/config.py | 10 ++--
pym/portage/sync/modules/rsync/__init__.py | 2 +-
pym/portage/sync/modules/rsync/rsync.py | 6 ++-
pym/portage/tests/sync/test_sync_local.py | 73 +++++++++++++++++++++++++++---
6 files changed, 85 insertions(+), 13 deletions(-)
diff --git a/man/portage.5 b/man/portage.5
index e77fc6e..e84142a 100644
--- a/man/portage.5
+++ b/man/portage.5
@@ -1021,6 +1021,11 @@ group id will be changed.
.br
This key takes precedence over FEATURES=userpriv. If user or group id
is provided, Portage no longer uses owner of the directory.
+.TP
+.B sync-rsync-extra-opts
+Extra options to give to rsync on repository synchronization. It takes
+precedence over a declaration in [DEFAULT] section, that takes
+precedence over PORTAGE_RSYNC_EXTRA_OPTS.
.RE
.I Example:
diff --git a/pym/portage/package/ebuild/config.py
b/pym/portage/package/ebuild/config.py
index 3a4007b..08db363 100644
--- a/pym/portage/package/ebuild/config.py
+++ b/pym/portage/package/ebuild/config.py
@@ -515,6 +515,8 @@ class config(object):
v = confs.get("SYNC")
if v is not None:
portdir_sync = v
+ if 'PORTAGE_RSYNC_EXTRA_OPTS' in confs:
+ self['PORTAGE_RSYNC_EXTRA_OPTS'] =
confs['PORTAGE_RSYNC_EXTRA_OPTS']
self["PORTDIR"] = portdir
self["PORTDIR_OVERLAY"] = portdir_overlay
diff --git a/pym/portage/repository/config.py b/pym/portage/repository/config.py
index ef14f13..0b12100 100644
--- a/pym/portage/repository/config.py
+++ b/pym/portage/repository/config.py
@@ -545,9 +545,9 @@ class RepoConfigLoader(object):
return portdir
@staticmethod
- def _parse(paths, prepos, ignored_map, ignored_location_map,
local_config, portdir):
+ def _parse(paths, prepos, ignored_map, ignored_location_map,
local_config, portdir, default_opts):
"""Parse files in paths to load config"""
- parser = SafeConfigParser()
+ parser = SafeConfigParser(defaults=default_opts)
# use read_file/readfp in order to control decoding of unicode
try:
@@ -619,6 +619,7 @@ class RepoConfigLoader(object):
treemap = {}
ignored_map = {}
ignored_location_map = {}
+ default_opts = {}
if "PORTAGE_REPOSITORIES" in settings:
portdir = ""
@@ -631,10 +632,13 @@ class RepoConfigLoader(object):
# deprecated portdir_sync
portdir_sync = settings.get("SYNC", "")
+ default_opts['sync-rsync-extra-opts'] = \
+ settings.get("PORTAGE_RSYNC_EXTRA_OPTS", None)
+
try:
self._parse(paths, prepos, ignored_map,
ignored_location_map, settings.local_config,
- portdir)
+ portdir, default_opts)
except ConfigParserError as e:
writemsg(
_("!!! Error while reading repo config file:
%s\n") % e,
diff --git a/pym/portage/sync/modules/rsync/__init__.py
b/pym/portage/sync/modules/rsync/__init__.py
index 13832f8..f2bad09 100644
--- a/pym/portage/sync/modules/rsync/__init__.py
+++ b/pym/portage/sync/modules/rsync/__init__.py
@@ -23,7 +23,7 @@ module_spec = {
'exists': 'Returns a boolean if the specified
directory exists',
},
'validate_config': CheckSyncConfig,
- 'module_specific_options': (),
+ 'module_specific_options': ('sync-rsync-extra-opts',),
}
}
}
diff --git a/pym/portage/sync/modules/rsync/rsync.py
b/pym/portage/sync/modules/rsync/rsync.py
index d84c36d..8041f07 100644
--- a/pym/portage/sync/modules/rsync/rsync.py
+++ b/pym/portage/sync/modules/rsync/rsync.py
@@ -72,8 +72,10 @@ class RsyncSync(NewBase):
rsync_opts = self._validate_rsync_opts(rsync_opts,
syncuri)
self.rsync_opts = self._rsync_opts_extend(opts, rsync_opts)
- self.extra_rsync_opts = portage.util.shlex_split(
- self.settings.get("PORTAGE_RSYNC_EXTRA_OPTS",""))
+ self.extra_rsync_opts = list()
+ if 'sync-rsync-extra-opts' in self.repo.module_specific_options:
+ self.extra_rsync_opts.extend(portage.util.shlex_split(
+
self.repo.module_specific_options['sync-rsync-extra-opts']))
# Real local timestamp file.
self.servertimestampfile = os.path.join(
diff --git a/pym/portage/tests/sync/test_sync_local.py
b/pym/portage/tests/sync/test_sync_local.py
index 65c20f8..f50caba 100644
--- a/pym/portage/tests/sync/test_sync_local.py
+++ b/pym/portage/tests/sync/test_sync_local.py
@@ -7,7 +7,7 @@ import textwrap
import time
import portage
-from portage import os, shutil
+from portage import os, shutil, _shell_quote
from portage import _unicode_decode
from portage.const import PORTAGE_PYM_PATH, TIMESTAMP_FORMAT
from portage.process import find_binary
@@ -36,11 +36,14 @@ class SyncLocalTestCase(TestCase):
return
repos_conf = textwrap.dedent("""
+ [DEFAULT]
+ %(default_keys)s
[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
+ %(repo_extra_keys)s
""")
profile = {
@@ -73,9 +76,17 @@ class SyncLocalTestCase(TestCase):
committer_name = "Gentoo Dev"
committer_email = "[email protected]"
- def change_sync_type(sync_type):
- env["PORTAGE_REPOSITORIES"] = repos_conf % \
- {"EPREFIX": eprefix, "sync-type": sync_type}
+ def repos_set_conf(sync_type, dflt_keys=None, xtra_keys=None):
+ env["PORTAGE_REPOSITORIES"] = repos_conf % {\
+ "EPREFIX": eprefix, "sync-type": sync_type,
+ "default_keys": "" if dflt_keys is None else
dflt_keys,
+ "repo_extra_keys": "" if xtra_keys is None else
xtra_keys}
+
+ def alter_ebuild():
+ with open(os.path.join(repo.location + "_sync",
+ "dev-libs", "A", "A-0.ebuild"), "a") as f:
+ f.write("\n")
+ os.unlink(os.path.join(metadata_dir, 'timestamp.chk'))
sync_cmds = (
(homedir, cmds["emerge"] + ("--sync",)),
@@ -90,6 +101,53 @@ class SyncLocalTestCase(TestCase):
repo.location + "_sync")),
)
+ rsync_opts_repos = (
+ (homedir, alter_ebuild),
+ (homedir, lambda: repos_set_conf("rsync", None,
+ "sync-rsync-extra-opts = --backup
--backup-dir=%s" %
+ _shell_quote(repo.location + "_back"))),
+ (homedir, cmds['emerge'] + ("--sync",)),
+ (homedir, lambda: self.assertTrue(os.path.exists(
+ repo.location + "_back"))),
+ (homedir, lambda: shutil.rmtree(repo.location +
"_back")),
+ (homedir, lambda: repos_set_conf("rsync")),
+ )
+
+ rsync_opts_repos_default = (
+ (homedir, alter_ebuild),
+ (homedir, lambda: repos_set_conf("rsync",
+ "sync-rsync-extra-opts = --backup
--backup-dir=%s" %
+ _shell_quote(repo.location+"_back"))),
+ (homedir, cmds['emerge'] + ("--sync",)),
+ (homedir, lambda:
self.assertTrue(os.path.exists(repo.location + "_back"))),
+ (homedir, lambda: shutil.rmtree(repo.location +
"_back")),
+ (homedir, lambda: repos_set_conf("rsync")),
+ )
+
+ rsync_opts_repos_default_ovr = (
+ (homedir, alter_ebuild),
+ (homedir, lambda: repos_set_conf("rsync",
+ "sync-rsync-extra-opts = --backup
--backup-dir=%s" %
+ _shell_quote(repo.location + "_back_nowhere"),
+ "sync-rsync-extra-opts = --backup
--backup-dir=%s" %
+ _shell_quote(repo.location + "_back"))),
+ (homedir, cmds['emerge'] + ("--sync",)),
+ (homedir, lambda:
self.assertTrue(os.path.exists(repo.location + "_back"))),
+ (homedir, lambda: shutil.rmtree(repo.location +
"_back")),
+ (homedir, lambda: repos_set_conf("rsync")),
+ )
+
+ rsync_opts_repos_default_cancel = (
+ (homedir, alter_ebuild),
+ (homedir, lambda: repos_set_conf("rsync",
+ "sync-rsync-extra-opts = --backup
--backup-dir=%s" %
+ _shell_quote(repo.location + "_back_nowhere"),
+ "sync-rsync-extra-opts = ")),
+ (homedir, cmds['emerge'] + ("--sync",)),
+ (homedir, lambda:
self.assertFalse(os.path.exists(repo.location + "_back"))),
+ (homedir, lambda: repos_set_conf("rsync")),
+ )
+
delete_sync_repo = (
(homedir, lambda: shutil.rmtree(
repo.location + "_sync")),
@@ -107,7 +165,7 @@ class SyncLocalTestCase(TestCase):
)
sync_type_git = (
- (homedir, lambda: change_sync_type("git")),
+ (homedir, lambda: repos_set_conf("git")),
)
pythonpath = os.environ.get("PYTHONPATH")
@@ -132,10 +190,9 @@ class SyncLocalTestCase(TestCase):
"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,
}
+ repos_set_conf("rsync")
if os.environ.get("SANDBOX_ON") == "1":
# avoid problems from nested sandbox instances
@@ -160,6 +217,8 @@ class SyncLocalTestCase(TestCase):
stdout = subprocess.PIPE
for cwd, cmd in rename_repo + sync_cmds + \
+ rsync_opts_repos + rsync_opts_repos_default + \
+ rsync_opts_repos_default_ovr +
rsync_opts_repos_default_cancel + \
delete_sync_repo + git_repo_create +
sync_type_git + \
rename_repo + sync_cmds: