Blob Blame History Raw
From ac19a179deba767a6edafc8477ae168652039f5e Mon Sep 17 00:00:00 2001
From: Richard Hughes <richard@hughsie.com>
Date: Wed, 6 Jun 2018 12:10:59 +0100
Subject: [PATCH 2/4] Do not use Python version 3

---
 contrib/firmware-packager/firmware-packager |  2 +-
 data/installed-tests/hardware.py            |  2 +-
 libfwupd/generate-version-script.py         |  2 +-
 po/make-images                              | 23 +++++++++++----------
 po/test-deps                                |  2 +-
 5 files changed, 16 insertions(+), 15 deletions(-)

diff --git a/contrib/firmware-packager/firmware-packager b/contrib/firmware-packager/firmware-packager
index 23e543ce..23658e6c 100755
--- a/contrib/firmware-packager/firmware-packager
+++ b/contrib/firmware-packager/firmware-packager
@@ -1,4 +1,4 @@
-#!/usr/bin/env python3
+#!/usr/bin/env python
 #
 # Copyright (C) 2017 Max Ehrlich max.ehr@gmail.com
 #
diff --git a/data/installed-tests/hardware.py b/data/installed-tests/hardware.py
index 026b5086..d79529ce 100755
--- a/data/installed-tests/hardware.py
+++ b/data/installed-tests/hardware.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python3
+#!/usr/bin/python
 # pylint: disable=wrong-import-position,too-many-locals,unused-argument,wrong-import-order
 #
 # Copyright (C) 2017 Richard Hughes <richard@hughsie.com>
diff --git a/libfwupd/generate-version-script.py b/libfwupd/generate-version-script.py
index a2dff9ba..e94c16c2 100755
--- a/libfwupd/generate-version-script.py
+++ b/libfwupd/generate-version-script.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python3
+#!/usr/bin/env python
 # pylint: disable=invalid-name,missing-docstring
 #
 # Copyright (C) 2017 Richard Hughes <richard@hughsie.com>
diff --git a/po/make-images b/po/make-images
index 9f5bd4bc..de9254f7 100755
--- a/po/make-images
+++ b/po/make-images
@@ -1,4 +1,4 @@
-#!/usr/bin/env python3
+#!/usr/bin/env python
 """ This thing rasterizes text for use later """
 
 # pylint: disable=wrong-import-position,too-many-locals,unused-argument
@@ -80,11 +80,11 @@ class Rasterizer:
             PangoCairo.context_set_font_options(pctx, fo)
 
             attrs = Pango.AttrList()
-            length = len(bytes(string, "utf8"))
+            length = len(string)
             items = Pango.itemize(pctx, string, 0, length, attrs, None)
             gs = Pango.GlyphString()
             Pango.shape(string, length, items[0].analysis, gs)
-            del img, cctx, pctx, layout
+            #del img, cctx, pctx, layout
 
             def find_size(fs, f, data):
                 """ find our size, I hope... """
@@ -102,11 +102,11 @@ class Rasterizer:
             log = data['log']
             ink = data['ink']
 
-            height = math.ceil(max(ink.height, log.height) / Pango.SCALE)
-            width = math.ceil(max(ink.width, log.width) / Pango.SCALE)
+            height = int(math.ceil(max(ink.height, log.height) / Pango.SCALE))
+            width = int(math.ceil(max(ink.width, log.width) / Pango.SCALE))
 
-            x = -math.ceil(log.x / Pango.SCALE)
-            y = -math.ceil(log.y / Pango.SCALE)
+            x = int(-math.ceil(log.x / Pango.SCALE))
+            y = int(-math.ceil(log.y / Pango.SCALE))
 
             img = cairo.ImageSurface(cairo.FORMAT_RGB24, width, height)
             cctx = cairo.Context(img)
@@ -129,7 +129,7 @@ class Rasterizer:
                 tmpname = filename[len(os.environ['DESTDIR']):]
             except KeyError:
                 tmpname = filename[len(os.environ['MESON_BUILD_ROOT']):]
-            print("Writing %s                    " % (tmpname,), end='\r')
+            print("Writing %s                    " % (tmpname,))
             def make_dir(d):
                 """ make our parent dir and then our own dir """
                 if os.access(d, os.O_RDWR):
@@ -167,7 +167,9 @@ class Rasterizer:
                 nameinfo.update({'width': width,
                                  'height': height,
                                  'suffix': 'bmp'})
-                filename = self.pattern.format_map(nameinfo)
+                filename = self.pattern
+                for key in nameinfo:
+                    filename = filename.replace('{' + key + '}', str(nameinfo[key]))
                 render_one(lang, string, width, height, filename)
         print("")
 
@@ -177,7 +179,6 @@ if __name__ == '__main__':
     if len(sys.argv) != 4:
         usage(1)
 
-    label = os.fsencode(sys.argv[1]).decode('utf-8')
-    r = Rasterizer(label=label, modir=sys.argv[2],
+    r = Rasterizer(label=sys.argv[1], modir=sys.argv[2],
                    linguas=sys.argv[3])
     r.render()
diff --git a/po/test-deps b/po/test-deps
index cc8c9fd0..4d2be2da 100755
--- a/po/test-deps
+++ b/po/test-deps
@@ -1,4 +1,4 @@
-#!/usr/bin/env python3
+#!/usr/bin/env python
 """ Check dependencies needed for rasterization """
 
 """
-- 
2.17.1