ltmpl: do brace expansion on the entire template
Handle brace expansion while parsing the template rather than individually per-command. This is closer to how bash does things anyway.
This commit is contained in:
parent
d61ae8c1e6
commit
f5164d6460
@ -59,14 +59,17 @@ class LoraxTemplate(object):
|
|||||||
lines = filter(lambda line: not line.startswith("#"), lines)
|
lines = filter(lambda line: not line.startswith("#"), lines)
|
||||||
|
|
||||||
# mako template now returns unicode strings
|
# mako template now returns unicode strings
|
||||||
lines = map(lambda line: line.encode("ascii"), lines)
|
lines = map(lambda line: line.encode("utf8"), lines)
|
||||||
|
|
||||||
# split with shlex
|
# split with shlex and perform brace expansion
|
||||||
lines = map(shlex.split, lines)
|
lines = map(split_and_expand, lines)
|
||||||
|
|
||||||
self.lines = lines
|
self.lines = lines
|
||||||
return lines
|
return lines
|
||||||
|
|
||||||
|
def split_and_expand(line):
|
||||||
|
return [exp for word in shlex.split(line) for exp in brace_expand(word)]
|
||||||
|
|
||||||
def brace_expand(s):
|
def brace_expand(s):
|
||||||
if not ('{' in s and ',' in s and '}' in s):
|
if not ('{' in s and ',' in s and '}' in s):
|
||||||
yield s
|
yield s
|
||||||
@ -81,11 +84,10 @@ def brace_expand(s):
|
|||||||
def rglob(pathname, root="/", fatal=False):
|
def rglob(pathname, root="/", fatal=False):
|
||||||
seen = set()
|
seen = set()
|
||||||
rootlen = len(root)+1
|
rootlen = len(root)+1
|
||||||
for g in brace_expand(pathname):
|
for f in glob.iglob(joinpaths(root, pathname)):
|
||||||
for f in glob.iglob(joinpaths(root, g)):
|
if f not in seen:
|
||||||
if f not in seen:
|
seen.add(f)
|
||||||
seen.add(f)
|
yield f[rootlen:] # remove the root to produce relative path
|
||||||
yield f[rootlen:] # remove the root to produce relative path
|
|
||||||
if fatal and not seen:
|
if fatal and not seen:
|
||||||
raise IOError, "nothing matching %s in %s" % (pathname, root)
|
raise IOError, "nothing matching %s in %s" % (pathname, root)
|
||||||
|
|
||||||
@ -252,10 +254,7 @@ class LoraxTemplateRunner(object):
|
|||||||
self.yum.closeRpmDB()
|
self.yum.closeRpmDB()
|
||||||
|
|
||||||
def removefrom(self, pkg, *globs):
|
def removefrom(self, pkg, *globs):
|
||||||
globset = set()
|
globs_re = re.compile("|".join([fnmatch.translate(g) for g in globs]))
|
||||||
for g in globs:
|
|
||||||
globset.update(brace_expand(g))
|
|
||||||
globs_re = re.compile("|".join([fnmatch.translate(g) for g in globset]))
|
|
||||||
remove = filter(globs_re.match, self._filelist(pkg))
|
remove = filter(globs_re.match, self._filelist(pkg))
|
||||||
logger.debug("removing %i files from %s", len(remove), pkg)
|
logger.debug("removing %i files from %s", len(remove), pkg)
|
||||||
self.remove(*remove)
|
self.remove(*remove)
|
||||||
|
Loading…
Reference in New Issue
Block a user