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 ConfigParser
|
||||||
import tempfile
|
import tempfile
|
||||||
import shutil
|
import shutil
|
||||||
import itertools
|
|
||||||
import glob
|
import glob
|
||||||
import math
|
import math
|
||||||
import subprocess
|
import subprocess
|
||||||
@ -201,24 +200,15 @@ class Lorax(BaseLoraxClass):
|
|||||||
"product": self.product.name.lower() }
|
"product": self.product.name.lower() }
|
||||||
|
|
||||||
template = ltmpl.LoraxTemplate()
|
template = ltmpl.LoraxTemplate()
|
||||||
template = template.parse(tfile, tvars)
|
template.parse(tfile, tvars)
|
||||||
|
|
||||||
# get required directories
|
|
||||||
logger.info("creating tree directories")
|
logger.info("creating tree directories")
|
||||||
dirs = [f[1:] for f in template if f[0] == "mkdir"]
|
for d in template.getdata("mkdir"):
|
||||||
dirs = itertools.chain.from_iterable(dirs)
|
|
||||||
|
|
||||||
# create directories
|
|
||||||
for d in dirs:
|
|
||||||
os.makedirs(joinpaths(self.installtree.root, d))
|
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
|
# install packages
|
||||||
for package in required:
|
logger.info("getting list of required packages")
|
||||||
|
for package in template.getdata("install"):
|
||||||
self.installtree.yum.install(package)
|
self.installtree.yum.install(package)
|
||||||
|
|
||||||
skipbroken = self.conf.getboolean("yum", "skipbroken")
|
skipbroken = self.conf.getboolean("yum", "skipbroken")
|
||||||
@ -252,8 +242,8 @@ class Lorax(BaseLoraxClass):
|
|||||||
self.installtree.move_stubs()
|
self.installtree.move_stubs()
|
||||||
|
|
||||||
logger.info("getting list of required modules")
|
logger.info("getting list of required modules")
|
||||||
modules = [f[1:] for f in template if f[0] == "module"]
|
# Need a list to pass to cleanup_kernel_modules, not a generator
|
||||||
modules = list(itertools.chain.from_iterable(modules))
|
modules = list(template.getdata("module"))
|
||||||
|
|
||||||
self.installtree.move_modules()
|
self.installtree.move_modules()
|
||||||
|
|
||||||
@ -319,7 +309,7 @@ class Lorax(BaseLoraxClass):
|
|||||||
i.backup_required(self.workdir)
|
i.backup_required(self.workdir)
|
||||||
|
|
||||||
logger.info("getting list of not required packages")
|
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 = {}
|
rdb = {}
|
||||||
order = []
|
order = []
|
||||||
|
@ -56,4 +56,13 @@ class LoraxTemplate(object):
|
|||||||
# split with shlex
|
# split with shlex
|
||||||
lines = map(shlex.split, lines)
|
lines = map(shlex.split, lines)
|
||||||
|
|
||||||
|
self.lines = lines
|
||||||
return 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