As requested by jmbsvicetto, add support to StaticFileSet for sets within
authorZac Medico <zmedico@gentoo.org>
Sat, 20 Sep 2008 18:55:07 +0000 (18:55 -0000)
committerZac Medico <zmedico@gentoo.org>
Sat, 20 Sep 2008 18:55:07 +0000 (18:55 -0000)
subdirectories. This makes it possible to create a set name foo/bar by
placing a file named bar inside a directory named foo. By allowing sets
to be organized in subdirectories, it will allow us to avoid overcrowding
as the number of sets grows.

svn path=/main/trunk/; revision=11527

pym/portage/sets/files.py

index e02c1e7b2a3494a287f0a2edd4fd60108938e519..c9e71a3324e86d96fdacd3494f47df02c411c090 100644 (file)
@@ -7,7 +7,7 @@ import os
 import re
 from itertools import chain
 
-from portage.util import grabfile, write_atomic, ensure_dirs
+from portage.util import grabfile, write_atomic, ensure_dirs, normalize_path
 from portage.const import PRIVATE_PATH, USER_CONFIG_PATH
 from portage.locks import lockfile, unlockfile
 from portage import portage_gid
@@ -123,12 +123,18 @@ class StaticFileSet(EditablePackageSet):
                        except KeyError:
                                raise SetConfigError("Could not find repository '%s'" % match.groupdict()["reponame"])
                if os.path.isdir(directory):
-                       for filename in os.listdir(directory):
-                               if filename.endswith(".metadata"):
-                                       continue
-                               myname = name_pattern.replace("$name", filename)
-                               myname = myname.replace("${name}", filename)
-                               rValue[myname] = StaticFileSet(os.path.join(directory, filename), greedy=greedy, dbapi=trees["vartree"].dbapi)
+                       directory = normalize_path(directory)
+                       for parent, dirs, files in os.walk(directory):
+                               for filename in files:
+                                       if filename.endswith(".metadata"):
+                                               continue
+                                       filename = os.path.join(parent,
+                                               filename)[1 + len(directory):]
+                                       myname = name_pattern.replace("$name", filename)
+                                       myname = myname.replace("${name}", filename)
+                                       rValue[myname] = StaticFileSet(
+                                               os.path.join(directory, filename),
+                                               greedy=greedy, dbapi=trees["vartree"].dbapi)
                return rValue
        multiBuilder = classmethod(multiBuilder)