summaryrefslogtreecommitdiffstats
path: root/pym/portage/repository
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2010-10-02 10:00:18 -0700
committerZac Medico <zmedico@gentoo.org>2010-10-02 10:00:18 -0700
commit86ea3834dcb002bbe9e095771aedbbc85f539748 (patch)
tree9c02aa23c8273e22da6dc3e5f20f82f192d77e98 /pym/portage/repository
parent20c90e275d3fc9826fbafb4e80e3007730b9de1e (diff)
downloadportage-86ea3834dcb002bbe9e095771aedbbc85f539748.tar.gz
portage-86ea3834dcb002bbe9e095771aedbbc85f539748.tar.bz2
portage-86ea3834dcb002bbe9e095771aedbbc85f539748.zip
Bug #339402 - Ensure valid repo name.
Diffstat (limited to 'pym/portage/repository')
-rw-r--r--pym/portage/repository/config.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/pym/portage/repository/config.py b/pym/portage/repository/config.py
index acaec70bb..0e2507a82 100644
--- a/pym/portage/repository/config.py
+++ b/pym/portage/repository/config.py
@@ -3,6 +3,7 @@
import codecs
import logging
+import re
try:
from configparser import SafeConfigParser, ParsingError
@@ -16,6 +17,8 @@ from portage.localization import _
from portage import _unicode_encode
from portage import _encodings
+_repo_name_sub_re = re.compile(r'[^\w-]')
+
class RepoConfig(object):
"""Stores config of one repository"""
@@ -72,7 +75,21 @@ class RepoConfig(object):
missing = True
if self.location is not None:
name, missing = self._read_repo_name(self.location)
+ # 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('-')
+ 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('-')
+ # If basename only contains whitespace then the
+ # end result is name = 'x'.
+
elif name == "DEFAULT":
missing = False
self.name = name