* [gentoo-portage-dev] [PATCH] conf: Enable to set rsync extra opts per repository
@ 2015-06-17 18:40 Étienne Buira
2015-06-17 20:32 ` Brian Dolbec
0 siblings, 1 reply; 15+ messages in thread
From: Étienne Buira @ 2015-06-17 18:40 UTC (permalink / raw
To: gentoo-portage-dev
---
man/portage.5 | 5 +++
pym/portage/package/ebuild/config.py | 2 +
pym/portage/repository/config.py | 24 +++++++---
pym/portage/sync/modules/rsync/rsync.py | 6 ++-
pym/portage/tests/sync/test_sync_local.py | 73 ++++++++++++++++++++++++++++---
5 files changed, 95 insertions(+), 15 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 b7c969d..196b87a 100644
--- a/pym/portage/repository/config.py
+++ b/pym/portage/repository/config.py
@@ -87,7 +87,7 @@ class RepoConfig(object):
'main_repo', 'manifest_hashes', 'masters', 'missing_repo_name',
'name', 'portage1_profiles', 'portage1_profiles_compat', 'priority',
'profile_formats', 'sign_commit', 'sign_manifest', 'sync_cvs_repo',
- 'sync_depth',
+ 'sync_depth', 'sync_rsync_extra_opts',
'sync_type', 'sync_umask', 'sync_uri', 'sync_user', 'thin_manifest',
'update_changelog', 'user_location', '_eapis_banned',
'_eapis_deprecated', '_masters_orig')
@@ -180,6 +180,8 @@ class RepoConfig(object):
self.sync_depth = repo_opts.get('sync-depth')
+ self.sync_rsync_extra_opts = repo_opts.get('sync-rsync-extra-opts', None)
+
# Not implemented.
format = repo_opts.get('format')
if format is not None:
@@ -415,6 +417,8 @@ class RepoConfig(object):
repo_msg.append(indent + "sync-umask: " + self.sync_umask)
if self.sync_uri:
repo_msg.append(indent + "sync-uri: " + self.sync_uri)
+ if self.sync_rsync_extra_opts:
+ repo_msg.append(indent + "sync-rsync-extra-opts: " + self.sync_rsync_extra_opts)
if self.sync_user:
repo_msg.append(indent + "sync-user: " + self.sync_user)
if self.masters:
@@ -477,6 +481,9 @@ class RepoConfigLoader(object):
if prepos['DEFAULT'].masters is not None:
default_repo_opts['masters'] = \
' '.join(prepos['DEFAULT'].masters)
+ if prepos['DEFAULT'].sync_rsync_extra_opts is not None:
+ default_repo_opts['sync-rsync-extra-opts'] = \
+ prepos['DEFAULT'].sync_rsync_extra_opts
if overlays:
# We need a copy of the original repos.conf data, since we're
@@ -504,7 +511,7 @@ class RepoConfigLoader(object):
# repos.conf is allowed to override.
for k in ('aliases', 'auto_sync', 'eclass_overrides',
'force', 'masters', 'priority', 'sync_cvs_repo',
- 'sync_depth',
+ 'sync_depth', 'sync_rsync_extra_opts',
'sync_type', 'sync_umask', 'sync_uri', 'sync_user',
):
v = getattr(repos_conf_opts, k, None)
@@ -543,9 +550,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:
@@ -615,6 +622,7 @@ class RepoConfigLoader(object):
treemap = {}
ignored_map = {}
ignored_location_map = {}
+ default_opts = {}
if "PORTAGE_REPOSITORIES" in settings:
portdir = ""
@@ -627,10 +635,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,
@@ -962,7 +973,8 @@ class RepoConfigLoader(object):
def config_string(self):
str_or_int_keys = ("auto_sync", "format", "location",
"main_repo", "priority", "sync_cvs_repo",
- "sync_type", "sync_umask", "sync_uri", 'sync_user')
+ "sync_type", "sync_umask", "sync_uri", 'sync_user',
+ 'sync_rsync_extra_opts')
str_tuple_keys = ("aliases", "eclass_overrides", "force")
repo_config_tuple_keys = ("masters",)
keys = str_or_int_keys + str_tuple_keys + repo_config_tuple_keys
diff --git a/pym/portage/sync/modules/rsync/rsync.py b/pym/portage/sync/modules/rsync/rsync.py
index d84c36d..1f09f60 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 self.repo.sync_rsync_extra_opts is not None:
+ self.extra_rsync_opts.extend(portage.util.shlex_split(
+ self.repo.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 = "gentoo-dev@gentoo.org"
- 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:
^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [gentoo-portage-dev] [PATCH] conf: Enable to set rsync extra opts per repository
2015-06-17 18:40 [gentoo-portage-dev] [PATCH] conf: Enable to set rsync extra opts per repository Étienne Buira
@ 2015-06-17 20:32 ` Brian Dolbec
2015-06-18 21:32 ` Étienne Buira
2015-06-18 21:36 ` [gentoo-portage-dev] [PATCH v2 1/2] sync: allow sync modules to have specific options Étienne Buira
0 siblings, 2 replies; 15+ messages in thread
From: Brian Dolbec @ 2015-06-17 20:32 UTC (permalink / raw
To: gentoo-portage-dev
Be aware that I have not read over the diff very much yet.
On Wed, 17 Jun 2015 20:40:30 +0200
Étienne Buira <etienne.buira@gmail.com> wrote:
> ---
> man/portage.5 | 5 +++
> pym/portage/package/ebuild/config.py | 2 +
> pym/portage/repository/config.py | 24 +++++++---
> pym/portage/sync/modules/rsync/rsync.py | 6 ++-
> pym/portage/tests/sync/test_sync_local.py | 73
> ++++++++++++++++++++++++++++--- 5 files changed, 95 insertions(+), 15
> deletions(-)
>
...
> 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
Not sure why ebuild/config.py needs changes... will look at it more
> diff --git a/pym/portage/repository/config.py
> b/pym/portage/repository/config.py index b7c969d..196b87a 100644
> --- a/pym/portage/repository/config.py
> +++ b/pym/portage/repository/config.py
This approach is not wanted, it means hard coding any sync module
options in the main loader that might be sync-type specific.
We want to make it generic so any arbitrary sync-type options (more
than the base required options) can be added for any module without the
need to change this. Those options are not used anywhere else other
than the sync module.
One method might be to replace the copying of the configparser options
into python variables. Instead change it to look for the option in the
configparser instance. And only maintain some base options or
functions which pull from the config instance.
--
Brian Dolbec <dolsen>
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [gentoo-portage-dev] [PATCH] conf: Enable to set rsync extra opts per repository
2015-06-17 20:32 ` Brian Dolbec
@ 2015-06-18 21:32 ` Étienne Buira
2015-07-06 18:28 ` Brian Dolbec
2015-06-18 21:36 ` [gentoo-portage-dev] [PATCH v2 1/2] sync: allow sync modules to have specific options Étienne Buira
1 sibling, 1 reply; 15+ messages in thread
From: Étienne Buira @ 2015-06-18 21:32 UTC (permalink / raw
To: gentoo-portage-dev
Hi, thank you for reviewing
On Wed, Jun 17, 2015 at 01:32:17PM -0700, Brian Dolbec wrote:
> Be aware that I have not read over the diff very much yet.
>
> On Wed, 17 Jun 2015 20:40:30 +0200
> Étienne Buira <etienne.buira@gmail.com> wrote:
>
> > 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
>
> Not sure why ebuild/config.py needs changes... will look at it more
For the same reason the same thing is done about ['SYNC']: forwarding
its value to RepoConfigLoader.__init__ settings argument.
> > diff --git a/pym/portage/repository/config.py
> > b/pym/portage/repository/config.py index b7c969d..196b87a 100644
> > --- a/pym/portage/repository/config.py
> > +++ b/pym/portage/repository/config.py
>
>
> This approach is not wanted, it means hard coding any sync module
> options in the main loader that might be sync-type specific.
>
> We want to make it generic so any arbitrary sync-type options (more
> than the base required options) can be added for any module without the
> need to change this. Those options are not used anywhere else other
> than the sync module.
Ok, patchset follows.
> One method might be to replace the copying of the configparser options
> into python variables. Instead change it to look for the option in the
> configparser instance. And only maintain some base options or
> functions which pull from the config instance.
Not sure i understood what you meant, nor how that would look like,
please explain if patchset is not oked.
Regards.
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [gentoo-portage-dev] [PATCH] conf: Enable to set rsync extra opts per repository
2015-06-18 21:32 ` Étienne Buira
@ 2015-07-06 18:28 ` Brian Dolbec
2015-07-06 22:05 ` Brian Dolbec
2015-07-08 17:45 ` Étienne Buira
0 siblings, 2 replies; 15+ messages in thread
From: Brian Dolbec @ 2015-07-06 18:28 UTC (permalink / raw
To: gentoo-portage-dev
On Thu, 18 Jun 2015 23:32:27 +0200
Étienne Buira <etienne.buira@gmail.com> wrote:
> Hi, thank you for reviewing
>
> On Wed, Jun 17, 2015 at 01:32:17PM -0700, Brian Dolbec wrote:
> > Be aware that I have not read over the diff very much yet.
> >
> > On Wed, 17 Jun 2015 20:40:30 +0200
> > Étienne Buira <etienne.buira@gmail.com> wrote:
> >
> > > 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
> >
> > Not sure why ebuild/config.py needs changes... will look at it more
>
> For the same reason the same thing is done about ['SYNC']: forwarding
> its value to RepoConfigLoader.__init__ settings argument.
>
> > > diff --git a/pym/portage/repository/config.py
> > > b/pym/portage/repository/config.py index b7c969d..196b87a 100644
> > > --- a/pym/portage/repository/config.py
> > > +++ b/pym/portage/repository/config.py
> >
> >
> > This approach is not wanted, it means hard coding any sync module
> > options in the main loader that might be sync-type specific.
> >
> > We want to make it generic so any arbitrary sync-type options (more
> > than the base required options) can be added for any module without
> > the need to change this. Those options are not used anywhere else
> > other than the sync module.
>
> Ok, patchset follows.
Sorry, it's taken so long to review these ones. There has been a lot
going on recently.
This is much better, I like the way you've added them for the most
part. But, you added them to the actual sync module class. By doing
that, it forces portage to load the sync module even if it is not going
to perform any sync action.
Portage's code requires that the configs be loaded for all operations,
so it reads them on initialization. That is the reason I put the
config validation code handling in the sync module's module_spec. It
is small, lightweight, and only provides the info needed.
Each sync module's __init__.py contains only the information about the
sync module for the plugin system to use and any config validation code
needed. The module_specific_options should be defined here. That way
none of the actual sync code is loaded until a sync operation is
performed. This both speeds up initialization of portage and reduces
it's memory needs slightly.
hmm, this is the cvs module's module_spec, I was thinking we might be
able to add the module_specific_opts there after the validate_config
definition, like so:
module_spec = {
'name': 'cvs',
'description': doc,
'provides':{
'cvs-module': {
'name': "cvs",
'class': "CVSSync",
'description': doc,
'functions': ['sync', 'new', 'exists'],
'func_desc': {
'sync': 'Performs a cvs up on the
repository', 'new': 'Creates the new repository at the specified
location', 'exists': 'Returns a boolean of whether the specified dir ' +
'exists and is a valid CVS
repository', },
'validate_config': CheckCVSConfig,
'module_specific_opts': None,
}
}
}
Also, the config validation code should probably be exteneded for any
module specific options as well.
I'll look into whether that will work.
I'll add your patch and see about moving things around.
>
> > One method might be to replace the copying of the configparser
> > options into python variables. Instead change it to look for the
> > option in the configparser instance. And only maintain some base
> > options or functions which pull from the config instance.
>
> Not sure i understood what you meant, nor how that would look like,
> please explain if patchset is not oked.
>
> Regards.
>
>
Don't worry about this, this change will require a complete re-do of
the portage/repository/config code. I like your approach to handle
this for the most part. It will be the easiest to do with the code
that is in place now.
--
Brian Dolbec <dolsen>
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [gentoo-portage-dev] [PATCH] conf: Enable to set rsync extra opts per repository
2015-07-06 18:28 ` Brian Dolbec
@ 2015-07-06 22:05 ` Brian Dolbec
2015-07-08 17:45 ` Étienne Buira
1 sibling, 0 replies; 15+ messages in thread
From: Brian Dolbec @ 2015-07-06 22:05 UTC (permalink / raw
To: gentoo-portage-dev
[-- Attachment #1: Type: text/plain, Size: 1862 bytes --]
On Mon, 6 Jul 2015 11:28:36 -0700
Brian Dolbec <dolsen@gentoo.org> wrote:
> hmm, this is the cvs module's module_spec, I was thinking we might be
> able to add the module_specific_opts there after the validate_config
> definition, like so:
>
> module_spec = {
> 'name': 'cvs',
> 'description': doc,
> 'provides':{
> 'cvs-module': {
> 'name': "cvs",
> 'class': "CVSSync",
> 'description': doc,
> 'functions': ['sync', 'new', 'exists'],
> 'func_desc': {
> 'sync': 'Performs a cvs up on the
> repository', 'new': 'Creates the new repository at the specified
> location', 'exists': 'Returns a boolean of whether the specified dir
> ' + 'exists and is a valid CVS
> repository', },
> 'validate_config': CheckCVSConfig,
> 'module_specific_opts': None,
> }
> }
> }
>
>
> Also, the config validation code should probably be exteneded for any
> module specific options as well.
>
> I'll look into whether that will work.
> I'll add your patch and see about moving things around.
>
OK, I think I got it, I haven't tested your extra-options field, but a
normal rsync operation worked for me. I simplified the naming some,
the "sync_cvs_repo" name was old and oblsolete (replaced by the
universal "auto-sync" setting). So for rsync it is simply
"extra-options". Also since they are being stored in a dictionary,
there is no need to sub the - for _.
I think this should work out well. Now it should be easier to add
branch support to the git module.
Try it out, see what you think. You can squash my commits back into
yours with just a small mention of my contribution. No big deal for
me ;)
I thank you for your work on this.
I've attached the 2 patches of changes. Please test and check it for
errors (there is bound to be some) I haven't tested it thoroughly yet.
--
Brian Dolbec <dolsen>
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Rework-PATCH-v2-1-2-sync-allow-sync-modules-to-have-.patch --]
[-- Type: text/x-patch, Size: 9174 bytes --]
From e540b25c133aa5df8c13ae9b6f57506ec2cb07ba Mon Sep 17 00:00:00 2001
From: Brian Dolbec <dolsen@gentoo.org>
Date: Mon, 6 Jul 2015 14:51:13 -0700
Subject: [PATCH 1/2] Rework [PATCH v2 1/2] sync: allow sync modules to have
specific options
Move things around so they are defined in the module_spec instead.
Simplify the code a little as portage has no other use for these settings.
Signed-off-by: Brian Dolbec <dolsen@gentoo.org>
---
pym/portage/repository/config.py | 31 +++++++++++----------------
pym/portage/sync/__init__.py | 18 +++++++++-------
pym/portage/sync/modules/cvs/__init__.py | 1 +
pym/portage/sync/modules/cvs/cvs.py | 7 +-----
pym/portage/sync/modules/git/__init__.py | 1 +
pym/portage/sync/modules/svn/__init__.py | 1 +
pym/portage/sync/modules/webrsync/__init__.py | 1 +
pym/portage/sync/syncbase.py | 5 -----
8 files changed, 28 insertions(+), 37 deletions(-)
diff --git a/pym/portage/repository/config.py b/pym/portage/repository/config.py
index 8c16cb3..6626beb 100644
--- a/pym/portage/repository/config.py
+++ b/pym/portage/repository/config.py
@@ -90,8 +90,8 @@ class RepoConfig(object):
'sync_depth',
'sync_type', 'sync_umask', 'sync_uri', 'sync_user', 'thin_manifest',
'update_changelog', 'user_location', '_eapis_banned',
- '_eapis_deprecated', '_masters_orig') + \
- tuple(portage.sync.module_specific_options)
+ '_eapis_deprecated', '_masters_orig', 'module_specific_options',
+ )
def __init__(self, name, repo_opts, local_config=True):
"""Build a RepoConfig with options in repo_opts
@@ -176,10 +176,7 @@ class RepoConfig(object):
self.sync_depth = repo_opts.get('sync-depth')
- for o in portage.sync.module_specific_options:
- odash = o.replace('_', '-')
- if odash in repo_opts:
- setattr(self, o, repo_opts[odash])
+ self.module_specific_options = {}
# Not implemented.
format = repo_opts.get('format')
@@ -281,6 +278,10 @@ class RepoConfig(object):
self._eapis_banned = frozenset(layout_data['eapis-banned'])
self._eapis_deprecated = frozenset(layout_data['eapis-deprecated'])
+ def set_module_specific_opts(self, opts):
+ for o in opts:
+ self.module_specific_options[o] = repo_opts.get(o, None)
+
def eapi_is_banned(self, eapi):
return eapi in self._eapis_banned
@@ -425,11 +426,6 @@ class RepoConfig(object):
if self.eclass_overrides:
repo_msg.append(indent + "eclass-overrides: " + \
" ".join(self.eclass_overrides))
- if self.sync_type is not None:
- prefix = "sync_" + self.sync_type + "_"
- for o in portage.sync.module_specific_options:
- if hasattr(self, o) and o.startswith(prefix) and getattr(self, o):
- repo_msg.append(indent + o.replace('_', '-') + ": " + getattr(self, o))
repo_msg.append("")
return "\n".join(repo_msg)
@@ -481,9 +477,6 @@ class RepoConfigLoader(object):
if prepos['DEFAULT'].masters is not None:
default_repo_opts['masters'] = \
' '.join(prepos['DEFAULT'].masters)
- for o in portage.sync.module_specific_options:
- if hasattr(prepos['DEFAULT'], o):
- default_repo_opts[o.replace('_', '-')] = getattr(prepos['DEFAULT'], o)
if overlays:
# We need a copy of the original repos.conf data, since we're
@@ -513,7 +506,7 @@ class RepoConfigLoader(object):
'force', 'masters', 'priority',
'sync_depth',
'sync_type', 'sync_umask', 'sync_uri', 'sync_user',
- ) + tuple(portage.sync.module_specific_options):
+ ) + portage.sync.module_specific_options(repo, logging):
v = getattr(repos_conf_opts, k, None)
if v is not None:
setattr(repo, k, v)
@@ -605,6 +598,8 @@ class RepoConfigLoader(object):
optdict[oname] = parser.get(sname, oname)
repo = RepoConfig(sname, optdict, local_config=local_config)
+ repo.set_module_specific_opts(
+ portage.sync.module_specific_options(repo, logging))
# Perform repos.conf sync variable validation
portage.sync.validate_config(repo, logging)
@@ -635,8 +630,8 @@ class RepoConfigLoader(object):
# deprecated portdir_sync
portdir_sync = settings.get("SYNC", "")
- default_opts['sync-rsync-extra-opts'] = \
- settings.get("PORTAGE_RSYNC_EXTRA_OPTS", None)
+ #default_opts['sync-rsync-extra-opts'] = \
+ # settings.get("PORTAGE_RSYNC_EXTRA_OPTS", None)
try:
self._parse(paths, prepos, ignored_map,
@@ -974,7 +969,7 @@ class RepoConfigLoader(object):
str_or_int_keys = ("auto_sync", "format", "location",
"main_repo", "priority",
"sync_type", "sync_umask", "sync_uri", 'sync_user')
- str_or_int_keys += tuple(portage.sync.module_specific_options)
+ #str_or_int_keys += self.module_specific_options()
str_tuple_keys = ("aliases", "eclass_overrides", "force")
repo_config_tuple_keys = ("masters",)
keys = str_or_int_keys + str_tuple_keys + repo_config_tuple_keys
diff --git a/pym/portage/sync/__init__.py b/pym/portage/sync/__init__.py
index 11059eb..4edb402 100644
--- a/pym/portage/sync/__init__.py
+++ b/pym/portage/sync/__init__.py
@@ -25,15 +25,17 @@ module_controller = Modules(path=path, namepath="portage.sync.modules")
module_names = module_controller.module_names[:]
-def _build_module_specific_options_list():
- modules = set()
- for (mn, m) in [(mn, module_controller.get_class(mn)) for mn in module_names]:
- modules.update(["sync_" + mn + "_" + opt.replace('-', '_') for opt in m.specific_options()])
- return modules
-
-
-module_specific_options = frozenset(_build_module_specific_options_list())
+def module_specific_options(repo, logger):
+ '''Get the authorized module specific options set for
+ the repos.conf settings for the repo'''
+ global module_controller
+ #print(repo)
+ if repo.sync_type:
+ opts = frozenset([opt for opt in
+ module_controller.modules[repo.sync_type]['module_specific_options']])
+ return opts
+ return frozenset()
def validate_config(repo, logger):
'''Validate the repos.conf settings for the repo'''
diff --git a/pym/portage/sync/modules/cvs/__init__.py b/pym/portage/sync/modules/cvs/__init__.py
index 0f4a029..5da0781 100644
--- a/pym/portage/sync/modules/cvs/__init__.py
+++ b/pym/portage/sync/modules/cvs/__init__.py
@@ -40,6 +40,7 @@ module_spec = {
'exists and is a valid CVS repository',
},
'validate_config': CheckCVSConfig,
+ 'module_specific_options': ("sync_cvs_repo",),
}
}
}
diff --git a/pym/portage/sync/modules/cvs/cvs.py b/pym/portage/sync/modules/cvs/cvs.py
index 90e256b..4654ca4 100644
--- a/pym/portage/sync/modules/cvs/cvs.py
+++ b/pym/portage/sync/modules/cvs/cvs.py
@@ -19,11 +19,6 @@ class CVSSync(NewBase):
return "CVSSync"
- @staticmethod
- def specific_options():
- return ("repo",)
-
-
def __init__(self):
NewBase.__init__(self, "cvs", portage.const.CVS_PACKAGE_ATOM)
@@ -42,7 +37,7 @@ class CVSSync(NewBase):
"cd %s; exec cvs -z0 -d %s co -P -d %s %s" %
(portage._shell_quote(os.path.dirname(self.repo.location)), portage._shell_quote(cvs_root),
portage._shell_quote(os.path.basename(self.repo.location)),
- portage._shell_quote(self.repo.sync_cvs_repo)),
+ portage._shell_quote(self.repo.module_specific_options["sync_cvs_repo"])),
**portage._native_kwargs(self.spawn_kwargs)) != os.EX_OK:
msg = "!!! cvs checkout error; exiting."
self.logger(self.xterm_titles, msg)
diff --git a/pym/portage/sync/modules/git/__init__.py b/pym/portage/sync/modules/git/__init__.py
index a372881..cd28253 100644
--- a/pym/portage/sync/modules/git/__init__.py
+++ b/pym/portage/sync/modules/git/__init__.py
@@ -50,6 +50,7 @@ module_spec = {
'exists and is a valid Git repository',
},
'validate_config': CheckGitConfig,
+ 'module_specific_options': (,),
}
}
}
diff --git a/pym/portage/sync/modules/svn/__init__.py b/pym/portage/sync/modules/svn/__init__.py
index 59ab950..4189298 100644
--- a/pym/portage/sync/modules/svn/__init__.py
+++ b/pym/portage/sync/modules/svn/__init__.py
@@ -26,6 +26,7 @@ module_spec = {
'exists and is a valid SVN repository',
},
'validate_config': CheckSyncConfig,
+ 'module_specific_options': (,),
}
}
}
diff --git a/pym/portage/sync/modules/webrsync/__init__.py b/pym/portage/sync/modules/webrsync/__init__.py
index 5a92066..f3c40d4 100644
--- a/pym/portage/sync/modules/webrsync/__init__.py
+++ b/pym/portage/sync/modules/webrsync/__init__.py
@@ -44,6 +44,7 @@ module_spec = {
'exists and is a valid repository',
},
'validate_config': CheckSyncConfig,
+ 'module_specific_options': (,),
},
}
}
diff --git a/pym/portage/sync/syncbase.py b/pym/portage/sync/syncbase.py
index 4d75f69..d30d69d 100644
--- a/pym/portage/sync/syncbase.py
+++ b/pym/portage/sync/syncbase.py
@@ -24,11 +24,6 @@ class SyncBase(object):
return "BlankSync"
- @staticmethod
- def specific_options():
- return ()
-
-
def can_progressbar(self, func):
return False
--
2.4.5
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0002-Rework-PATCH-v2-2-2-sync-Enable-to-set-rsync-extra-o.patch --]
[-- Type: text/x-patch, Size: 1948 bytes --]
From 5909c1d7e290961eafe6802ff385719e08f4ff5a Mon Sep 17 00:00:00 2001
From: Brian Dolbec <dolsen@gentoo.org>
Date: Mon, 6 Jul 2015 14:53:34 -0700
Subject: [PATCH 2/2] Rework [PATCH v2 2/2] sync: Enable to set rsync extra
opts per repository
Update for changes made in previous commit
Signed-off-by: Brian Dolbec <dolsen@gentoo.org>
---
pym/portage/sync/modules/rsync/__init__.py | 1 +
pym/portage/sync/modules/rsync/rsync.py | 10 +++-------
2 files changed, 4 insertions(+), 7 deletions(-)
diff --git a/pym/portage/sync/modules/rsync/__init__.py b/pym/portage/sync/modules/rsync/__init__.py
index 9adc4c8..c717cd6 100644
--- a/pym/portage/sync/modules/rsync/__init__.py
+++ b/pym/portage/sync/modules/rsync/__init__.py
@@ -23,6 +23,7 @@ module_spec = {
'exists': 'Returns a boolean if the specified directory exists',
},
'validate_config': CheckSyncConfig,
+ 'module_specific_options': ("extra-opts",),
}
}
}
diff --git a/pym/portage/sync/modules/rsync/rsync.py b/pym/portage/sync/modules/rsync/rsync.py
index 2237901..27e60eb 100644
--- a/pym/portage/sync/modules/rsync/rsync.py
+++ b/pym/portage/sync/modules/rsync/rsync.py
@@ -44,11 +44,6 @@ class RsyncSync(NewBase):
return "RsyncSync"
- @staticmethod
- def specific_options():
- return ("extra-opts",)
-
-
def __init__(self):
NewBase.__init__(self, "rsync", RSYNC_PACKAGE_ATOM)
@@ -78,9 +73,10 @@ class RsyncSync(NewBase):
self.rsync_opts = self._rsync_opts_extend(opts, rsync_opts)
self.extra_rsync_opts = list()
- if self.repo.sync_rsync_extra_opts is not None:
+ extra_opts = self.repo.module_specific_options['sync_rsync_extra_opts']
+ if extra_opts is not None:
self.extra_rsync_opts.extend(portage.util.shlex_split(
- self.repo.sync_rsync_extra_opts))
+ extra_opts))
# Real local timestamp file.
self.servertimestampfile = os.path.join(
--
2.4.5
^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [gentoo-portage-dev] [PATCH] conf: Enable to set rsync extra opts per repository
2015-07-06 18:28 ` Brian Dolbec
2015-07-06 22:05 ` Brian Dolbec
@ 2015-07-08 17:45 ` Étienne Buira
2015-07-08 17:46 ` [gentoo-portage-dev] [PATCH v3 1/2] sync: allow sync modules to have specific options Étienne Buira
1 sibling, 1 reply; 15+ messages in thread
From: Étienne Buira @ 2015-07-08 17:45 UTC (permalink / raw
To: gentoo-portage-dev
On Mon, Jul 06, 2015 at 11:28:36AM -0700, Brian Dolbec wrote:
> On Thu, 18 Jun 2015 23:32:27 +0200
> Étienne Buira <etienne.buira@gmail.com> wrote:
>
> > Hi, thank you for reviewing
> >
> > On Wed, Jun 17, 2015 at 01:32:17PM -0700, Brian Dolbec wrote:
> > > Be aware that I have not read over the diff very much yet.
> > >
> > > On Wed, 17 Jun 2015 20:40:30 +0200
> > > Étienne Buira <etienne.buira@gmail.com> wrote:
> > >
> > > > 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
> > >
> > > Not sure why ebuild/config.py needs changes... will look at it more
> >
> > For the same reason the same thing is done about ['SYNC']: forwarding
> > its value to RepoConfigLoader.__init__ settings argument.
> >
> > > > diff --git a/pym/portage/repository/config.py
> > > > b/pym/portage/repository/config.py index b7c969d..196b87a 100644
> > > > --- a/pym/portage/repository/config.py
> > > > +++ b/pym/portage/repository/config.py
> > >
> > >
> > > This approach is not wanted, it means hard coding any sync module
> > > options in the main loader that might be sync-type specific.
> > >
> > > We want to make it generic so any arbitrary sync-type options (more
> > > than the base required options) can be added for any module without
> > > the need to change this. Those options are not used anywhere else
> > > other than the sync module.
> >
> > Ok, patchset follows.
>
> Sorry, it's taken so long to review these ones. There has been a lot
> going on recently.
Hi, Thank you again for reviewing and the hints.
> This is much better, I like the way you've added them for the most
> part. But, you added them to the actual sync module class. By doing
> that, it forces portage to load the sync module even if it is not going
> to perform any sync action.
Totally missed that lazy code loading point, thank you.
../..
New patchset follows.
Regards.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [gentoo-portage-dev] [PATCH v3 1/2] sync: allow sync modules to have specific options
2015-07-08 17:45 ` Étienne Buira
@ 2015-07-08 17:46 ` Étienne Buira
2015-07-08 17:46 ` [gentoo-portage-dev] [PATCH v3 2/2] sync: Enable to set rsync extra opts per repository Étienne Buira
0 siblings, 1 reply; 15+ messages in thread
From: Étienne Buira @ 2015-07-08 17:46 UTC (permalink / raw
To: gentoo-portage-dev; +Cc: Étienne Buira
With appreciated help from Brian Dolbec.
---
pym/portage/repository/config.py | 30 ++++++++++++++++-----------
pym/portage/sync/__init__.py | 12 +++++++++++
pym/portage/sync/modules/cvs/__init__.py | 3 ++-
pym/portage/sync/modules/cvs/cvs.py | 2 +-
pym/portage/sync/modules/git/__init__.py | 1 +
pym/portage/sync/modules/rsync/__init__.py | 1 +
pym/portage/sync/modules/svn/__init__.py | 1 +
pym/portage/sync/modules/webrsync/__init__.py | 1 +
8 files changed, 37 insertions(+), 14 deletions(-)
diff --git a/pym/portage/repository/config.py b/pym/portage/repository/config.py
index b7c969d..a461ffb 100644
--- a/pym/portage/repository/config.py
+++ b/pym/portage/repository/config.py
@@ -86,11 +86,12 @@ class RepoConfig(object):
'find_invalid_path_char', 'force', 'format', 'local_config', 'location',
'main_repo', 'manifest_hashes', 'masters', 'missing_repo_name',
'name', 'portage1_profiles', 'portage1_profiles_compat', 'priority',
- 'profile_formats', 'sign_commit', 'sign_manifest', 'sync_cvs_repo',
+ 'profile_formats', 'sign_commit', 'sign_manifest',
'sync_depth',
'sync_type', 'sync_umask', 'sync_uri', 'sync_user', 'thin_manifest',
'update_changelog', 'user_location', '_eapis_banned',
- '_eapis_deprecated', '_masters_orig')
+ '_eapis_deprecated', '_masters_orig', 'module_specific_options',
+ )
def __init__(self, name, repo_opts, local_config=True):
"""Build a RepoConfig with options in repo_opts
@@ -148,11 +149,6 @@ class RepoConfig(object):
priority = None
self.priority = priority
- sync_cvs_repo = repo_opts.get('sync-cvs-repo')
- if sync_cvs_repo is not None:
- sync_cvs_repo = sync_cvs_repo.strip()
- self.sync_cvs_repo = sync_cvs_repo or None
-
sync_type = repo_opts.get('sync-type')
if sync_type is not None:
sync_type = sync_type.strip()
@@ -180,6 +176,8 @@ class RepoConfig(object):
self.sync_depth = repo_opts.get('sync-depth')
+ self.module_specific_options = {}
+
# Not implemented.
format = repo_opts.get('format')
if format is not None:
@@ -280,6 +278,9 @@ class RepoConfig(object):
self._eapis_banned = frozenset(layout_data['eapis-banned'])
self._eapis_deprecated = frozenset(layout_data['eapis-deprecated'])
+ def set_module_specific_opt(self, opt, val):
+ self.module_specific_options[opt] = val
+
def eapi_is_banned(self, eapi):
return eapi in self._eapis_banned
@@ -407,8 +408,6 @@ class RepoConfig(object):
repo_msg.append(indent + "format: " + self.format)
if self.user_location:
repo_msg.append(indent + "location: " + self.user_location)
- if self.sync_cvs_repo:
- repo_msg.append(indent + "sync-cvs-repo: " + self.sync_cvs_repo)
if self.sync_type:
repo_msg.append(indent + "sync-type: " + self.sync_type)
if self.sync_umask:
@@ -426,6 +425,9 @@ class RepoConfig(object):
if self.eclass_overrides:
repo_msg.append(indent + "eclass-overrides: " + \
" ".join(self.eclass_overrides))
+ for o, v in self.module_specific_options.items():
+ if v is not None:
+ repo_msg.append(indent + o + ": " + v)
repo_msg.append("")
return "\n".join(repo_msg)
@@ -503,10 +505,10 @@ class RepoConfigLoader(object):
# Selectively copy only the attributes which
# repos.conf is allowed to override.
for k in ('aliases', 'auto_sync', 'eclass_overrides',
- 'force', 'masters', 'priority', 'sync_cvs_repo',
+ 'force', 'masters', 'priority',
'sync_depth',
'sync_type', 'sync_umask', 'sync_uri', 'sync_user',
- ):
+ ) + portage.sync.module_specific_options(repo, logging):
v = getattr(repos_conf_opts, k, None)
if v is not None:
setattr(repo, k, v)
@@ -598,6 +600,8 @@ class RepoConfigLoader(object):
optdict[oname] = parser.get(sname, oname)
repo = RepoConfig(sname, optdict, local_config=local_config)
+ for o in portage.sync.module_specific_options(repo):
+ repo.set_module_specific_opt(o, parser.get(sname, o))
# Perform repos.conf sync variable validation
portage.sync.validate_config(repo, logging)
@@ -961,7 +965,7 @@ class RepoConfigLoader(object):
def config_string(self):
str_or_int_keys = ("auto_sync", "format", "location",
- "main_repo", "priority", "sync_cvs_repo",
+ "main_repo", "priority",
"sync_type", "sync_umask", "sync_uri", 'sync_user')
str_tuple_keys = ("aliases", "eclass_overrides", "force")
repo_config_tuple_keys = ("masters",)
@@ -979,6 +983,8 @@ class RepoConfigLoader(object):
config_string += "%s = %s\n" % (key.replace("_", "-"), " ".join(getattr(repo, key)))
elif key in repo_config_tuple_keys:
config_string += "%s = %s\n" % (key.replace("_", "-"), " ".join(x.name for x in getattr(repo, key)))
+ for o, v in repo.module_specific_options.items():
+ config_string += "%s = %s\n" % (o, v)
return config_string.lstrip("\n")
def load_repository_config(settings, extra_files=None):
diff --git a/pym/portage/sync/__init__.py b/pym/portage/sync/__init__.py
index 51bf051..b0e0ebe 100644
--- a/pym/portage/sync/__init__.py
+++ b/pym/portage/sync/__init__.py
@@ -25,6 +25,18 @@ module_controller = Modules(path=path, namepath="portage.sync.modules")
module_names = module_controller.module_names[:]
+def module_specific_options(repo):
+ '''Get the authorized module specific options set for
+ the repos.conf settings for the repo'''
+ global module_controller
+
+ if repo.sync_type:
+ opts = frozenset([opt for opt in
+ module_controller.modules[repo.sync_type]['module_specific_options']])
+ return opts
+ return frozenset()
+
+
def validate_config(repo, logger):
'''Validate the repos.conf settings for the repo'''
global module_names, module_controller
diff --git a/pym/portage/sync/modules/cvs/__init__.py b/pym/portage/sync/modules/cvs/__init__.py
index 0f4a029..952053a 100644
--- a/pym/portage/sync/modules/cvs/__init__.py
+++ b/pym/portage/sync/modules/cvs/__init__.py
@@ -18,7 +18,7 @@ class CheckCVSConfig(CheckSyncConfig):
def check_cvs_repo(self):
- if self.repo.sync_cvs_repo is None:
+ if self.repo.module_specific_options['sync-cvs-repo'] is None:
writemsg_level("!!! %s\n" %
_("Repository '%s' has sync-type=cvs, but is missing sync-cvs-repo attribute")
% self.repo.name, level=self.logger.ERROR, noiselevel=-1)
@@ -40,6 +40,7 @@ module_spec = {
'exists and is a valid CVS repository',
},
'validate_config': CheckCVSConfig,
+ 'module_specific_options': ("sync-cvs-repo",),
}
}
}
diff --git a/pym/portage/sync/modules/cvs/cvs.py b/pym/portage/sync/modules/cvs/cvs.py
index 9b382ab..7b7908b 100644
--- a/pym/portage/sync/modules/cvs/cvs.py
+++ b/pym/portage/sync/modules/cvs/cvs.py
@@ -37,7 +37,7 @@ class CVSSync(NewBase):
"cd %s; exec cvs -z0 -d %s co -P -d %s %s" %
(portage._shell_quote(os.path.dirname(self.repo.location)), portage._shell_quote(cvs_root),
portage._shell_quote(os.path.basename(self.repo.location)),
- portage._shell_quote(self.repo.sync_cvs_repo)),
+ portage._shell_quote(self.repo.module_specific_options["sync-cvs-repo"])),
**portage._native_kwargs(self.spawn_kwargs)) != os.EX_OK:
msg = "!!! cvs checkout error; exiting."
self.logger(self.xterm_titles, msg)
diff --git a/pym/portage/sync/modules/git/__init__.py b/pym/portage/sync/modules/git/__init__.py
index a372881..da46b7f 100644
--- a/pym/portage/sync/modules/git/__init__.py
+++ b/pym/portage/sync/modules/git/__init__.py
@@ -50,6 +50,7 @@ module_spec = {
'exists and is a valid Git repository',
},
'validate_config': CheckGitConfig,
+ 'module_specific_options': (),
}
}
}
diff --git a/pym/portage/sync/modules/rsync/__init__.py b/pym/portage/sync/modules/rsync/__init__.py
index 9adc4c8..13832f8 100644
--- a/pym/portage/sync/modules/rsync/__init__.py
+++ b/pym/portage/sync/modules/rsync/__init__.py
@@ -23,6 +23,7 @@ module_spec = {
'exists': 'Returns a boolean if the specified directory exists',
},
'validate_config': CheckSyncConfig,
+ 'module_specific_options': (),
}
}
}
diff --git a/pym/portage/sync/modules/svn/__init__.py b/pym/portage/sync/modules/svn/__init__.py
index 59ab950..d7fa12c 100644
--- a/pym/portage/sync/modules/svn/__init__.py
+++ b/pym/portage/sync/modules/svn/__init__.py
@@ -26,6 +26,7 @@ module_spec = {
'exists and is a valid SVN repository',
},
'validate_config': CheckSyncConfig,
+ 'module_specific_options': (),
}
}
}
diff --git a/pym/portage/sync/modules/webrsync/__init__.py b/pym/portage/sync/modules/webrsync/__init__.py
index 5a92066..1dc64e4 100644
--- a/pym/portage/sync/modules/webrsync/__init__.py
+++ b/pym/portage/sync/modules/webrsync/__init__.py
@@ -44,6 +44,7 @@ module_spec = {
'exists and is a valid repository',
},
'validate_config': CheckSyncConfig,
+ 'module_specific_options': (),
},
}
}
--
2.0.5
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [gentoo-portage-dev] [PATCH v3 2/2] sync: Enable to set rsync extra opts per repository
2015-07-08 17:46 ` [gentoo-portage-dev] [PATCH v3 1/2] sync: allow sync modules to have specific options Étienne Buira
@ 2015-07-08 17:46 ` Étienne Buira
2015-07-14 19:52 ` [gentoo-portage-dev] [PATCH] RsyncSync: don't pass None sync-rsync-extra-opts value into shlex_split Zac Medico
0 siblings, 1 reply; 15+ messages in thread
From: Étienne Buira @ 2015-07-08 17:46 UTC (permalink / raw
To: gentoo-portage-dev; +Cc: Étienne Buira
---
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 a461ffb..eb183e2 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 = "gentoo-dev@gentoo.org"
- 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:
--
2.0.5
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [gentoo-portage-dev] [PATCH] RsyncSync: don't pass None sync-rsync-extra-opts value into shlex_split
2015-07-08 17:46 ` [gentoo-portage-dev] [PATCH v3 2/2] sync: Enable to set rsync extra opts per repository Étienne Buira
@ 2015-07-14 19:52 ` Zac Medico
2015-07-14 19:56 ` [gentoo-portage-dev] " Zac Medico
0 siblings, 1 reply; 15+ messages in thread
From: Zac Medico @ 2015-07-14 19:52 UTC (permalink / raw
To: gentoo-portage-dev; +Cc: Zac Medico
This fixes an issue with SyncLocalTestCase hanging on my system.
---
pym/portage/sync/modules/rsync/rsync.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pym/portage/sync/modules/rsync/rsync.py b/pym/portage/sync/modules/rsync/rsync.py
index 8041f07..f08bf5c 100644
--- a/pym/portage/sync/modules/rsync/rsync.py
+++ b/pym/portage/sync/modules/rsync/rsync.py
@@ -73,7 +73,7 @@ class RsyncSync(NewBase):
self.rsync_opts = self._rsync_opts_extend(opts, rsync_opts)
self.extra_rsync_opts = list()
- if 'sync-rsync-extra-opts' in self.repo.module_specific_options:
+ if self.repo.module_specific_options.get('sync-rsync-extra-opts'):
self.extra_rsync_opts.extend(portage.util.shlex_split(
self.repo.module_specific_options['sync-rsync-extra-opts']))
--
2.3.6
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [gentoo-portage-dev] Re: [PATCH] RsyncSync: don't pass None sync-rsync-extra-opts value into shlex_split
2015-07-14 19:52 ` [gentoo-portage-dev] [PATCH] RsyncSync: don't pass None sync-rsync-extra-opts value into shlex_split Zac Medico
@ 2015-07-14 19:56 ` Zac Medico
2015-07-14 20:04 ` Brian Dolbec
0 siblings, 1 reply; 15+ messages in thread
From: Zac Medico @ 2015-07-14 19:56 UTC (permalink / raw
To: gentoo-portage-dev
On Tue, Jul 14, 2015 at 12:52 PM, Zac Medico <zmedico@gentoo.org> wrote:
> This fixes an issue with SyncLocalTestCase hanging on my system.
> ---
> pym/portage/sync/modules/rsync/rsync.py | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/pym/portage/sync/modules/rsync/rsync.py b/pym/portage/sync/modules/rsync/rsync.py
> index 8041f07..f08bf5c 100644
> --- a/pym/portage/sync/modules/rsync/rsync.py
> +++ b/pym/portage/sync/modules/rsync/rsync.py
> @@ -73,7 +73,7 @@ class RsyncSync(NewBase):
> self.rsync_opts = self._rsync_opts_extend(opts, rsync_opts)
>
> self.extra_rsync_opts = list()
> - if 'sync-rsync-extra-opts' in self.repo.module_specific_options:
> + if self.repo.module_specific_options.get('sync-rsync-extra-opts'):
> self.extra_rsync_opts.extend(portage.util.shlex_split(
> self.repo.module_specific_options['sync-rsync-extra-opts']))
>
> --
> 2.3.6
>
I'm not sure if this is really the correct fix. Is there supposed to
be a None 'sync-rsync-extra-opts' value in module_specific_options?
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [gentoo-portage-dev] Re: [PATCH] RsyncSync: don't pass None sync-rsync-extra-opts value into shlex_split
2015-07-14 19:56 ` [gentoo-portage-dev] " Zac Medico
@ 2015-07-14 20:04 ` Brian Dolbec
2015-07-14 21:35 ` Brian Dolbec
0 siblings, 1 reply; 15+ messages in thread
From: Brian Dolbec @ 2015-07-14 20:04 UTC (permalink / raw
To: gentoo-portage-dev
On Tue, 14 Jul 2015 12:56:34 -0700
Zac Medico <zmedico@gentoo.org> wrote:
> On Tue, Jul 14, 2015 at 12:52 PM, Zac Medico <zmedico@gentoo.org>
> wrote:
> > This fixes an issue with SyncLocalTestCase hanging on my system.
> > ---
> > pym/portage/sync/modules/rsync/rsync.py | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/pym/portage/sync/modules/rsync/rsync.py
> > b/pym/portage/sync/modules/rsync/rsync.py index 8041f07..f08bf5c
> > 100644 --- a/pym/portage/sync/modules/rsync/rsync.py
> > +++ b/pym/portage/sync/modules/rsync/rsync.py
> > @@ -73,7 +73,7 @@ class RsyncSync(NewBase):
> > self.rsync_opts = self._rsync_opts_extend(opts,
> > rsync_opts)
> >
> > self.extra_rsync_opts = list()
> > - if 'sync-rsync-extra-opts' in
> > self.repo.module_specific_options:
> > + if
> > self.repo.module_specific_options.get('sync-rsync-extra-opts'):
> > self.extra_rsync_opts.extend(portage.util.shlex_split( self.repo.module_specific_options['sync-rsync-extra-opts']))
> >
> > --
> > 2.3.6
> >
>
> I'm not sure if this is really the correct fix. Is there supposed to
> be a None 'sync-rsync-extra-opts' value in module_specific_options?
>
I don't think so, that may have been my fault when I sent Etiene my
partial rework on his patches.
--
Brian Dolbec <dolsen>
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [gentoo-portage-dev] Re: [PATCH] RsyncSync: don't pass None sync-rsync-extra-opts value into shlex_split
2015-07-14 20:04 ` Brian Dolbec
@ 2015-07-14 21:35 ` Brian Dolbec
2015-07-21 17:18 ` Étienne Buira
0 siblings, 1 reply; 15+ messages in thread
From: Brian Dolbec @ 2015-07-14 21:35 UTC (permalink / raw
To: gentoo-portage-dev
On Tue, 14 Jul 2015 13:04:00 -0700
Brian Dolbec <dolsen@gentoo.org> wrote:
> On Tue, 14 Jul 2015 12:56:34 -0700
> Zac Medico <zmedico@gentoo.org> wrote:
>
> > On Tue, Jul 14, 2015 at 12:52 PM, Zac Medico <zmedico@gentoo.org>
> > wrote:
> > > This fixes an issue with SyncLocalTestCase hanging on my system.
> > > ---
> > > pym/portage/sync/modules/rsync/rsync.py | 2 +-
> > > 1 file changed, 1 insertion(+), 1 deletion(-)
> > >
> > > diff --git a/pym/portage/sync/modules/rsync/rsync.py
> > > b/pym/portage/sync/modules/rsync/rsync.py index 8041f07..f08bf5c
> > > 100644 --- a/pym/portage/sync/modules/rsync/rsync.py
> > > +++ b/pym/portage/sync/modules/rsync/rsync.py
> > > @@ -73,7 +73,7 @@ class RsyncSync(NewBase):
> > > self.rsync_opts = self._rsync_opts_extend(opts,
> > > rsync_opts)
> > >
> > > self.extra_rsync_opts = list()
> > > - if 'sync-rsync-extra-opts' in
> > > self.repo.module_specific_options:
> > > + if
> > > self.repo.module_specific_options.get('sync-rsync-extra-opts'):
> > > self.extra_rsync_opts.extend(portage.util.shlex_split( self.repo.module_specific_options['sync-rsync-extra-opts']))
> > >
> > > --
> > > 2.3.6
> > >
> >
> > I'm not sure if this is really the correct fix. Is there supposed to
> > be a None 'sync-rsync-extra-opts' value in module_specific_options?
> >
>
> I don't think so, that may have been my fault when I sent Etiene my
> partial rework on his patches.
>
All patches, Etiene's 2 original with some additional small fixes
rebased in, plus a few more changes have been pushed to master now
--
Brian Dolbec <dolsen>
^ permalink raw reply [flat|nested] 15+ messages in thread
* [gentoo-portage-dev] [PATCH v2 1/2] sync: allow sync modules to have specific options
2015-06-17 20:32 ` Brian Dolbec
2015-06-18 21:32 ` Étienne Buira
@ 2015-06-18 21:36 ` Étienne Buira
2015-06-18 21:36 ` [gentoo-portage-dev] [PATCH v2 2/2] sync: Enable to set rsync extra opts per repository Étienne Buira
1 sibling, 1 reply; 15+ messages in thread
From: Étienne Buira @ 2015-06-18 21:36 UTC (permalink / raw
To: gentoo-portage-dev; +Cc: Étienne Buira
---
pym/portage/repository/config.py | 34 +++++++++++++++++++++-------------
pym/portage/sync/__init__.py | 10 ++++++++++
pym/portage/sync/modules/cvs/cvs.py | 5 +++++
pym/portage/sync/syncbase.py | 5 +++++
4 files changed, 41 insertions(+), 13 deletions(-)
diff --git a/pym/portage/repository/config.py b/pym/portage/repository/config.py
index b7c969d..60eb1f2 100644
--- a/pym/portage/repository/config.py
+++ b/pym/portage/repository/config.py
@@ -86,11 +86,12 @@ class RepoConfig(object):
'find_invalid_path_char', 'force', 'format', 'local_config', 'location',
'main_repo', 'manifest_hashes', 'masters', 'missing_repo_name',
'name', 'portage1_profiles', 'portage1_profiles_compat', 'priority',
- 'profile_formats', 'sign_commit', 'sign_manifest', 'sync_cvs_repo',
+ 'profile_formats', 'sign_commit', 'sign_manifest',
'sync_depth',
'sync_type', 'sync_umask', 'sync_uri', 'sync_user', 'thin_manifest',
'update_changelog', 'user_location', '_eapis_banned',
- '_eapis_deprecated', '_masters_orig')
+ '_eapis_deprecated', '_masters_orig') + \
+ tuple(portage.sync.module_specific_options)
def __init__(self, name, repo_opts, local_config=True):
"""Build a RepoConfig with options in repo_opts
@@ -148,11 +149,6 @@ class RepoConfig(object):
priority = None
self.priority = priority
- sync_cvs_repo = repo_opts.get('sync-cvs-repo')
- if sync_cvs_repo is not None:
- sync_cvs_repo = sync_cvs_repo.strip()
- self.sync_cvs_repo = sync_cvs_repo or None
-
sync_type = repo_opts.get('sync-type')
if sync_type is not None:
sync_type = sync_type.strip()
@@ -180,6 +176,11 @@ class RepoConfig(object):
self.sync_depth = repo_opts.get('sync-depth')
+ for o in portage.sync.module_specific_options:
+ odash = o.replace('_', '-')
+ if odash in repo_opts:
+ setattr(self, o, repo_opts[odash])
+
# Not implemented.
format = repo_opts.get('format')
if format is not None:
@@ -407,8 +408,6 @@ class RepoConfig(object):
repo_msg.append(indent + "format: " + self.format)
if self.user_location:
repo_msg.append(indent + "location: " + self.user_location)
- if self.sync_cvs_repo:
- repo_msg.append(indent + "sync-cvs-repo: " + self.sync_cvs_repo)
if self.sync_type:
repo_msg.append(indent + "sync-type: " + self.sync_type)
if self.sync_umask:
@@ -426,6 +425,11 @@ class RepoConfig(object):
if self.eclass_overrides:
repo_msg.append(indent + "eclass-overrides: " + \
" ".join(self.eclass_overrides))
+ if self.sync_type is not None:
+ prefix = "sync_" + self.sync_type + "_"
+ for o in portage.sync.module_specific_options:
+ if hasattr(self, o) and o.startswith(prefix) and getattr(self, o):
+ repo_msg.append(indent + o.replace('_', '-') + ": " + getattr(self, o))
repo_msg.append("")
return "\n".join(repo_msg)
@@ -477,6 +481,9 @@ class RepoConfigLoader(object):
if prepos['DEFAULT'].masters is not None:
default_repo_opts['masters'] = \
' '.join(prepos['DEFAULT'].masters)
+ for o in portage.sync.module_specific_options:
+ if hasattr(prepos['DEFAULT'], o):
+ default_repo_opts[o.replace('_', '-')] = getattr(prepos['DEFAULT'], o)
if overlays:
# We need a copy of the original repos.conf data, since we're
@@ -503,10 +510,10 @@ class RepoConfigLoader(object):
# Selectively copy only the attributes which
# repos.conf is allowed to override.
for k in ('aliases', 'auto_sync', 'eclass_overrides',
- 'force', 'masters', 'priority', 'sync_cvs_repo',
+ 'force', 'masters', 'priority',
'sync_depth',
'sync_type', 'sync_umask', 'sync_uri', 'sync_user',
- ):
+ ) + tuple(portage.sync.module_specific_options):
v = getattr(repos_conf_opts, k, None)
if v is not None:
setattr(repo, k, v)
@@ -961,8 +968,9 @@ class RepoConfigLoader(object):
def config_string(self):
str_or_int_keys = ("auto_sync", "format", "location",
- "main_repo", "priority", "sync_cvs_repo",
+ "main_repo", "priority",
"sync_type", "sync_umask", "sync_uri", 'sync_user')
+ str_or_int_keys += tuple(portage.sync.module_specific_options)
str_tuple_keys = ("aliases", "eclass_overrides", "force")
repo_config_tuple_keys = ("masters",)
keys = str_or_int_keys + str_tuple_keys + repo_config_tuple_keys
@@ -972,7 +980,7 @@ class RepoConfigLoader(object):
for key in sorted(keys):
if key == "main_repo" and repo_name != "DEFAULT":
continue
- if getattr(repo, key) is not None:
+ if hasattr(repo, key) and getattr(repo, key) is not None:
if key in str_or_int_keys:
config_string += "%s = %s\n" % (key.replace("_", "-"), getattr(repo, key))
elif key in str_tuple_keys:
diff --git a/pym/portage/sync/__init__.py b/pym/portage/sync/__init__.py
index 51bf051..11059eb 100644
--- a/pym/portage/sync/__init__.py
+++ b/pym/portage/sync/__init__.py
@@ -25,6 +25,16 @@ module_controller = Modules(path=path, namepath="portage.sync.modules")
module_names = module_controller.module_names[:]
+def _build_module_specific_options_list():
+ modules = set()
+ for (mn, m) in [(mn, module_controller.get_class(mn)) for mn in module_names]:
+ modules.update(["sync_" + mn + "_" + opt.replace('-', '_') for opt in m.specific_options()])
+ return modules
+
+
+module_specific_options = frozenset(_build_module_specific_options_list())
+
+
def validate_config(repo, logger):
'''Validate the repos.conf settings for the repo'''
global module_names, module_controller
diff --git a/pym/portage/sync/modules/cvs/cvs.py b/pym/portage/sync/modules/cvs/cvs.py
index 9b382ab..90e256b 100644
--- a/pym/portage/sync/modules/cvs/cvs.py
+++ b/pym/portage/sync/modules/cvs/cvs.py
@@ -19,6 +19,11 @@ class CVSSync(NewBase):
return "CVSSync"
+ @staticmethod
+ def specific_options():
+ return ("repo",)
+
+
def __init__(self):
NewBase.__init__(self, "cvs", portage.const.CVS_PACKAGE_ATOM)
diff --git a/pym/portage/sync/syncbase.py b/pym/portage/sync/syncbase.py
index d30d69d..4d75f69 100644
--- a/pym/portage/sync/syncbase.py
+++ b/pym/portage/sync/syncbase.py
@@ -24,6 +24,11 @@ class SyncBase(object):
return "BlankSync"
+ @staticmethod
+ def specific_options():
+ return ()
+
+
def can_progressbar(self, func):
return False
--
2.0.5
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [gentoo-portage-dev] [PATCH v2 2/2] sync: Enable to set rsync extra opts per repository
2015-06-18 21:36 ` [gentoo-portage-dev] [PATCH v2 1/2] sync: allow sync modules to have specific options Étienne Buira
@ 2015-06-18 21:36 ` Étienne Buira
0 siblings, 0 replies; 15+ messages in thread
From: Étienne Buira @ 2015-06-18 21:36 UTC (permalink / raw
To: gentoo-portage-dev; +Cc: Étienne Buira
---
man/portage.5 | 5 +++
pym/portage/package/ebuild/config.py | 2 +
pym/portage/repository/config.py | 10 +++--
pym/portage/sync/modules/rsync/rsync.py | 11 ++++-
pym/portage/tests/sync/test_sync_local.py | 73 ++++++++++++++++++++++++++++---
5 files changed, 89 insertions(+), 12 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 60eb1f2..8c16cb3 100644
--- a/pym/portage/repository/config.py
+++ b/pym/portage/repository/config.py
@@ -550,9 +550,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:
@@ -622,6 +622,7 @@ class RepoConfigLoader(object):
treemap = {}
ignored_map = {}
ignored_location_map = {}
+ default_opts = {}
if "PORTAGE_REPOSITORIES" in settings:
portdir = ""
@@ -634,10 +635,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/rsync.py b/pym/portage/sync/modules/rsync/rsync.py
index d84c36d..2237901 100644
--- a/pym/portage/sync/modules/rsync/rsync.py
+++ b/pym/portage/sync/modules/rsync/rsync.py
@@ -44,6 +44,11 @@ class RsyncSync(NewBase):
return "RsyncSync"
+ @staticmethod
+ def specific_options():
+ return ("extra-opts",)
+
+
def __init__(self):
NewBase.__init__(self, "rsync", RSYNC_PACKAGE_ATOM)
@@ -72,8 +77,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 self.repo.sync_rsync_extra_opts is not None:
+ self.extra_rsync_opts.extend(portage.util.shlex_split(
+ self.repo.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 = "gentoo-dev@gentoo.org"
- 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:
--
2.0.5
^ permalink raw reply related [flat|nested] 15+ messages in thread
end of thread, other threads:[~2015-07-21 17:18 UTC | newest]
Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-06-17 18:40 [gentoo-portage-dev] [PATCH] conf: Enable to set rsync extra opts per repository Étienne Buira
2015-06-17 20:32 ` Brian Dolbec
2015-06-18 21:32 ` Étienne Buira
2015-07-06 18:28 ` Brian Dolbec
2015-07-06 22:05 ` Brian Dolbec
2015-07-08 17:45 ` Étienne Buira
2015-07-08 17:46 ` [gentoo-portage-dev] [PATCH v3 1/2] sync: allow sync modules to have specific options Étienne Buira
2015-07-08 17:46 ` [gentoo-portage-dev] [PATCH v3 2/2] sync: Enable to set rsync extra opts per repository Étienne Buira
2015-07-14 19:52 ` [gentoo-portage-dev] [PATCH] RsyncSync: don't pass None sync-rsync-extra-opts value into shlex_split Zac Medico
2015-07-14 19:56 ` [gentoo-portage-dev] " Zac Medico
2015-07-14 20:04 ` Brian Dolbec
2015-07-14 21:35 ` Brian Dolbec
2015-07-21 17:18 ` Étienne Buira
2015-06-18 21:36 ` [gentoo-portage-dev] [PATCH v2 1/2] sync: allow sync modules to have specific options Étienne Buira
2015-06-18 21:36 ` [gentoo-portage-dev] [PATCH v2 2/2] sync: Enable to set rsync extra opts per repository Étienne Buira
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox