summaryrefslogtreecommitdiffstats
path: root/pym/portage/repository
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2010-10-05 15:10:28 -0700
committerZac Medico <zmedico@gentoo.org>2010-10-05 15:10:28 -0700
commit3aab1f4ca10a7d9136c4176e6a69e29bb84beea9 (patch)
treecaced978c9f294655b41f4afc0a8ea636f4205df /pym/portage/repository
parent9ff5e9731142d389373ea6ebc949919c3b637110 (diff)
downloadportage-3aab1f4ca10a7d9136c4176e6a69e29bb84beea9.tar.gz
portage-3aab1f4ca10a7d9136c4176e6a69e29bb84beea9.tar.bz2
portage-3aab1f4ca10a7d9136c4176e6a69e29bb84beea9.zip
Add _gen_valid_repo() to ensure valid repo name.
Diffstat (limited to 'pym/portage/repository')
-rw-r--r--pym/portage/repository/config.py23
1 files 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