add a placeholder for repository paths in 'filename' and 'directory' options for...
authorMarius Mauch <genone@gentoo.org>
Sat, 15 Mar 2008 19:33:45 +0000 (19:33 -0000)
committerMarius Mauch <genone@gentoo.org>
Sat, 15 Mar 2008 19:33:45 +0000 (19:33 -0000)
svn path=/main/trunk/; revision=9469

pym/portage/sets/files.py

index 683756ec506908c8990b073c676b6b9bcd2a2de5..ab9a12fe13277ae59a0eda0cc01f9bf8836fa386 100644 (file)
@@ -4,6 +4,7 @@
 
 import errno
 import os
+import re
 from itertools import chain
 
 from portage.util import grabfile, write_atomic, ensure_dirs
@@ -20,7 +21,9 @@ __all__ = ["StaticFileSet", "ConfigFileSet", "WorldSet"]
 
 class StaticFileSet(EditablePackageSet):
        _operations = ["merge", "unmerge"]
-       
+       _repopath_match = re.compile(r'.*\$\{repository:(?P<reponame>.+)\}.*')
+       _repopath_sub = re.compile(r'\$\{repository:(?P<reponame>.+)\}')
+               
        def __init__(self, filename, greedy=False, dbapi=None):
                super(StaticFileSet, self).__init__()
                self._filename = filename
@@ -94,16 +97,25 @@ class StaticFileSet(EditablePackageSet):
                if not "filename" in options:
                        raise SetConfigError("no filename specified")
                greedy = get_boolean(options, "greedy", True)
-               return StaticFileSet(options["filename"], greedy=greedy, dbapi=trees["vartree"].dbapi)
+               filename = options["filename"]
+               # look for repository path variables
+               match = self._repopath_match.match(filename)
+               if match:
+                       filename = self._repopath_sub.sub(trees["porttree"].dbapi.treemap[match.groupdict()["reponame"]], filename)
+               return StaticFileSet(filename, greedy=greedy, dbapi=trees["vartree"].dbapi)
        singleBuilder = classmethod(singleBuilder)
        
        def multiBuilder(self, options, settings, trees):
                rValue = {}
                directory = options.get("directory", os.path.join(settings["PORTAGE_CONFIGROOT"], USER_CONFIG_PATH.lstrip(os.sep), "sets"))
-               name_pattern = options.get("name_pattern", "sets/$name")
+               name_pattern = options.get("name_pattern", "sets/${name}")
                if not "$name" in name_pattern and not "${name}" in name_pattern:
-                       raise SetConfigError("name_pattern doesn't include $name placeholder")
+                       raise SetConfigError("name_pattern doesn't include ${name} placeholder")
                greedy = get_boolean(options, "greedy", True)
+               # look for repository path variables
+               match = self._repopath_match.match(directory)
+               if match:
+                       directory = self._repopath_sub.sub(trees["porttree"].dbapi.treemap[match.groupdict()["reponame"]], directory)
                if os.path.isdir(directory):
                        for filename in os.listdir(directory):
                                if filename.endswith(".metadata"):