Gentoo Archives: gentoo-portage-dev

From: "Étienne Buira" <etienne.buira@×××××.com>
To: gentoo-portage-dev@l.g.o
Cc: "Étienne Buira" <etienne.buira@×××××.com>
Subject: [gentoo-portage-dev] [PATCH v3 1/2] sync: allow sync modules to have specific options
Date: Wed, 08 Jul 2015 17:47:20
Message-Id: 1436377602-10820-1-git-send-email-etienne.buira@gmail.com
In Reply to: Re: [gentoo-portage-dev] [PATCH] conf: Enable to set rsync extra opts per repository by "Étienne Buira"
1 With appreciated help from Brian Dolbec.
2 ---
3 pym/portage/repository/config.py | 30 ++++++++++++++++-----------
4 pym/portage/sync/__init__.py | 12 +++++++++++
5 pym/portage/sync/modules/cvs/__init__.py | 3 ++-
6 pym/portage/sync/modules/cvs/cvs.py | 2 +-
7 pym/portage/sync/modules/git/__init__.py | 1 +
8 pym/portage/sync/modules/rsync/__init__.py | 1 +
9 pym/portage/sync/modules/svn/__init__.py | 1 +
10 pym/portage/sync/modules/webrsync/__init__.py | 1 +
11 8 files changed, 37 insertions(+), 14 deletions(-)
12
13 diff --git a/pym/portage/repository/config.py b/pym/portage/repository/config.py
14 index b7c969d..a461ffb 100644
15 --- a/pym/portage/repository/config.py
16 +++ b/pym/portage/repository/config.py
17 @@ -86,11 +86,12 @@ class RepoConfig(object):
18 'find_invalid_path_char', 'force', 'format', 'local_config', 'location',
19 'main_repo', 'manifest_hashes', 'masters', 'missing_repo_name',
20 'name', 'portage1_profiles', 'portage1_profiles_compat', 'priority',
21 - 'profile_formats', 'sign_commit', 'sign_manifest', 'sync_cvs_repo',
22 + 'profile_formats', 'sign_commit', 'sign_manifest',
23 'sync_depth',
24 'sync_type', 'sync_umask', 'sync_uri', 'sync_user', 'thin_manifest',
25 'update_changelog', 'user_location', '_eapis_banned',
26 - '_eapis_deprecated', '_masters_orig')
27 + '_eapis_deprecated', '_masters_orig', 'module_specific_options',
28 + )
29
30 def __init__(self, name, repo_opts, local_config=True):
31 """Build a RepoConfig with options in repo_opts
32 @@ -148,11 +149,6 @@ class RepoConfig(object):
33 priority = None
34 self.priority = priority
35
36 - sync_cvs_repo = repo_opts.get('sync-cvs-repo')
37 - if sync_cvs_repo is not None:
38 - sync_cvs_repo = sync_cvs_repo.strip()
39 - self.sync_cvs_repo = sync_cvs_repo or None
40 -
41 sync_type = repo_opts.get('sync-type')
42 if sync_type is not None:
43 sync_type = sync_type.strip()
44 @@ -180,6 +176,8 @@ class RepoConfig(object):
45
46 self.sync_depth = repo_opts.get('sync-depth')
47
48 + self.module_specific_options = {}
49 +
50 # Not implemented.
51 format = repo_opts.get('format')
52 if format is not None:
53 @@ -280,6 +278,9 @@ class RepoConfig(object):
54 self._eapis_banned = frozenset(layout_data['eapis-banned'])
55 self._eapis_deprecated = frozenset(layout_data['eapis-deprecated'])
56
57 + def set_module_specific_opt(self, opt, val):
58 + self.module_specific_options[opt] = val
59 +
60 def eapi_is_banned(self, eapi):
61 return eapi in self._eapis_banned
62
63 @@ -407,8 +408,6 @@ class RepoConfig(object):
64 repo_msg.append(indent + "format: " + self.format)
65 if self.user_location:
66 repo_msg.append(indent + "location: " + self.user_location)
67 - if self.sync_cvs_repo:
68 - repo_msg.append(indent + "sync-cvs-repo: " + self.sync_cvs_repo)
69 if self.sync_type:
70 repo_msg.append(indent + "sync-type: " + self.sync_type)
71 if self.sync_umask:
72 @@ -426,6 +425,9 @@ class RepoConfig(object):
73 if self.eclass_overrides:
74 repo_msg.append(indent + "eclass-overrides: " + \
75 " ".join(self.eclass_overrides))
76 + for o, v in self.module_specific_options.items():
77 + if v is not None:
78 + repo_msg.append(indent + o + ": " + v)
79 repo_msg.append("")
80 return "\n".join(repo_msg)
81
82 @@ -503,10 +505,10 @@ class RepoConfigLoader(object):
83 # Selectively copy only the attributes which
84 # repos.conf is allowed to override.
85 for k in ('aliases', 'auto_sync', 'eclass_overrides',
86 - 'force', 'masters', 'priority', 'sync_cvs_repo',
87 + 'force', 'masters', 'priority',
88 'sync_depth',
89 'sync_type', 'sync_umask', 'sync_uri', 'sync_user',
90 - ):
91 + ) + portage.sync.module_specific_options(repo, logging):
92 v = getattr(repos_conf_opts, k, None)
93 if v is not None:
94 setattr(repo, k, v)
95 @@ -598,6 +600,8 @@ class RepoConfigLoader(object):
96 optdict[oname] = parser.get(sname, oname)
97
98 repo = RepoConfig(sname, optdict, local_config=local_config)
99 + for o in portage.sync.module_specific_options(repo):
100 + repo.set_module_specific_opt(o, parser.get(sname, o))
101
102 # Perform repos.conf sync variable validation
103 portage.sync.validate_config(repo, logging)
104 @@ -961,7 +965,7 @@ class RepoConfigLoader(object):
105
106 def config_string(self):
107 str_or_int_keys = ("auto_sync", "format", "location",
108 - "main_repo", "priority", "sync_cvs_repo",
109 + "main_repo", "priority",
110 "sync_type", "sync_umask", "sync_uri", 'sync_user')
111 str_tuple_keys = ("aliases", "eclass_overrides", "force")
112 repo_config_tuple_keys = ("masters",)
113 @@ -979,6 +983,8 @@ class RepoConfigLoader(object):
114 config_string += "%s = %s\n" % (key.replace("_", "-"), " ".join(getattr(repo, key)))
115 elif key in repo_config_tuple_keys:
116 config_string += "%s = %s\n" % (key.replace("_", "-"), " ".join(x.name for x in getattr(repo, key)))
117 + for o, v in repo.module_specific_options.items():
118 + config_string += "%s = %s\n" % (o, v)
119 return config_string.lstrip("\n")
120
121 def load_repository_config(settings, extra_files=None):
122 diff --git a/pym/portage/sync/__init__.py b/pym/portage/sync/__init__.py
123 index 51bf051..b0e0ebe 100644
124 --- a/pym/portage/sync/__init__.py
125 +++ b/pym/portage/sync/__init__.py
126 @@ -25,6 +25,18 @@ module_controller = Modules(path=path, namepath="portage.sync.modules")
127 module_names = module_controller.module_names[:]
128
129
130 +def module_specific_options(repo):
131 + '''Get the authorized module specific options set for
132 + the repos.conf settings for the repo'''
133 + global module_controller
134 +
135 + if repo.sync_type:
136 + opts = frozenset([opt for opt in
137 + module_controller.modules[repo.sync_type]['module_specific_options']])
138 + return opts
139 + return frozenset()
140 +
141 +
142 def validate_config(repo, logger):
143 '''Validate the repos.conf settings for the repo'''
144 global module_names, module_controller
145 diff --git a/pym/portage/sync/modules/cvs/__init__.py b/pym/portage/sync/modules/cvs/__init__.py
146 index 0f4a029..952053a 100644
147 --- a/pym/portage/sync/modules/cvs/__init__.py
148 +++ b/pym/portage/sync/modules/cvs/__init__.py
149 @@ -18,7 +18,7 @@ class CheckCVSConfig(CheckSyncConfig):
150
151
152 def check_cvs_repo(self):
153 - if self.repo.sync_cvs_repo is None:
154 + if self.repo.module_specific_options['sync-cvs-repo'] is None:
155 writemsg_level("!!! %s\n" %
156 _("Repository '%s' has sync-type=cvs, but is missing sync-cvs-repo attribute")
157 % self.repo.name, level=self.logger.ERROR, noiselevel=-1)
158 @@ -40,6 +40,7 @@ module_spec = {
159 'exists and is a valid CVS repository',
160 },
161 'validate_config': CheckCVSConfig,
162 + 'module_specific_options': ("sync-cvs-repo",),
163 }
164 }
165 }
166 diff --git a/pym/portage/sync/modules/cvs/cvs.py b/pym/portage/sync/modules/cvs/cvs.py
167 index 9b382ab..7b7908b 100644
168 --- a/pym/portage/sync/modules/cvs/cvs.py
169 +++ b/pym/portage/sync/modules/cvs/cvs.py
170 @@ -37,7 +37,7 @@ class CVSSync(NewBase):
171 "cd %s; exec cvs -z0 -d %s co -P -d %s %s" %
172 (portage._shell_quote(os.path.dirname(self.repo.location)), portage._shell_quote(cvs_root),
173 portage._shell_quote(os.path.basename(self.repo.location)),
174 - portage._shell_quote(self.repo.sync_cvs_repo)),
175 + portage._shell_quote(self.repo.module_specific_options["sync-cvs-repo"])),
176 **portage._native_kwargs(self.spawn_kwargs)) != os.EX_OK:
177 msg = "!!! cvs checkout error; exiting."
178 self.logger(self.xterm_titles, msg)
179 diff --git a/pym/portage/sync/modules/git/__init__.py b/pym/portage/sync/modules/git/__init__.py
180 index a372881..da46b7f 100644
181 --- a/pym/portage/sync/modules/git/__init__.py
182 +++ b/pym/portage/sync/modules/git/__init__.py
183 @@ -50,6 +50,7 @@ module_spec = {
184 'exists and is a valid Git repository',
185 },
186 'validate_config': CheckGitConfig,
187 + 'module_specific_options': (),
188 }
189 }
190 }
191 diff --git a/pym/portage/sync/modules/rsync/__init__.py b/pym/portage/sync/modules/rsync/__init__.py
192 index 9adc4c8..13832f8 100644
193 --- a/pym/portage/sync/modules/rsync/__init__.py
194 +++ b/pym/portage/sync/modules/rsync/__init__.py
195 @@ -23,6 +23,7 @@ module_spec = {
196 'exists': 'Returns a boolean if the specified directory exists',
197 },
198 'validate_config': CheckSyncConfig,
199 + 'module_specific_options': (),
200 }
201 }
202 }
203 diff --git a/pym/portage/sync/modules/svn/__init__.py b/pym/portage/sync/modules/svn/__init__.py
204 index 59ab950..d7fa12c 100644
205 --- a/pym/portage/sync/modules/svn/__init__.py
206 +++ b/pym/portage/sync/modules/svn/__init__.py
207 @@ -26,6 +26,7 @@ module_spec = {
208 'exists and is a valid SVN repository',
209 },
210 'validate_config': CheckSyncConfig,
211 + 'module_specific_options': (),
212 }
213 }
214 }
215 diff --git a/pym/portage/sync/modules/webrsync/__init__.py b/pym/portage/sync/modules/webrsync/__init__.py
216 index 5a92066..1dc64e4 100644
217 --- a/pym/portage/sync/modules/webrsync/__init__.py
218 +++ b/pym/portage/sync/modules/webrsync/__init__.py
219 @@ -44,6 +44,7 @@ module_spec = {
220 'exists and is a valid repository',
221 },
222 'validate_config': CheckSyncConfig,
223 + 'module_specific_options': (),
224 },
225 }
226 }
227 --
228 2.0.5

Replies

Subject Author
[gentoo-portage-dev] [PATCH v3 2/2] sync: Enable to set rsync extra opts per repository "Étienne Buira" <etienne.buira@×××××.com>