Add "getdata" method to LoraxTemplate
getdata(cmd) will return a generator that yields every token on every line that starts with the token "cmd". getdata(cmd, mode="lines") will yield a list for each line rather than every individual token. this simplifies some things in __init__.py.
This commit is contained in:
parent
b186317213
commit
a82da40015
@ -34,7 +34,6 @@ import os
|
||||
import ConfigParser
|
||||
import tempfile
|
||||
import shutil
|
||||
import itertools
|
||||
import glob
|
||||
import math
|
||||
import subprocess
|
||||
@ -201,24 +200,15 @@ class Lorax(BaseLoraxClass):
|
||||
"product": self.product.name.lower() }
|
||||
|
||||
template = ltmpl.LoraxTemplate()
|
||||
template = template.parse(tfile, tvars)
|
||||
template.parse(tfile, tvars)
|
||||
|
||||
# get required directories
|
||||
logger.info("creating tree directories")
|
||||
dirs = [f[1:] for f in template if f[0] == "mkdir"]
|
||||
dirs = itertools.chain.from_iterable(dirs)
|
||||
|
||||
# create directories
|
||||
for d in dirs:
|
||||
for d in template.getdata("mkdir"):
|
||||
os.makedirs(joinpaths(self.installtree.root, d))
|
||||
|
||||
# get list of required packages
|
||||
logger.info("getting list of required packages")
|
||||
required = [f[1:] for f in template if f[0] == "install"]
|
||||
required = itertools.chain.from_iterable(required)
|
||||
|
||||
# install packages
|
||||
for package in required:
|
||||
logger.info("getting list of required packages")
|
||||
for package in template.getdata("install"):
|
||||
self.installtree.yum.install(package)
|
||||
|
||||
skipbroken = self.conf.getboolean("yum", "skipbroken")
|
||||
@ -252,8 +242,8 @@ class Lorax(BaseLoraxClass):
|
||||
self.installtree.move_stubs()
|
||||
|
||||
logger.info("getting list of required modules")
|
||||
modules = [f[1:] for f in template if f[0] == "module"]
|
||||
modules = list(itertools.chain.from_iterable(modules))
|
||||
# Need a list to pass to cleanup_kernel_modules, not a generator
|
||||
modules = list(template.getdata("module"))
|
||||
|
||||
self.installtree.move_modules()
|
||||
|
||||
@ -319,7 +309,7 @@ class Lorax(BaseLoraxClass):
|
||||
i.backup_required(self.workdir)
|
||||
|
||||
logger.info("getting list of not required packages")
|
||||
remove = [f[1:] for f in template if f[0] == "remove"]
|
||||
remove = template.getdata("remove", mode="lines")
|
||||
|
||||
rdb = {}
|
||||
order = []
|
||||
|
@ -56,4 +56,13 @@ class LoraxTemplate(object):
|
||||
# split with shlex
|
||||
lines = map(shlex.split, lines)
|
||||
|
||||
self.lines = lines
|
||||
return lines
|
||||
|
||||
def getdata(self, cmd, mode="tokens"):
|
||||
'''returns a generator that yields every token on every line starting
|
||||
with 'cmd'. if mode is "lines", you get a list for each line instead.'''
|
||||
if mode == "lines":
|
||||
return (f[1:] for f in self.lines if f[0]==cmd)
|
||||
else:
|
||||
return (i for f in self.lines if f[0]==cmd for i in f[1:])
|
||||
|
Loading…
Reference in New Issue
Block a user