Additional python3 changes

Add a 'lower' filter to the templates to replace string.lower which no
longer exists. Fix udev_escape, the strings are already unicode, and
drop --chdir from runcmd. It wasn't ever used, and passing cwd to the
new runcmd isn't supported.
This commit is contained in:
Brian C. Lane 2015-05-07 12:31:16 -07:00
parent 2f927118a7
commit eb22c69f29
5 changed files with 18 additions and 17 deletions

View File

@ -1,6 +1,5 @@
<%page args="configdir, KERNELDIR, efiarch, isolabel"/> <%page args="configdir, KERNELDIR, efiarch, isolabel"/>
<% <%
from string import lower
EFIBOOTDIR="EFI/BOOT" EFIBOOTDIR="EFI/BOOT"
APPLE_EFI_ICON=inroot+"/usr/share/pixmaps/bootloader/fedora.icns" APPLE_EFI_ICON=inroot+"/usr/share/pixmaps/bootloader/fedora.icns"
APPLE_EFI_DISKNAME=inroot+"/usr/share/pixmaps/bootloader/fedora-media.vol" APPLE_EFI_DISKNAME=inroot+"/usr/share/pixmaps/bootloader/fedora-media.vol"

View File

@ -1,6 +1,5 @@
<%page args="configdir, KERNELDIR, efiarch, isolabel"/> <%page args="configdir, KERNELDIR, efiarch, isolabel"/>
<% <%
from string import lower
EFIBOOTDIR="EFI/BOOT" EFIBOOTDIR="EFI/BOOT"
APPLE_EFI_ICON=inroot+"/usr/share/pixmaps/bootloader/fedora.icns" APPLE_EFI_ICON=inroot+"/usr/share/pixmaps/bootloader/fedora.icns"
APPLE_EFI_DISKNAME=inroot+"/usr/share/pixmaps/bootloader/fedora-media.vol" APPLE_EFI_DISKNAME=inroot+"/usr/share/pixmaps/bootloader/fedora-media.vol"

View File

@ -69,9 +69,6 @@ class LoraxTemplate(object):
# remove comments # remove comments
lines = [line for line in lines if not line.startswith("#")] lines = [line for line in lines if not line.startswith("#")]
# mako template now returns unicode strings
lines = [line.encode("utf8") for line in lines]
# split with shlex and perform brace expansion # split with shlex and perform brace expansion
lines = [split_and_expand(line) for line in lines] lines = [split_and_expand(line) for line in lines]
@ -302,7 +299,7 @@ class LoraxTemplateRunner(object):
append /etc/resolv.conf "" append /etc/resolv.conf ""
''' '''
with open(self._out(filename), "a") as fobj: with open(self._out(filename), "a") as fobj:
fobj.write(data.decode('string_escape')+"\n") fobj.write(bytes(data, "utf8").decode('unicode_escape')+"\n")
def treeinfo(self, section, key, *valuetoks): def treeinfo(self, section, key, *valuetoks):
''' '''
@ -431,10 +428,8 @@ class LoraxTemplateRunner(object):
# TODO: add ssh-keygen, mkisofs(?), find, and other useful commands # TODO: add ssh-keygen, mkisofs(?), find, and other useful commands
def runcmd(self, *cmdlist): def runcmd(self, *cmdlist):
''' '''
runcmd CMD [--chdir=DIR] [ARG ...] runcmd CMD [ARG ...]
Run the given command with the given arguments. Run the given command with the given arguments.
If "--chdir=DIR" is given, change to the named directory
before executing the command.
NOTE: All paths given MUST be COMPLETE, ABSOLUTE PATHS to the file NOTE: All paths given MUST be COMPLETE, ABSOLUTE PATHS to the file
or files mentioned. ${root}/${inroot}/${outroot} are good for or files mentioned. ${root}/${inroot}/${outroot} are good for
@ -451,15 +446,14 @@ class LoraxTemplateRunner(object):
remove ${f} remove ${f}
%endfor %endfor
''' '''
cwd = None
cmd = cmdlist cmd = cmdlist
logger.debug('running command: %s', cmd) logger.debug('running command: %s', cmd)
if cmd[0].startswith("--chdir="): if cmd[0].startswith("--chdir="):
cwd = cmd[0].split('=',1)[1] logger.error("--chdir is no longer supported for runcmd.")
cmd = cmd[1:] raise ValueError("--chdir is no longer supported for runcmd.")
try: try:
stdout = runcmd_output(cmd, cwd=cwd) stdout = runcmd_output(cmd)
if stdout: if stdout:
logger.debug('command output:\n%s', stdout) logger.debug('command output:\n%s', stdout)
logger.debug("command finished successfully") logger.debug("command finished successfully")

View File

@ -193,7 +193,7 @@ class TreeBuilder(object):
inroot=inroot, outroot=outroot, inroot=inroot, outroot=outroot,
basearch=arch.basearch, libdir=arch.libdir, basearch=arch.basearch, libdir=arch.libdir,
isolabel=isolabel, udev=udev_escape, domacboot=domacboot, doupgrade=doupgrade, isolabel=isolabel, udev=udev_escape, domacboot=domacboot, doupgrade=doupgrade,
workdir=workdir) workdir=workdir, lower=string_lower)
self._runner = LoraxTemplateRunner(inroot, outroot, templatedir=templatedir) self._runner = LoraxTemplateRunner(inroot, outroot, templatedir=templatedir)
self._runner.defaults = self.vars self._runner.defaults = self.vars
self.add_templates = add_templates or [] self.add_templates = add_templates or []
@ -325,6 +325,15 @@ udev_blacklist=' !"$%&\'()*,/;<>?[\\]^`{|}~' # ASCII printable, minus whitelist
udev_blacklist += ''.join(chr(i) for i in range(32)) # ASCII non-printable udev_blacklist += ''.join(chr(i) for i in range(32)) # ASCII non-printable
def udev_escape(label): def udev_escape(label):
out = '' out = ''
for ch in label.decode('utf8'): for ch in label:
out += ch if ch not in udev_blacklist else '\\x%02x' % ord(ch) out += ch if ch not in udev_blacklist else '\\x%02x' % ord(ch)
return out.encode('utf8') return out
def string_lower(string):
""" Return a lowercase string.
:param string: String to lowercase
This is used as a filter in the templates.
"""
return string.lower()

View File

@ -34,7 +34,7 @@ class TreeInfo(object):
self.c = configparser.ConfigParser() self.c = configparser.ConfigParser()
section = "general" section = "general"
data = {"timestamp": time.time(), data = {"timestamp": str(time.time()),
"family": product, "family": product,
"version": version, "version": version,
"name": "%s-%s" % (product, version), "name": "%s-%s" % (product, version),