aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Harder <radhermit@gmail.com>2015-06-28 02:40:13 -0400
committerTim Harder <radhermit@gmail.com>2015-06-28 04:34:23 -0400
commitc4d518e70d51a721b1a1714e5b35d84c4a6aa436 (patch)
tree6d09e6259393516ab9d1328e633f8d923a2ed893
parentportage_conf: don't try to load /etc/make.globals anymore (diff)
downloadpkgcore-c4d518e70d51a721b1a1714e5b35d84c4a6aa436.tar.gz
pkgcore-c4d518e70d51a721b1a1714e5b35d84c4a6aa436.tar.bz2
pkgcore-c4d518e70d51a721b1a1714e5b35d84c4a6aa436.zip
fs/livefs: add sorted_scan() to return regular, nonhidden files
Mostly the same thing is being used in a several places throughout the code.
-rw-r--r--pkgcore/ebuild/portage_conf.py15
-rw-r--r--pkgcore/ebuild/profiles.py11
-rw-r--r--pkgcore/ebuild/repository.py5
-rw-r--r--pkgcore/fs/livefs.py27
-rw-r--r--pkgcore/test/fs/test_livefs.py24
5 files changed, 58 insertions, 24 deletions
diff --git a/pkgcore/ebuild/portage_conf.py b/pkgcore/ebuild/portage_conf.py
index e7e1d2f1..e47b5be5 100644
--- a/pkgcore/ebuild/portage_conf.py
+++ b/pkgcore/ebuild/portage_conf.py
@@ -25,12 +25,12 @@ from pkgcore import const
from pkgcore.config import basics, configurable
from pkgcore.ebuild import const as econst, profiles
from pkgcore.ebuild.repo_objs import RepoConfig
+from pkgcore.fs.livefs import sorted_scan
from pkgcore.pkgsets.glsa import SecurityUpgrades
demandload(
'errno',
'pkgcore.config:errors',
- 'pkgcore.fs.livefs:iter_scan',
'pkgcore.log:logger',
)
@@ -293,16 +293,10 @@ def load_repos_conf(path):
directory, if a directory is passed all the non-hidden files within
that directory are parsed in alphabetical order.
"""
- if os.path.isdir(path):
- files = iter_scan(path)
- files = sorted(x.location for x in files if x.is_reg
- and not x.basename.startswith('.'))
- else:
- files = [path]
-
defaults = {}
repos = {}
- for fp in files:
+
+ for fp in sorted_scan(path, nonexistent=True):
try:
with open(fp) as f:
config = ConfigParser()
@@ -588,8 +582,7 @@ def config_from_make_conf(location="/etc/", profile_override=None, **kwargs):
# now add the fetcher- we delay it till here to clean out the environ
# it passes to the command.
# *everything* in make_conf must be str values also.
- distdir = normpath(os.environ.get(
- "DISTDIR", make_conf.pop("DISTDIR")))
+ distdir = normpath(os.environ.get("DISTDIR", make_conf.pop("DISTDIR")))
add_fetcher(config, make_conf, distdir)
# finally... domain.
diff --git a/pkgcore/ebuild/profiles.py b/pkgcore/ebuild/profiles.py
index fe9dc035..9ce0b27f 100644
--- a/pkgcore/ebuild/profiles.py
+++ b/pkgcore/ebuild/profiles.py
@@ -32,7 +32,7 @@ demandload(
'pkgcore.ebuild:cpv,repo_objs',
'pkgcore.ebuild.atom:atom',
'pkgcore.ebuild.eapi:get_eapi',
- 'pkgcore.fs.livefs:iter_scan',
+ 'pkgcore.fs.livefs:sorted_scan',
'pkgcore.repository.util:SimpleTree',
'pkgcore.restrictions:packages',
)
@@ -92,14 +92,7 @@ def _load_and_invoke(func, filename, handler, fallback, read_func,
else:
data = []
profile_len = len(profile_path) + 1
- try:
- files = iter_scan(base)
- files = sorted(x.location for x in files if x.is_reg
- and not x.basename.startswith('.'))
- except EnvironmentError as e:
- if errno.ENOENT != e.errno:
- raise
- files = []
+ files = sorted_scan(base)
if not files:
data = None
else:
diff --git a/pkgcore/ebuild/repository.py b/pkgcore/ebuild/repository.py
index 5d23788a..e471cefe 100644
--- a/pkgcore/ebuild/repository.py
+++ b/pkgcore/ebuild/repository.py
@@ -36,7 +36,7 @@ demandload(
'snakeoil.data_source:local_source',
'pkgcore.ebuild:ebd,digest,repo_objs,atom,profiles,processor',
'pkgcore.ebuild:errors@ebuild_errors',
- 'pkgcore.fs.livefs:iter_scan',
+ 'pkgcore.fs.livefs:sorted_scan',
'pkgcore.log:logger',
'pkgcore.package:errors@pkg_errors',
'pkgcore.util.packages:groupby_pkg',
@@ -454,8 +454,7 @@ class _UnconfiguredTree(prototype.tree):
pos, neg = [], []
try:
if not self.config.profile_formats.intersection(['pms', 'portage-2']):
- paths = sorted(x.location for x in iter_scan(path)
- if x.is_reg)
+ paths = sorted_scan(path)
else:
paths = [path]
for path in paths:
diff --git a/pkgcore/fs/livefs.py b/pkgcore/fs/livefs.py
index 91503a0b..8d613882 100644
--- a/pkgcore/fs/livefs.py
+++ b/pkgcore/fs/livefs.py
@@ -20,7 +20,7 @@ from pkgcore.fs.contents import contentsSet
from pkgcore.fs.fs import (
fsFile, fsDir, fsSymlink, fsDev, fsFifo, get_major_minor, fsBase)
-__all__ = ["gen_obj", "scan", "iter_scan"]
+__all__ = ["gen_obj", "scan", "iter_scan", "sorted_scan"]
def gen_chksums(handlers, location):
@@ -152,6 +152,31 @@ def iter_scan(path, offset=None, follow_symlinks=False, chksum_types=None):
return _internal_offset_iter_scan(path, chksum_handlers, offset, stat_func)
+def sorted_scan(path, nonexistent=False, *args, **kwargs):
+ """
+ Recursively scan a path for regular, nonhidden files.
+
+ :return: a list of regular, nonhidden file locations accessible under the
+ given path
+
+ :param path: str path of what directory to scan in the livefs
+ :param nonexistent: return nonexistent given path if True, else return
+ an empty list
+
+ Look at :py:func:`iter_scan` for other valid args.
+ """
+ files = [path] if nonexistent else []
+
+ try:
+ files = sorted(x.location for x in iter_scan(path, *args, **kwargs)
+ if x.is_reg and not x.basename.startswith('.'))
+ except EnvironmentError as e:
+ if e.errno != errno.ENOENT:
+ raise
+
+ return files
+
+
def scan(*a, **kw):
"""Alias for list(iter_scan(\*a, \*\*kw))
diff --git a/pkgcore/test/fs/test_livefs.py b/pkgcore/test/fs/test_livefs.py
index 5f786fd4..b49af3af 100644
--- a/pkgcore/test/fs/test_livefs.py
+++ b/pkgcore/test/fs/test_livefs.py
@@ -103,6 +103,30 @@ class FsObjsTest(TempDirMixin, TestCase):
seen.append(obj.location)
self.assertEqual((files[0],), tuple(sorted(seen)))
+ def test_sorted_scan(self):
+ path = os.path.join(self.dir, "sorted_scan")
+ os.mkdir(path)
+ files = [os.path.normpath(os.path.join(path, x)) for x in
+ ["tmp", "blah", "dar", ".foo", ".bar"]]
+ # cheap version of a touch.
+ map(lambda x: open(x, "w").close(), files)
+ dirs = [os.path.normpath(os.path.join(path, x)) for x in [
+ "a", "b", "c"]]
+ map(os.mkdir, dirs)
+
+ # regular directory scanning
+ sorted_files = livefs.sorted_scan(path)
+ self.assertEqual(
+ list(map(lambda x: pjoin(path, x), ['blah', 'dar', 'tmp'])),
+ sorted_files)
+
+ # nonexistent paths
+ nonexistent_path = os.path.join(self.dir, 'foobar')
+ sorted_files = livefs.sorted_scan(nonexistent_path)
+ self.assertEqual(sorted_files, [])
+ sorted_files = livefs.sorted_scan(nonexistent_path, nonexistent=True)
+ self.assertEqual(sorted_files, [nonexistent_path])
+
def test_relative_sym(self):
f = os.path.join(self.dir, "relative-symlink-test")