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:
parent
2f927118a7
commit
eb22c69f29
@ -1,6 +1,5 @@
|
||||
<%page args="configdir, KERNELDIR, efiarch, isolabel"/>
|
||||
<%
|
||||
from string import lower
|
||||
EFIBOOTDIR="EFI/BOOT"
|
||||
APPLE_EFI_ICON=inroot+"/usr/share/pixmaps/bootloader/fedora.icns"
|
||||
APPLE_EFI_DISKNAME=inroot+"/usr/share/pixmaps/bootloader/fedora-media.vol"
|
||||
|
@ -1,6 +1,5 @@
|
||||
<%page args="configdir, KERNELDIR, efiarch, isolabel"/>
|
||||
<%
|
||||
from string import lower
|
||||
EFIBOOTDIR="EFI/BOOT"
|
||||
APPLE_EFI_ICON=inroot+"/usr/share/pixmaps/bootloader/fedora.icns"
|
||||
APPLE_EFI_DISKNAME=inroot+"/usr/share/pixmaps/bootloader/fedora-media.vol"
|
||||
|
@ -69,9 +69,6 @@ class LoraxTemplate(object):
|
||||
# remove comments
|
||||
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
|
||||
lines = [split_and_expand(line) for line in lines]
|
||||
|
||||
@ -302,7 +299,7 @@ class LoraxTemplateRunner(object):
|
||||
append /etc/resolv.conf ""
|
||||
'''
|
||||
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):
|
||||
'''
|
||||
@ -431,10 +428,8 @@ class LoraxTemplateRunner(object):
|
||||
# TODO: add ssh-keygen, mkisofs(?), find, and other useful commands
|
||||
def runcmd(self, *cmdlist):
|
||||
'''
|
||||
runcmd CMD [--chdir=DIR] [ARG ...]
|
||||
runcmd CMD [ARG ...]
|
||||
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
|
||||
or files mentioned. ${root}/${inroot}/${outroot} are good for
|
||||
@ -451,15 +446,14 @@ class LoraxTemplateRunner(object):
|
||||
remove ${f}
|
||||
%endfor
|
||||
'''
|
||||
cwd = None
|
||||
cmd = cmdlist
|
||||
logger.debug('running command: %s', cmd)
|
||||
if cmd[0].startswith("--chdir="):
|
||||
cwd = cmd[0].split('=',1)[1]
|
||||
cmd = cmd[1:]
|
||||
logger.error("--chdir is no longer supported for runcmd.")
|
||||
raise ValueError("--chdir is no longer supported for runcmd.")
|
||||
|
||||
try:
|
||||
stdout = runcmd_output(cmd, cwd=cwd)
|
||||
stdout = runcmd_output(cmd)
|
||||
if stdout:
|
||||
logger.debug('command output:\n%s', stdout)
|
||||
logger.debug("command finished successfully")
|
||||
|
@ -193,7 +193,7 @@ class TreeBuilder(object):
|
||||
inroot=inroot, outroot=outroot,
|
||||
basearch=arch.basearch, libdir=arch.libdir,
|
||||
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.defaults = self.vars
|
||||
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
|
||||
def udev_escape(label):
|
||||
out = ''
|
||||
for ch in label.decode('utf8'):
|
||||
for ch in label:
|
||||
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()
|
||||
|
@ -34,7 +34,7 @@ class TreeInfo(object):
|
||||
self.c = configparser.ConfigParser()
|
||||
|
||||
section = "general"
|
||||
data = {"timestamp": time.time(),
|
||||
data = {"timestamp": str(time.time()),
|
||||
"family": product,
|
||||
"version": version,
|
||||
"name": "%s-%s" % (product, version),
|
||||
|
Loading…
Reference in New Issue
Block a user