[master 5/11] Additional python3 changes
bcl
installerbot-noreply at redhat.com
Sat May 9 00:59:11 UTC 2015
From: "Brian C. Lane" <bcl at redhat.com>
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.
---
share/efi.tmpl | 1 -
share/live/efi.tmpl | 1 -
src/pylorax/ltmpl.py | 16 +++++-----------
src/pylorax/treebuilder.py | 15 ++++++++++++---
src/pylorax/treeinfo.py | 2 +-
5 files changed, 18 insertions(+), 17 deletions(-)
diff --git a/share/efi.tmpl b/share/efi.tmpl
index c82e1c7..e2585d8 100644
--- a/share/efi.tmpl
+++ b/share/efi.tmpl
@@ -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"
diff --git a/share/live/efi.tmpl b/share/live/efi.tmpl
index 54e1e15..009790c 100644
--- a/share/live/efi.tmpl
+++ b/share/live/efi.tmpl
@@ -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"
diff --git a/src/pylorax/ltmpl.py b/src/pylorax/ltmpl.py
index df39e98..93ecd14 100644
--- a/src/pylorax/ltmpl.py
+++ b/src/pylorax/ltmpl.py
@@ -69,9 +69,6 @@ def parse(self, template_file, variables):
# 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 @@ def append(self, filename, data):
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 @@ def log(self, msg):
# 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 @@ def runcmd(self, *cmdlist):
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")
diff --git a/src/pylorax/treebuilder.py b/src/pylorax/treebuilder.py
index efd5909..bea9bcb 100644
--- a/src/pylorax/treebuilder.py
+++ b/src/pylorax/treebuilder.py
@@ -193,7 +193,7 @@ def __init__(self, product, arch, inroot, outroot, runtime, isolabel, domacboot=
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 @@ def findkernels(root="/", kdir="boot"):
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()
diff --git a/src/pylorax/treeinfo.py b/src/pylorax/treeinfo.py
index 538a27e..4c84006 100644
--- a/src/pylorax/treeinfo.py
+++ b/src/pylorax/treeinfo.py
@@ -34,7 +34,7 @@ def __init__(self, product, version, variant, basearch,
self.c = configparser.ConfigParser()
section = "general"
- data = {"timestamp": time.time(),
+ data = {"timestamp": str(time.time()),
"family": product,
"version": version,
"name": "%s-%s" % (product, version),
--
To view this commit on github, visit https://github.com/rhinstaller/lorax/commit/a6a30955cef9ed6c60d4762157d1355cca09af28
More information about the anaconda-patches
mailing list