public inbox for gentoo-portage-dev@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Étienne Buira" <etienne.buira@gmail.com>
To: gentoo-portage-dev@lists.gentoo.org
Cc: "Étienne Buira" <etienne.buira@gmail.com>
Subject: [gentoo-portage-dev] [PATCH v3 1/2] sync: allow sync modules to have specific options
Date: Wed,  8 Jul 2015 19:46:41 +0200	[thread overview]
Message-ID: <1436377602-10820-1-git-send-email-etienne.buira@gmail.com> (raw)
In-Reply-To: <20150708174531.GA29970@rcKGHUlyQfVFW>

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



  reply	other threads:[~2015-07-08 17:47 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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         ` Étienne Buira [this message]
2015-07-08 17:46           ` [gentoo-portage-dev] [PATCH v3 2/2] sync: " É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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1436377602-10820-1-git-send-email-etienne.buira@gmail.com \
    --to=etienne.buira@gmail.com \
    --cc=gentoo-portage-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox