commit: f7e0e0a96364d651ac43a2774e0d94ecc5838387 Author: Brian Dolbec <dolsen <AT> gentoo <DOT> org> AuthorDate: Tue Jun 3 18:00:05 2014 +0000 Commit: Brian Dolbec <brian.dolbec <AT> gmail <DOT> com> CommitDate: Wed Oct 1 22:58:13 2014 +0000 URL: http://sources.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=f7e0e0a9
Repoman: Refactor repos.RepoSettings class, fix the repoman_settings not being re-assigned When the repo is not in the confiig'd repos, it creates a ne repoman_settings object which contains the temporaily activated repo. main.py was not re-assigning repoman_settings to the new object. Split out _add_repo() to it's own function. Split out the gpg-sign specific function for git into plugin-ready functions, for later. --- pym/repoman/main.py | 2 + pym/repoman/repos.py | 119 ++++++++++++++++++++++++++++++++------------------- 2 files changed, 77 insertions(+), 44 deletions(-) diff --git a/pym/repoman/main.py b/pym/repoman/main.py index 3b5296b..47ada0c 100755 --- a/pym/repoman/main.py +++ b/pym/repoman/main.py @@ -135,6 +135,8 @@ vcs_settings = VCSSettings(options, repoman_settings) repo_settings = RepoSettings(config_root, portdir, portdir_overlay, repoman_settings, vcs_settings, options, qawarnings) +repoman_settings = repo_settings.repoman_settings + portdb = repo_settings.portdb ################## diff --git a/pym/repoman/repos.py b/pym/repoman/repos.py index b79e241..6bd1eb4 100644 --- a/pym/repoman/repos.py +++ b/pym/repoman/repos.py @@ -26,75 +26,46 @@ class RepoSettings(object): def __init__(self, config_root, portdir, portdir_overlay, repoman_settings=None, vcs_settings=None, options=None, qawarnings=None): + self.repoman_settings = repoman_settings + self.vcs_settings = vcs_settings + # Ensure that current repository is in the list of enabled repositories. self.repodir = os.path.realpath(portdir_overlay) try: repoman_settings.repositories.get_repo_for_location(self.repodir) except KeyError: - self.repo_conf = portage.repository.config - self.repo_name = self.repo_conf.RepoConfig._read_valid_repo_name(portdir_overlay)[0] - self.layout_conf_data = self.repo_conf.parse_layout_conf(portdir_overlay)[0] - if self.layout_conf_data['repo-name']: - self.repo_name = self.layout_conf_data['repo-name'] - tmp_conf_file = io.StringIO(textwrap.dedent(""" - [%s] - location = %s - """) % (self.repo_name, portdir_overlay)) - # Ensure that the repository corresponding to $PWD overrides a - # repository of the same name referenced by the existing PORTDIR - # or PORTDIR_OVERLAY settings. - repoman_settings['PORTDIR_OVERLAY'] = "%s %s" % ( - repoman_settings.get('PORTDIR_OVERLAY', ''), - portage._shell_quote(portdir_overlay)) - self.repositories = self.repo_conf.load_repository_config( - repoman_settings, extra_files=[tmp_conf_file]) - # We have to call the config constructor again so that attributes - # dependent on config.repositories are initialized correctly. - repoman_settings = portage.config( - config_root=config_root, local_config=False, repositories=self.repositories) + self._add_repo(config_root, portdir_overlay) - self.root = repoman_settings['EROOT'] + self.root = self.repoman_settings['EROOT'] self.trees = { - self.root: {'porttree': portage.portagetree(settings=repoman_settings)} + self.root: {'porttree': portage.portagetree(settings=self.repoman_settings)} } self.portdb = self.trees[self.root]['porttree'].dbapi # Constrain dependency resolution to the master(s) # that are specified in layout.conf. - self.repo_config = repoman_settings.repositories.get_repo_for_location(self.repodir) + self.repo_config = self.repoman_settings.repositories.get_repo_for_location(self.repodir) self.portdb.porttrees = list(self.repo_config.eclass_db.porttrees) self.portdir = self.portdb.porttrees[0] self.commit_env = os.environ.copy() # list() is for iteration on a copy. - for repo in list(repoman_settings.repositories): + for repo in list(self.repoman_settings.repositories): # all paths are canonical if repo.location not in self.repo_config.eclass_db.porttrees: - del repoman_settings.repositories[repo.name] + del self.repoman_settings.repositories[repo.name] if self.repo_config.allow_provide_virtual: qawarnings.add("virtual.oldstyle") if self.repo_config.sign_commit: - if vcs_settings.vcs == 'git': - # NOTE: It's possible to use --gpg-sign=key_id to specify the key in - # the commit arguments. If key_id is unspecified, then it must be - # configured by `git config user.signingkey key_id`. - vcs_settings.vcs_local_opts.append("--gpg-sign") - if repoman_settings.get("PORTAGE_GPG_DIR"): - # Pass GNUPGHOME to git for bug #462362. - self.commit_env["GNUPGHOME"] = repoman_settings["PORTAGE_GPG_DIR"] - - # Pass GPG_TTY to git for bug #477728. - try: - self.commit_env["GPG_TTY"] = os.ttyname(sys.stdin.fileno()) - except OSError: - pass + func = getattr(self, '_vcs_gpg_%s' % vcs_settings.vcs) + func() # In order to disable manifest signatures, repos may set # "sign-manifests = false" in metadata/layout.conf. This # can be used to prevent merge conflicts like those that # thin-manifests is designed to prevent. - self.sign_manifests = "sign" in repoman_settings.features and \ + self.sign_manifests = "sign" in self.repoman_settings.features and \ self.repo_config.sign_manifest if self.repo_config.sign_manifest and self.repo_config.name == "gentoo" and \ @@ -110,13 +81,13 @@ class RepoSettings(object): logging.warn(line) is_commit = options.mode in ("commit",) - valid_gpg_key = repoman_settings.get("PORTAGE_GPG_KEY") and re.match( - r'^%s$' % GPG_KEY_ID_REGEX, repoman_settings["PORTAGE_GPG_KEY"]) + valid_gpg_key = self.repoman_settings.get("PORTAGE_GPG_KEY") and re.match( + r'^%s$' % GPG_KEY_ID_REGEX, self.repoman_settings["PORTAGE_GPG_KEY"]) if self.sign_manifests and is_commit and not valid_gpg_key: logging.error( "PORTAGE_GPG_KEY value is invalid: %s" % - repoman_settings["PORTAGE_GPG_KEY"]) + self.repoman_settings["PORTAGE_GPG_KEY"]) sys.exit(1) manifest_hashes = self.repo_config.manifest_hashes @@ -150,6 +121,66 @@ class RepoSettings(object): logging.error(line) sys.exit(1) + + def _add_repo(self, config_root, portdir_overlay): + self.repo_conf = portage.repository.config + self.repo_name = self.repo_conf.RepoConfig._read_valid_repo_name(portdir_overlay)[0] + self.layout_conf_data = self.repo_conf.parse_layout_conf(portdir_overlay)[0] + if self.layout_conf_data['repo-name']: + self.repo_name = self.layout_conf_data['repo-name'] + tmp_conf_file = io.StringIO(textwrap.dedent(""" + [%s] + location = %s + """) % (self.repo_name, portdir_overlay)) + # Ensure that the repository corresponding to $PWD overrides a + # repository of the same name referenced by the existing PORTDIR + # or PORTDIR_OVERLAY settings. + self.repoman_settings['PORTDIR_OVERLAY'] = "%s %s" % ( + self.repoman_settings.get('PORTDIR_OVERLAY', ''), + portage._shell_quote(portdir_overlay)) + self.repositories = self.repo_conf.load_repository_config( + self.repoman_settings, extra_files=[tmp_conf_file]) + # We have to call the config constructor again so that attributes + # dependent on config.repositories are initialized correctly. + self.repoman_settings = portage.config( + config_root=config_root, local_config=False, repositories=self.repositories) + + ########### future vcs plugin functions + + def _vcs_gpg_bzr(self): + pass + + + def _vcs_gpg_cvs(self): + pass + + + def _vcs_gpg_git(self): + # NOTE: It's possible to use --gpg-sign=key_id to specify the key in + # the commit arguments. If key_id is unspecified, then it must be + # configured by `git config user.signingkey key_id`. + self.vcs_settings.vcs_local_opts.append("--gpg-sign") + if self.repoman_settings.get("PORTAGE_GPG_DIR"): + # Pass GNUPGHOME to git for bug #462362. + self.commit_env["GNUPGHOME"] = self.repoman_settings["PORTAGE_GPG_DIR"] + + # Pass GPG_TTY to git for bug #477728. + try: + self.commit_env["GPG_TTY"] = os.ttyname(sys.stdin.fileno()) + except OSError: + pass + + + def _vcs_gpg_hg(self): + pass + + + def _vcs_gpg_svn(self): + pass + + + + def list_checks(kwlist, liclist, uselist, repoman_settings): liclist_deprecated = set() if "DEPRECATED" in repoman_settings._license_manager._license_groups: