[jhbuild/another-round] Python 3 fixes for extdeps/goalreport/systemininstall



commit ee051834b81b70d16a8ac2a6423d813507132d04
Author: Christoph Reiter <reiter christoph gmail com>
Date:   Mon Sep 23 18:14:31 2019 +0200

    Python 3 fixes for extdeps/goalreport/systemininstall
    
    Found while going through all commands and various options.

 jhbuild/commands/extdeps.py    | 12 ++++++------
 jhbuild/commands/goalreport.py | 14 +++++++-------
 jhbuild/utils/systeminstall.py | 12 ++++++------
 3 files changed, 19 insertions(+), 19 deletions(-)
---
diff --git a/jhbuild/commands/extdeps.py b/jhbuild/commands/extdeps.py
index a04fd700..6eb14745 100644
--- a/jhbuild/commands/extdeps.py
+++ b/jhbuild/commands/extdeps.py
@@ -25,8 +25,8 @@ import socket
 import sys
 import time
 
-from jhbuild.utils import _
-from jhbuild.utils.compat import cmp, BytesIO
+from jhbuild.utils import _, open_text
+from jhbuild.utils.compat import TextIO
 
 import jhbuild.moduleset
 from jhbuild.commands import Command, register_command
@@ -80,7 +80,7 @@ class cmd_extdeps(Command):
 
     def run(self, config, options, args, help=None):
         if options.output:
-            output = BytesIO()
+            output = TextIO()
         else:
             output = sys.stdout
 
@@ -108,7 +108,7 @@ class cmd_extdeps(Command):
         print('<table>', file=output)
         print('<tbody>', file=output)
 
-        module_list.sort(lambda x,y: cmp(x.name.lower(), y.name.lower()))
+        module_list.sort(key=lambda x: x.name.lower())
         for mod in module_list:
             # if not mod.moduleset_name.startswith('gnome-suites-core-deps-base'):
             #    continue
@@ -155,7 +155,7 @@ class cmd_extdeps(Command):
         print('</html>', file=output)
 
         if output != sys.stdout:
-            open(options.output, 'w').write(output.getvalue())
+            open_text(options.output, 'w').write(output.getvalue())
 
 
     def compute_rdeps(self, module):
@@ -165,7 +165,7 @@ class cmd_extdeps(Command):
                 continue
             if module.name in mod.dependencies:
                 rdeps.append(mod.name)
-        rdeps.sort(lambda x,y: cmp(x.lower(), y.lower()))
+        rdeps.sort(key=lambda x: x.lower())
         return rdeps
 
 register_command(cmd_extdeps)
diff --git a/jhbuild/commands/goalreport.py b/jhbuild/commands/goalreport.py
index a944fc49..dcc0210b 100644
--- a/jhbuild/commands/goalreport.py
+++ b/jhbuild/commands/goalreport.py
@@ -39,9 +39,9 @@ except ImportError:
 import jhbuild.moduleset
 from jhbuild.errors import CommandError
 from jhbuild.commands import Command, register_command
-from jhbuild.utils import httpcache, cmds, _
+from jhbuild.utils import httpcache, cmds, _, open_text
 from jhbuild.modtypes import MetaModule
-from jhbuild.utils.compat import BytesIO
+from jhbuild.utils.compat import TextIO
 
 try:
     t_bold = cmds.get_output(['tput', 'bold'])
@@ -368,7 +368,7 @@ class cmd_goalreport(Command):
 
     def run(self, config, options, args, help=None):
         if options.output:
-            output = BytesIO()
+            output = TextIO()
             global curses
             if curses and config.progress_bar:
                 try:
@@ -400,7 +400,7 @@ class cmd_goalreport(Command):
             cachedir = os.path.join(os.environ['HOME'], '.cache','jhbuild')
         if options.cache:
             try:
-                results = pickle.load(open(os.path.join(cachedir, options.cache)))
+                results = pickle.load(open(os.path.join(cachedir, options.cache), "rb"))
             except Exception:
                 pass
 
@@ -458,7 +458,7 @@ class cmd_goalreport(Command):
         if not os.path.exists(cachedir):
             os.makedirs(cachedir)
         if options.cache:
-            pickle.dump(results, open(os.path.join(cachedir, options.cache), 'w'))
+            pickle.dump(results, open(os.path.join(cachedir, options.cache), 'wb'))
 
         print(HTML_AT_TOP % {'title': self.title}, file=output)
         if self.page_intro:
@@ -569,7 +569,7 @@ class cmd_goalreport(Command):
         print('</html>', file=output)
 
         if output != sys.stdout:
-            open(options.output, 'w').write(output.getvalue())
+            open_text(options.output, 'w').write(output.getvalue())
 
         if output != sys.stdout and config.progress_bar:
             sys.stdout.write('\n')
@@ -758,7 +758,7 @@ class cmd_goalreport(Command):
         if not curses:
             return
         columns = curses.tigetnum('cols')
-        width = columns / 2
+        width = columns // 2
         num_hashes = int(round(progress * width))
         progress_bar = '[' + (num_hashes * '=') + ((width - num_hashes) * '-') + ']'
 
diff --git a/jhbuild/utils/systeminstall.py b/jhbuild/utils/systeminstall.py
index 1250d12b..3af2ce63 100644
--- a/jhbuild/utils/systeminstall.py
+++ b/jhbuild/utils/systeminstall.py
@@ -120,17 +120,17 @@ def systemdependencies_met(module_name, sysdeps, config):
                 shell_split = shlex.split
             try:
                 while True:
-                    arg = itr.next()
+                    arg = next(itr)
                     if arg.strip() in ['-I', '-isystem']:
                         # extract paths handling quotes and multiple paths
-                        paths += shell_split(itr.next())[0].split(os.pathsep)
+                        paths += shell_split(next(itr))[0].split(os.pathsep)
                     elif arg.startswith('-I'):
                         paths += shell_split(arg[2:])[0].split(os.pathsep)
             except StopIteration:
                 pass
             return paths
         try:
-            multiarch = subprocess.check_output(['gcc', '-print-multiarch']).strip()
+            multiarch = udecode(subprocess.check_output(['gcc', '-print-multiarch'])).strip()
         except (EnvironmentError, subprocess.CalledProcessError):
             multiarch = None
         # search /usr/include and its multiarch subdir (if any) by default
@@ -385,7 +385,7 @@ class PacmanSystemInstall(SystemInstall):
 
         for name, filename in uninstalled_filenames:
             try:
-                result = subprocess.check_output(['pkgfile', '--raw', filename])
+                result = udecode(subprocess.check_output(['pkgfile', '--raw', filename]))
                 if result:
                     package_names.add(result.split('\n')[0])
             except subprocess.CalledProcessError:
@@ -535,11 +535,11 @@ class AptSystemInstall(SystemInstall):
         # Get multiarch include directory, e.g. /usr/include/x86_64-linux-gnu
         multiarch = None
         try:
-            multiarch = subprocess.check_output(['gcc', '-print-multiarch']).strip()
+            multiarch = udecode(subprocess.check_output(['gcc', '-print-multiarch'])).strip()
         except (EnvironmentError, subprocess.CalledProcessError):
             # Really need GCC to continue. Yes, this is fragile.
             self._install_packages(['gcc'])
-            multiarch = subprocess.check_output(['gcc', '-print-multiarch']).strip()
+            multiarch = udecode(subprocess.check_output(['gcc', '-print-multiarch'])).strip()
 
         c_includes = get_uninstalled_c_includes(uninstalled)
         self._append_native_packages_or_warn_c_includes(c_includes, native_packages, multiarch)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]