commit:     23ce474e516b278e5ee04a31aab6d47b1b3df0fb
Author:     Étienne Buira <etienne.buira <AT> gmail <DOT> com>
AuthorDate: Wed Jul  8 17:46:41 2015 +0000
Commit:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Tue Jul 14 21:27:42 2015 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=23ce474e

sync: allow sync modules to have specific options

With appreciated help from Brian Dolbec.
Fixed leading whitespace.

 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..ef14f13 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': (),
                },
        }
 }

Reply via email to