From 3aab1f4ca10a7d9136c4176e6a69e29bb84beea9 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Tue, 5 Oct 2010 15:10:28 -0700 Subject: Add _gen_valid_repo() to ensure valid repo name. --- pym/portage/repository/config.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/pym/portage/repository/config.py b/pym/portage/repository/config.py index bbe62229a..e99073dfa 100644 --- a/pym/portage/repository/config.py +++ b/pym/portage/repository/config.py @@ -19,6 +19,19 @@ from portage import _encodings _repo_name_sub_re = re.compile(r'[^\w-]') +def _gen_valid_repo(name): + """ + Substitute hyphen in place of characters that don't conform to PMS 3.1.5, + and strip hyphen from left side if necessary. This returns None if the + given name contains no valid characters. + """ + name = _repo_name_sub_re.sub(' ', name.strip()) + name = '-'.join(name.split()) + name = name.lstrip('-') + if not name: + name = None + return name + class RepoConfig(object): """Stores config of one repository""" @@ -78,17 +91,13 @@ class RepoConfig(object): # We must ensure that the name conforms to PMS 3.1.5 # in order to avoid InvalidAtom exceptions when we # use it to generate atoms. - name = _repo_name_sub_re.sub(' ', name.strip()) - name = '-'.join(name.split()) - name = name.lstrip('-') + name = _gen_valid_repo(name) if not name: # name only contains invalid characters name = "x-" + os.path.basename(self.location) - name = _repo_name_sub_re.sub(' ', name.strip()) - name = '-'.join(name.split()) - name = name.lstrip('-') + name = _gen_valid_repo(name) # If basename only contains whitespace then the - # end result is name = 'x'. + # end result is name = 'x-'. elif name == "DEFAULT": missing = False -- cgit v1.2.3-1-g7c22