make _glob an iterator, and remove it from RuntimeBuilder.cleanup()

This commit is contained in:
Will Woods 2011-06-30 11:13:09 -04:00
parent da2b53d91f
commit 75d1b6562b

View File

@ -104,17 +104,19 @@ def brace_expand(s):
for alt in brace_expand(prefix+choice+suffix): for alt in brace_expand(prefix+choice+suffix):
yield alt yield alt
def _glob(globpat, root="/", fatal=True): def _glob(pathname, root="/", fatal=True):
files_found = set() seen = set()
for g in brace_expand(globpat): rootlen = len(root)+1
files_found.update(glob.glob(joinpaths(root, g))) for g in brace_expand(pathname):
if fatal and not files_found: for f in glob.iglob(joinpaths(root, g)):
raise IOError, "nothing matching %s" % joinpaths(root, globpat) if f not in seen:
return [f.replace(root+os.path.sep,"",1) for f in files_found] seen.add(f)
yield f[rootlen:] # remove the root to produce relative path
def _exists(path, root=""): if fatal and not seen:
return (len(_glob(path, root, fatal=False)) > 0) raise IOError, "nothing matching %s in %s" % (pathname, root)
def _exists(pathname, root=""):
return True if _glob(pathname, root) else False
class RuntimeBuilder(object): class RuntimeBuilder(object):
'''Builds the anaconda runtime image.''' '''Builds the anaconda runtime image.'''
@ -149,8 +151,8 @@ class RuntimeBuilder(object):
# get removelocales list first # get removelocales list first
localedir = joinpaths(self.vars.root, "usr/share/locale") localedir = joinpaths(self.vars.root, "usr/share/locale")
langtable = joinpaths(self.vars.root, "usr/share/anaconda/lang-table") langtable = joinpaths(self.vars.root, "usr/share/anaconda/lang-table")
locales = set([basename(d) for d in _glob(localedir+"/*") if isdir(d)]) locales = set([d for d in os.listdir(localedir) if isdir(joinpaths(localedir,d))])
keeplocales = set([line.split()[1] for line in open(langtable)]) keeplocales = [line.split()[1] for line in open(langtable)]
removelocales = locales.difference(keeplocales) removelocales = locales.difference(keeplocales)
self._runner.run("runtime-cleanup.tmpl", removelocales=removelocales) self._runner.run("runtime-cleanup.tmpl", removelocales=removelocales)