From 5bff83c1da2d99da99fab70cb8b9ae13717a4323 Mon Sep 17 00:00:00 2001 From: Bradley Sepos Date: Mon, 25 Feb 2019 07:03:28 -0500 Subject: [PATCH] configure: gtk: make: scripts: Make scripts compatible with Python 3. --- configure | 2 +- gtk/src/makedeps.py | 4 ++-- make/configure.py | 42 ++++++++++++++++++++----------------- make/df-fetch.py | 4 ++-- make/df-verify.py | 2 +- scripts/create_resources.py | 13 ++++++------ 6 files changed, 36 insertions(+), 31 deletions(-) diff --git a/configure b/configure index 2500e3bb7..b9c11b2f4 100755 --- a/configure +++ b/configure @@ -14,7 +14,7 @@ inpath() } if ( inpath bash ); then - for p in python2.7 python2.6 python2.5 python2.4 python2 python + for p in python3 python2 do if ( inpath $p ); then exec $p `dirname $0`/make/configure.py "$@" diff --git a/gtk/src/makedeps.py b/gtk/src/makedeps.py index bd3da2efc..2cbd1bcb1 100644 --- a/gtk/src/makedeps.py +++ b/gtk/src/makedeps.py @@ -62,13 +62,13 @@ def main(): try: depsfile = open("widget.deps", "w") - except Exception, err: + except Exception as err: print >> sys.stderr, ( "Error: %s" % str(err) ) sys.exit(1) try: revfile = open("widget_reverse.deps", "w") - except Exception, err: + except Exception as err: print >> sys.stderr, ( "Error: %s" % str(err)) sys.exit(1) diff --git a/make/configure.py b/make/configure.py index cb8384647..64e12556c 100644 --- a/make/configure.py +++ b/make/configure.py @@ -1,8 +1,6 @@ ############################################################################### ## -## This script is coded for minimum version of Python 2.7 . -## -## Python3 is incompatible. +## This script is coded for Python 2.7 through Python 3.x ## ## Authors: konablend ## @@ -142,7 +140,7 @@ class Configure( object ): try: return open( *args ) - except Exception, x: + except Exception as x: self.errln( 'open failure: %s', x ) def record_log( self ): @@ -430,7 +428,7 @@ class HostTupleProbe( ShellProbe, list ): super( HostTupleProbe, self ).__init__( 'host tuple', '%s/config.guess' % (cfg.dir), abort=True, head=True ) def _parseSession( self ): - self.spec = self.session[0] if self.session else '' + self.spec = self.session[0].decode('utf-8') if self.session else '' ## grok GNU host tuples m = re.match( HostTupleProbe.GNU_TUPLE_RE, self.spec ) @@ -670,7 +668,7 @@ class SelectMode( dict ): self.mode = value def toString( self, nodefault=False ): - keys = self.keys() + keys = list(self.copy().keys()) keys.sort() if len(self) == 1: value = self.mode @@ -720,6 +718,8 @@ class RepoProbe( ShellProbe ): def _parseSession( self ): for line in self.session: + line = line.decode('utf-8') + ## grok fields m = re.match( '([^\=]+)\=(.*)', line ) if not m: @@ -900,8 +900,12 @@ class ToolProbe( Action ): self.names = [] self.kwargs = kwargs for name in names: - if name: - self.names.append( str(name) ) + try: + name = str(name) + except: + name = None + if name is not None: + self.names.append( name ) self.name = self.names[0] self.pretext = self.name self.pathname = self.names[0] @@ -984,7 +988,7 @@ class VersionProbe( Action ): self._parse() self.fail = False self.msg_end = self.svers - except Exception, x: + except Exception as x: self.svers = '0.0.0' self.ivers = [0,0,0] self.msg_end = str(x) @@ -994,7 +998,7 @@ class VersionProbe( Action ): super( VersionProbe, self )._dumpSession( printf ) def _parse( self ): - mo = re.match( self.rexpr, self.session[0], re.IGNORECASE ) + mo = re.match( self.rexpr, self.session[0].decode('utf-8'), re.IGNORECASE ) md = mo.groupdict() self.svers = md['svers'] if 'i0' in md and md['i0']: @@ -1163,7 +1167,7 @@ class ConfigDocument: elif type == 'm4': fname = os.path.join( 'project', project.name_lower + '.m4' ) else: - raise ValueError, 'unknown file type: ' + type + raise ValueError('unknown file type: ' + type) ftmp = cfg.mktmpname(fname) try: @@ -1175,16 +1179,16 @@ class ConfigDocument: out_file.close() except: pass - except Exception, x: + except Exception as x: try: os.remove( ftmp ) - except Exception, x: + except Exception as x: pass cfg.errln( 'failed writing to %s\n%s', ftmp, x ) try: os.rename( ftmp, fname ) - except Exception, x: + except Exception as x: cfg.errln( 'failed writing to %s\n%s', fname, x ) ############################################################################### @@ -1210,16 +1214,16 @@ def encodeDistfileConfig(): out_file.close() except: pass - except Exception, x: + except Exception as x: try: os.remove( ftmp ) - except Exception, x: + except Exception as x: pass cfg.errln( 'failed writing to %s\n%s', ftmp, x ) try: os.rename( ftmp, fname ) - except Exception, x: + except Exception as x: cfg.errln( 'failed writing to %s\n%s', fname, x ) ############################################################################### @@ -1419,7 +1423,7 @@ class Launcher: ## launch/pipe try: pipe = subprocess.Popen( cmd, shell=True, bufsize=1, stdout=subprocess.PIPE, stderr=subprocess.STDOUT ) - except Exception, x: + except Exception as x: cfg.errln( 'launch failure: %s', x ) for line in pipe.stdout: self.echof( '%s', line ) @@ -2009,7 +2013,7 @@ int main() else: stdout.write( 'You may now cd into %s and run make (%s).\n' % (cfg.build_dir,Tools.gmake.pathname) ) -except AbortError, x: +except AbortError as x: stderr.write( 'ERROR: %s\n' % (x) ) try: cfg.record_log() diff --git a/make/df-fetch.py b/make/df-fetch.py index 633ffdf07..cfea5256c 100644 --- a/make/df-fetch.py +++ b/make/df-fetch.py @@ -121,7 +121,7 @@ class Tool(hb_distfile.Tool): url.download(error) if not self.options.exhaust_url: break - except Exception, x: + except Exception as x: ## propagate exception if no remaining urls if not urls: raise @@ -131,7 +131,7 @@ class Tool(hb_distfile.Tool): error = hb_distfile.ToolError(self.name) try: self._run(error) - except Exception, x: + except Exception as x: self.debug_exception() self.errln('%s failure; %s' % (error.op,x), exit=1) diff --git a/make/df-verify.py b/make/df-verify.py index 8af3bee9c..eb29f4bc9 100644 --- a/make/df-verify.py +++ b/make/df-verify.py @@ -90,7 +90,7 @@ class Tool(hb_distfile.Tool): error = hb_distfile.ToolError(self.name) try: self._run(error) - except Exception, x: + except Exception as x: self.debug_exception() self.errln('%s failure; %s' % (error.op,x), exit=1) diff --git a/scripts/create_resources.py b/scripts/create_resources.py index 54d1310b6..43cf298d2 100755 --- a/scripts/create_resources.py +++ b/scripts/create_resources.py @@ -41,7 +41,7 @@ def start_element_handler(tag, attr): try: with open(fname) as fp: val = json.load(fp) - except Exception, err: + except Exception as err: print >> sys.stderr, ("Error: %s" % str(err)) elif fname is None: print >> sys.stderr, ("Error: No such json file %s" % fbase) @@ -63,7 +63,7 @@ def start_element_handler(tag, attr): try: with open(fname) as fp: val = fp.read() - except Exception, err: + except Exception as err: print >> sys.stderr, ("Error: %s" % str(err)) sys.exit(1) elif fname is None: @@ -74,9 +74,9 @@ def start_element_handler(tag, attr): val = attr["value"] if val is not None: - if isinstance(current, types.DictType): + if isinstance(current, dict): current[key] = val - elif isinstance(current, types.TupleType): + elif isinstance(current, tuple): current.append(val) @@ -91,8 +91,9 @@ def resource_parse_file(infile): parser.CharacterDataHandler = cdata_handler try: - parser.ParseFile(infile) - except ExpatError, err: + with open(infile.name, 'rb') as file: + parser.ParseFile(file) + except ExpatError as err: print >> sys.stderr, ("Error: %s" % str(err)) return None -- 2.40.0