sb: Update code base to support Python3 and Python2.

Fix Windows support to allow MSYS2 Python to be used.

Updates #2619.
This commit is contained in:
Chris Johns 2016-03-07 11:56:02 +11:00
parent b537e55364
commit 3a972f6102
29 changed files with 412 additions and 314 deletions

View File

@ -1,7 +1,7 @@
#! /usr/bin/env python #! /usr/bin/env python
# #
# RTEMS Tools Project (http://www.rtems.org/) # RTEMS Tools Project (http://www.rtems.org/)
# Copyright 2014 Chris Johns (chrisj@rtems.org) # Copyright 2014-2016 Chris Johns (chrisj@rtems.org)
# All rights reserved. # All rights reserved.
# #
# This file is part of the RTEMS Tools package in 'rtems-tools'. # This file is part of the RTEMS Tools package in 'rtems-tools'.
@ -29,6 +29,8 @@
# POSSIBILITY OF SUCH DAMAGE. # POSSIBILITY OF SUCH DAMAGE.
# #
from __future__ import print_function
import os import os
import sys import sys
@ -42,13 +44,13 @@ except:
try: try:
import argparse import argparse
except: except:
print >> sys.stderr, "Incorrect Source Builder installation" print("Incorrect Source Builder installation", file = sys.stderr)
sys.exit(1) sys.exit(1)
try: try:
import pkgconfig import pkgconfig
except ImportError: except ImportError:
print >> sys.stderr, "Incorrect Source Builder installation" print("Incorrect Source Builder installation", file = sys.stderr)
sys.exit(1) sys.exit(1)
# #
@ -81,12 +83,12 @@ def log(s, lf = True):
out = sys.stdout out = sys.stdout
if lf: if lf:
if out != sys.stdout and trace_stdout: if out != sys.stdout and trace_stdout:
print s print(s)
print >> out, s print(s, file = out)
else: else:
if out != sys.stdout and trace_stdout: if out != sys.stdout and trace_stdout:
print s, print(s, end = '', flush = True)
print >> out, s, print(out, s, end = '', flush = True)
def run(argv): def run(argv):
@ -191,13 +193,13 @@ def run(argv):
if ec == 0: if ec == 0:
if args.cflags: if args.cflags:
if len(flags['cflags']): if len(flags['cflags']):
print flags['cflags'] print(flags['cflags'])
log('cflags: %s' % (flags['cflags'])) log('cflags: %s' % (flags['cflags']))
else: else:
log('cflags: empty') log('cflags: empty')
if args.libs: if args.libs:
if len(flags['libs']): if len(flags['libs']):
print flags['libs'] print(flags['libs'])
log('libs: %s' % (flags['libs'])) log('libs: %s' % (flags['libs']))
else: else:
log('libs: empty') log('libs: empty')
@ -215,9 +217,9 @@ try:
ec = run(sys.argv) ec = run(sys.argv)
log('ec = %d' % (ec)) log('ec = %d' % (ec))
except ImportError: except ImportError:
print >> sys.stderr, "incorrect package config installation" print("incorrect package config installation", file = sys.stderr)
sys.exit(1) sys.exit(1)
except pkgconfig.error, e: except pkgconfig.error, e:
print >> sys.stderr, 'error: %s' % (e) print('error: %s' % (e), file = sys.stderr)
sys.exit(1) sys.exit(1)
sys.exit(ec) sys.exit(ec)

View File

@ -18,6 +18,8 @@
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
from __future__ import print_function
import sys, os import sys, os
base = os.path.dirname(sys.argv[0]) base = os.path.dirname(sys.argv[0])
sys.path.insert(0, base + '/sb') sys.path.insert(0, base + '/sb')
@ -25,5 +27,5 @@ try:
import bootstrap import bootstrap
bootstrap.run(sys.argv) bootstrap.run(sys.argv)
except ImportError: except ImportError:
print >> sys.stderr, "Incorrect Source Builder installation" print("Incorrect Source Builder installation", file = sys.stderr)
sys.exit(1) sys.exit(1)

View File

@ -18,6 +18,8 @@
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
from __future__ import print_function
import sys, os import sys, os
base = os.path.dirname(sys.argv[0]) base = os.path.dirname(sys.argv[0])
sys.path.insert(0, base + '/sb') sys.path.insert(0, base + '/sb')
@ -25,5 +27,5 @@ try:
import build import build
build.run(sys.argv) build.run(sys.argv)
except ImportError: except ImportError:
print >> sys.stderr, "Incorrect Source Builder installation" print("Incorrect Source Builder installation", file = sys.stderr)
sys.exit(1) sys.exit(1)

View File

@ -18,6 +18,8 @@
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
from __future__ import print_function
import sys, os import sys, os
base = os.path.dirname(sys.argv[0]) base = os.path.dirname(sys.argv[0])
sys.path.insert(0, base + '/sb') sys.path.insert(0, base + '/sb')
@ -25,5 +27,5 @@ try:
import check import check
check.run() check.run()
except ImportError: except ImportError:
print >> sys.stderr, "Incorrect Set Bulder installation" print("Incorrect Source Builder installation", file = sys.stderr)
sys.exit(1) sys.exit(1)

View File

@ -18,6 +18,8 @@
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
from __future__ import print_function
import sys, os import sys, os
base = os.path.dirname(sys.argv[0]) base = os.path.dirname(sys.argv[0])
sys.path.insert(0, base + '/sb') sys.path.insert(0, base + '/sb')
@ -25,5 +27,5 @@ try:
import options import options
options.run(sys.argv) options.run(sys.argv)
except ImportError: except ImportError:
print >> sys.stderr, "Incorrect Defaults installation" print("Incorrect Source Builder installation", file = sys.stderr)
sys.exit(1) sys.exit(1)

View File

@ -18,6 +18,8 @@
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
from __future__ import print_function
import sys, os import sys, os
base = os.path.dirname(sys.argv[0]) base = os.path.dirname(sys.argv[0])
sys.path.insert(0, base + '/sb') sys.path.insert(0, base + '/sb')
@ -25,5 +27,5 @@ try:
import reports import reports
reports.run(sys.argv) reports.run(sys.argv)
except ImportError: except ImportError:
print >> sys.stderr, "Incorrect Defaults installation" print("Incorrect Source Builder installation", file = sys.stderr)
sys.exit(1) sys.exit(1)

View File

@ -18,6 +18,8 @@
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
from __future__ import print_function
import sys, os import sys, os
base = os.path.dirname(sys.argv[0]) base = os.path.dirname(sys.argv[0])
sys.path.insert(0, base + '/sb') sys.path.insert(0, base + '/sb')
@ -25,5 +27,5 @@ try:
import rtemsconfig import rtemsconfig
rtemsconfig.run(sys.argv) rtemsconfig.run(sys.argv)
except ImportError: except ImportError:
print >> sys.stderr, "Incorrect Set Bulder installation" print("Incorrect Source Builder installation", file = sys.stderr)
sys.exit(1) sys.exit(1)

View File

@ -18,12 +18,17 @@
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
from __future__ import print_function
import sys, os import sys, os
base = os.path.dirname(sys.argv[0]) base = os.path.dirname(sys.argv[0])
sys.path.insert(0, base + '/sb') sys.path.insert(0, base + '/sb')
import setbuilder
try: try:
import setbuilder import setbuilder
setbuilder.run() setbuilder.run()
except ImportError: except ImportError:
print >> sys.stderr, "Incorrect Set Bulder installation" print("Incorrect Source Builder installation", file = sys.stderr)
sys.exit(1) sys.exit(1)

View File

@ -18,6 +18,8 @@
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
# #
from __future__ import print_function
import datetime import datetime
import operator import operator
import os import os
@ -46,7 +48,7 @@ def _grep(file, pattern):
f = open(path.host(file), 'r') f = open(path.host(file), 'r')
matches = [rege.match(l) != None for l in f.readlines()] matches = [rege.match(l) != None for l in f.readlines()]
f.close() f.close()
except IOError, err: except IOError as err:
raise error.general('reading: %s' % (file)) raise error.general('reading: %s' % (file))
return True in matches return True in matches
@ -91,10 +93,10 @@ class command:
else: else:
cmd = self.cmd cmd = self.cmd
self.output = subprocess.check_output(cmd, cwd = path.host(self.cwd)) self.output = subprocess.check_output(cmd, cwd = path.host(self.cwd))
except subprocess.CalledProcessError, cpe: except subprocess.CalledProcessError as cpe:
self.exit_code = cpe.returncode self.exit_code = cpe.returncode
self.output = cpe.output self.output = cpe.output
except OSError, ose: except OSError as ose:
raise error.general('bootstrap failed: %s in %s: %s' % \ raise error.general('bootstrap failed: %s in %s: %s' % \
(' '.join(cmd), path.host(self.cwd), (str(ose)))) (' '.join(cmd), path.host(self.cwd), (str(ose))))
except KeyboardInterrupt: except KeyboardInterrupt:
@ -114,7 +116,7 @@ class command:
def reraise(self): def reraise(self):
if self.result is not None: if self.result is not None:
raise self.result[0], self.result[1], self.result[2] raise self.result[0](self.result[1]).with_traceback(self.result[2])
class autoreconf: class autoreconf:
@ -145,7 +147,7 @@ class autoreconf:
b.write(' esac' + os.linesep) b.write(' esac' + os.linesep)
b.write('])' + os.linesep) b.write('])' + os.linesep)
b.close() b.close()
except IOError, err: except IOError as err:
raise error.general('writing: %s' % (acinclude)) raise error.general('writing: %s' % (acinclude))
def is_alive(self): def is_alive(self):
@ -164,7 +166,7 @@ class autoreconf:
t = open(path.host(stamp_h), 'w') t = open(path.host(stamp_h), 'w')
t.write('timestamp') t.write('timestamp')
t.close() t.close()
except IOError, err: except IOError as err:
raise error.general('writing: %s' % (stamp_h)) raise error.general('writing: %s' % (stamp_h))
def generate(topdir, jobs): def generate(topdir, jobs):
@ -212,7 +214,7 @@ class ampolish3:
for l in self.command.output: for l in self.command.output:
p.write(l) p.write(l)
p.close() p.close()
except IOError, err: except IOError as err:
raise error.general('writing: %s' % (self.preinstall)) raise error.general('writing: %s' % (self.preinstall))
def preinstall(topdir, jobs): def preinstall(topdir, jobs):
@ -275,15 +277,15 @@ def run(args):
preinstall(topdir, opts.jobs(opts.defaults['_ncpus'])) preinstall(topdir, opts.jobs(opts.defaults['_ncpus']))
else: else:
generate(topdir, opts.jobs(opts.defaults['_ncpus'])) generate(topdir, opts.jobs(opts.defaults['_ncpus']))
except error.general, gerr: except error.general as gerr:
print gerr print(gerr)
print >> sys.stderr, 'Bootstrap FAILED' print('Bootstrap FAILED', file = sys.stderr)
sys.exit(1) sys.exit(1)
except error.internal, ierr: except error.internal as ierr:
print ierr print(ierr)
print >> sys.stderr, 'Bootstrap FAILED' print('Bootstrap FAILED', file = sys.stderr)
sys.exit(1) sys.exit(1)
except error.exit, eerr: except error.exit as eerr:
pass pass
except KeyboardInterrupt: except KeyboardInterrupt:
log.notice('abort: user terminated') log.notice('abort: user terminated')

View File

@ -22,6 +22,8 @@
# installed not to be package unless you run a packager around this. # installed not to be package unless you run a packager around this.
# #
from __future__ import print_function
import copy import copy
import getopt import getopt
import glob import glob
@ -29,8 +31,6 @@ import os
import shutil import shutil
import stat import stat
import sys import sys
import urllib2
import urlparse
try: try:
import check import check
@ -45,10 +45,10 @@ try:
import sources import sources
import version import version
except KeyboardInterrupt: except KeyboardInterrupt:
print 'abort: user terminated' print('abort: user terminated')
sys.exit(1) sys.exit(1)
except: except:
print 'error: unknown application load error' print('error: unknown application load error')
sys.exit(1) sys.exit(1)
class script: class script:
@ -81,7 +81,7 @@ class script:
os.chmod(path.host(name), stat.S_IRWXU | \ os.chmod(path.host(name), stat.S_IRWXU | \
stat.S_IRGRP | stat.S_IXGRP | \ stat.S_IRGRP | stat.S_IXGRP | \
stat.S_IROTH | stat.S_IXOTH) stat.S_IROTH | stat.S_IXOTH)
except IOError, err: except IOError as err:
raise error.general('creating script: ' + name) raise error.general('creating script: ' + name)
except: except:
if s is not None: if s is not None:
@ -128,11 +128,11 @@ class build:
self.config = config.file(name, opts, self.macros) self.config = config.file(name, opts, self.macros)
self.script = script() self.script = script()
self.macros['buildname'] = self._name_(self.macros['name']) self.macros['buildname'] = self._name_(self.macros['name'])
except error.general, gerr: except error.general as gerr:
log.notice(str(gerr)) log.notice(str(gerr))
log.stderr('Build FAILED') log.stderr('Build FAILED')
raise raise
except error.internal, ierr: except error.internal as ierr:
log.notice(str(ierr)) log.notice(str(ierr))
log.stderr('Internal Build FAILED') log.stderr('Internal Build FAILED')
raise raise
@ -232,7 +232,7 @@ class build:
args = args[1:] args = args[1:]
try: try:
opts, args = getopt.getopt(args[1:], 'qDcn:ba') opts, args = getopt.getopt(args[1:], 'qDcn:ba')
except getopt.GetoptError, ge: except getopt.GetoptError as ge:
raise error.general('source setup error: %s' % str(ge)) raise error.general('source setup error: %s' % str(ge))
quiet = False quiet = False
unpack_before_chdir = True unpack_before_chdir = True
@ -473,12 +473,12 @@ class build:
self.script.write(sn) self.script.write(sn)
log.notice('building: %s%s' % (cxc_label, name)) log.notice('building: %s%s' % (cxc_label, name))
self.run(sn) self.run(sn)
except error.general, gerr: except error.general as gerr:
log.notice(str(gerr)) log.notice(str(gerr))
log.stderr('Build FAILED') log.stderr('Build FAILED')
self._generate_report_('Build: %s' % (gerr)) self._generate_report_('Build: %s' % (gerr))
raise raise
except error.internal, ierr: except error.internal as ierr:
log.notice(str(ierr)) log.notice(str(ierr))
log.stderr('Internal Build FAILED') log.stderr('Internal Build FAILED')
self._generate_report_('Build: %s' % (ierr)) self._generate_report_('Build: %s' % (ierr))
@ -546,22 +546,22 @@ def run(args):
if opts.get_arg('--list-configs'): if opts.get_arg('--list-configs'):
configs = get_configs(opts) configs = get_configs(opts)
for p in configs['paths']: for p in configs['paths']:
print 'Examining: %s' % (os.path.relpath(p)) print('Examining: %s' % (os.path.relpath(p)))
for c in configs['files']: for c in configs['files']:
if c.endswith('.cfg'): if c.endswith('.cfg'):
print ' %s' % (c) print(' %s' % (c))
else: else:
for config_file in opts.config_files(): for config_file in opts.config_files():
b = build(config_file, True, opts) b = build(config_file, True, opts)
b.make() b.make()
b = None b = None
except error.general, gerr: except error.general as gerr:
log.stderr('Build FAILED') log.stderr('Build FAILED')
ec = 1 ec = 1
except error.internal, ierr: except error.internal as ierr:
log.stderr('Internal Build FAILED') log.stderr('Internal Build FAILED')
ec = 1 ec = 1
except error.exit, eerr: except error.exit as eerr:
pass pass
except KeyboardInterrupt: except KeyboardInterrupt:
log.notice('abort: user terminated') log.notice('abort: user terminated')

View File

@ -1,6 +1,6 @@
# #
# RTEMS Tools Project (http://www.rtems.org/) # RTEMS Tools Project (http://www.rtems.org/)
# Copyright 2010-2012 Chris Johns (chrisj@rtems.org) # Copyright 2010-2016 Chris Johns (chrisj@rtems.org)
# All rights reserved. # All rights reserved.
# #
# This file is part of the RTEMS Tools package in 'rtems-tools'. # This file is part of the RTEMS Tools package in 'rtems-tools'.
@ -21,6 +21,8 @@
# Check the defaults for a specific host. # Check the defaults for a specific host.
# #
from __future__ import print_function
import os import os
import error import error
@ -130,7 +132,7 @@ def host_setup(opts):
sane = True sane = True
for d in opts.defaults.keys(): for d in list(opts.defaults.keys()):
try: try:
(test, constraint, value) = opts.defaults.get(d) (test, constraint, value) = opts.defaults.get(d)
except: except:
@ -164,16 +166,16 @@ def run():
_opts = options.load(args = sys.argv) _opts = options.load(args = sys.argv)
log.notice('RTEMS Source Builder - Check, %s' % (version.str())) log.notice('RTEMS Source Builder - Check, %s' % (version.str()))
if host_setup(_opts): if host_setup(_opts):
print 'Environment is ok' print('Environment is ok')
else: else:
print 'Environment is not correctly set up' print('Environment is not correctly set up')
except error.general, gerr: except error.general as gerr:
print gerr print(gerr)
sys.exit(1) sys.exit(1)
except error.internal, ierr: except error.internal as ierr:
print ierr print(ierr)
sys.exit(1) sys.exit(1)
except error.exit, eerr: except error.exit as eerr:
pass pass
except KeyboardInterrupt: except KeyboardInterrupt:
log.notice('abort: user terminated') log.notice('abort: user terminated')

View File

@ -1,6 +1,6 @@
# #
# RTEMS Tools Project (http://www.rtems.org/) # RTEMS Tools Project (http://www.rtems.org/)
# Copyright 2010-2013 Chris Johns (chrisj@rtems.org) # Copyright 2010-2016 Chris Johns (chrisj@rtems.org)
# All rights reserved. # All rights reserved.
# #
# This file is part of the RTEMS Tools package in 'rtems-tools'. # This file is part of the RTEMS Tools package in 'rtems-tools'.
@ -25,7 +25,10 @@
# other software modules. # other software modules.
# #
from __future__ import print_function
import copy import copy
from functools import reduce
import os import os
import re import re
import sys import sys
@ -39,10 +42,10 @@ try:
import pkgconfig import pkgconfig
import sources import sources
except KeyboardInterrupt: except KeyboardInterrupt:
print 'user terminated' print('user terminated', file = sys.stderr)
sys.exit(1) sys.exit(1)
except: except:
print 'error: unknown application load error' print('error: unknown application load error', file = sys.stderr)
sys.exit(1) sys.exit(1)
def _check_bool(value): def _check_bool(value):
@ -75,7 +78,7 @@ class package:
def _dictlist(dl): def _dictlist(dl):
s = '' s = ''
dll = dl.keys() dll = list(dl.keys())
dll.sort() dll.sort()
for d in dll: for d in dll:
if d: if d:
@ -250,7 +253,7 @@ class file:
def _dict(dd): def _dict(dd):
s = '' s = ''
ddl = dd.keys() ddl = list(dd.keys())
ddl.sort() ddl.sort()
for d in ddl: for d in ddl:
s += ' ' + d + ': ' + dd[d] + '\n' s += ' ' + d + ': ' + dd[d] + '\n'
@ -339,14 +342,14 @@ class file:
outter level. Nested levels will need to split with futher calls.''' outter level. Nested levels will need to split with futher calls.'''
trace_me = False trace_me = False
if trace_me: if trace_me:
print '------------------------------------------------------' print('------------------------------------------------------')
macros = [] macros = []
nesting = [] nesting = []
has_braces = False has_braces = False
c = 0 c = 0
while c < len(s): while c < len(s):
if trace_me: if trace_me:
print 'ms:', c, '"' + s[c:] + '"', has_braces, len(nesting), nesting print('ms:', c, '"' + s[c:] + '"', has_braces, len(nesting), nesting)
# #
# We need to watch for shell type variables or the form '${var}' because # We need to watch for shell type variables or the form '${var}' because
# they can upset the brace matching. # they can upset the brace matching.
@ -394,9 +397,9 @@ class file:
macros.append(s[macro_start:c + 1].strip()) macros.append(s[macro_start:c + 1].strip())
c += 1 c += 1
if trace_me: if trace_me:
print 'ms:', macros print('ms:', macros)
if trace_me: if trace_me:
print '-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=' print('-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=')
return macros return macros
def _shell(self, line): def _shell(self, line):
@ -435,7 +438,7 @@ class file:
op = test[1] op = test[1]
ver = self.macros.expand(test[2]) ver = self.macros.expand(test[2])
ok = pkg.check(op, ver) ok = pkg.check(op, ver)
except pkgconfig.error, pe: except pkgconfig.error as pe:
self._error('pkgconfig: check: %s' % (pe)) self._error('pkgconfig: check: %s' % (pe))
except: except:
raise error.internal('pkgconfig failure') raise error.internal('pkgconfig failure')
@ -459,7 +462,7 @@ class file:
fflags += [f] fflags += [f]
pkg_flags = ' '.join(fflags) pkg_flags = ' '.join(fflags)
log.trace('pkgconfig: %s: %s' % (flags, pkg_flags)) log.trace('pkgconfig: %s: %s' % (flags, pkg_flags))
except pkgconfig.error, pe: except pkgconfig.error as pe:
self._error('pkgconfig: %s: %s' % (flags, pe)) self._error('pkgconfig: %s: %s' % (flags, pe))
except: except:
raise error.internal('pkgconfig failure') raise error.internal('pkgconfig failure')
@ -1127,7 +1130,7 @@ class file:
try: try:
log.trace('config: %s: _open: %s' % (self.name, path.host(configname))) log.trace('config: %s: _open: %s' % (self.name, path.host(configname)))
config = open(path.host(configname), 'r') config = open(path.host(configname), 'r')
except IOError, err: except IOError as err:
raise error.general('error opening config file: %s' % (path.host(configname))) raise error.general('error opening config file: %s' % (path.host(configname)))
self.configpath += [configname] self.configpath += [configname]
@ -1171,7 +1174,7 @@ class file:
self.load_depth -= 1 self.load_depth -= 1
def defined(self, name): def defined(self, name):
return self.macros.has_key(name) return name in self.macros
def define(self, name): def define(self, name):
if name in self.macros: if name in self.macros:
@ -1229,14 +1232,14 @@ def run():
opts = options.load(sys.argv, defaults = 'defaults.mc') opts = options.load(sys.argv, defaults = 'defaults.mc')
log.trace('config: count %d' % (len(opts.config_files()))) log.trace('config: count %d' % (len(opts.config_files())))
for config_file in opts.config_files(): for config_file in opts.config_files():
s = file(config_file, opts) s = open(config_file, opts)
print s print(s)
del s del s
except error.general, gerr: except error.general as gerr:
print gerr print(gerr)
sys.exit(1) sys.exit(1)
except error.internal, ierr: except error.internal as ierr:
print ierr print(ierr)
sys.exit(1) sys.exit(1)
except KeyboardInterrupt: except KeyboardInterrupt:
log.notice('abort: user terminated') log.notice('abort: user terminated')

View File

@ -1,6 +1,6 @@
# #
# RTEMS Tools Project (http://www.rtems.org/) # RTEMS Tools Project (http://www.rtems.org/)
# Copyright 2010-2013 Chris Johns (chrisj@rtems.org) # Copyright 2010-2016 Chris Johns (chrisj@rtems.org)
# All rights reserved. # All rights reserved.
# #
# This file is part of the RTEMS Tools package in 'rtems-tools'. # This file is part of the RTEMS Tools package in 'rtems-tools'.
@ -21,6 +21,8 @@
# Provide some basic access to the cvs command. # Provide some basic access to the cvs command.
# #
from __future__ import print_function
import os import os
import error import error
@ -151,8 +153,8 @@ if __name__ == '__main__':
if not path.exists(ldir): if not path.exists(ldir):
path.mkdir(ldir) path.mkdir(ldir)
c.checkout(':pserver:anoncvs@sourceware.org:/cvs/src', module = 'newlib') c.checkout(':pserver:anoncvs@sourceware.org:/cvs/src', module = 'newlib')
print c.cvs_version() print(c.cvs_version())
print c.valid() print(c.valid())
print c.status() print(c.status())
c.reset() c.reset()
print c.clean() print(c.clean())

View File

@ -22,12 +22,20 @@
# installed not to be package unless you run a packager around this. # installed not to be package unless you run a packager around this.
# #
from __future__ import print_function
import hashlib import hashlib
import os import os
import stat import stat
import sys import sys
import urllib2 try:
import urlparse import urllib.request as urllib_request
import urllib.parse as urllib_parse
import urllib.error as urllib_error
except ImportError:
import urllib as urllib_request
import urllib as urllib_parse
import urllib as urllib_error
import cvs import cvs
import error import error
@ -49,11 +57,11 @@ def _do_download(opts):
def _humanize_bytes(bytes, precision = 1): def _humanize_bytes(bytes, precision = 1):
abbrevs = ( abbrevs = (
(1 << 50L, 'PB'), (1 << 50, 'PB'),
(1 << 40L, 'TB'), (1 << 40, 'TB'),
(1 << 30L, 'GB'), (1 << 30, 'GB'),
(1 << 20L, 'MB'), (1 << 20, 'MB'),
(1 << 10L, 'kB'), (1 << 10, 'kB'),
(1, ' bytes') (1, ' bytes')
) )
if bytes == 1: if bytes == 1:
@ -82,7 +90,7 @@ def _hash_check(file_, absfile, macros, remove = True):
hasher = hashlib.new(hash[0]) hasher = hashlib.new(hash[0])
_in = open(path.host(absfile), 'rb') _in = open(path.host(absfile), 'rb')
hasher.update(_in.read()) hasher.update(_in.read())
except IOError, err: except IOError as err:
log.notice('hash: %s: read error: %s' % (file_, str(err))) log.notice('hash: %s: read error: %s' % (file_, str(err)))
failed = True failed = True
except: except:
@ -103,7 +111,7 @@ def _hash_check(file_, absfile, macros, remove = True):
if path.exists(absfile): if path.exists(absfile):
try: try:
os.remove(path.host(absfile)) os.remove(path.host(absfile))
except IOError, err: except IOError as err:
raise error.general('hash: %s: remove: %s' % (absfile, str(err))) raise error.general('hash: %s: remove: %s' % (absfile, str(err)))
except: except:
raise error.general('hash: %s: remove error' % (file_)) raise error.general('hash: %s: remove error' % (file_))
@ -317,7 +325,7 @@ def _http_downloader(url, local, config, opts):
# Hack for GitHub. # Hack for GitHub.
# #
if url.startswith('https://api.github.com'): if url.startswith('https://api.github.com'):
url = urlparse.urljoin(url, config.expand('tarball/%{version}')) url = urllib_parse.urljoin(url, config.expand('tarball/%{version}'))
dst = os.path.relpath(path.host(local)) dst = os.path.relpath(path.host(local))
log.notice('download: %s -> %s' % (url, dst)) log.notice('download: %s -> %s' % (url, dst))
failed = False failed = False
@ -335,14 +343,15 @@ def _http_downloader(url, local, config, opts):
try: try:
_in = None _in = None
_ssl_context = None _ssl_context = None
_urllib_url = url
try: try:
import ssl import ssl
_ssl_context = ssl._create_unverified_context() _ssl_context = ssl._create_unverified_context()
_in = urllib2.urlopen(url, context = _ssl_context) _in = urllib_request.urlopen(_urllib_url, context = _ssl_context)
except: except:
_ssl_context = None _ssl_context = None
if _ssl_context is None: if _ssl_context is None:
_in = urllib2.urlopen(url) _in = urllib_request.urlopen(_urllib_url)
if url != _in.geturl(): if url != _in.geturl():
log.notice(' redirect: %s' % (_in.geturl())) log.notice(' redirect: %s' % (_in.geturl()))
_out = open(path.host(local), 'wb') _out = open(path.host(local), 'wb')
@ -372,12 +381,12 @@ def _http_downloader(url, local, config, opts):
except: except:
log.stdout_raw('\n') log.stdout_raw('\n')
raise raise
except IOError, err: except IOError as err:
log.notice('download: %s: error: %s' % (url, str(err))) log.notice('download: %s: error: %s' % (url, str(err)))
if path.exists(local): if path.exists(local):
os.remove(path.host(local)) os.remove(path.host(local))
failed = True failed = True
except ValueError, err: except ValueError as err:
log.notice('download: %s: error: %s' % (url, str(err))) log.notice('download: %s: error: %s' % (url, str(err)))
if path.exists(local): if path.exists(local):
os.remove(path.host(local)) os.remove(path.host(local))
@ -570,7 +579,7 @@ def get_file(url, local, opts, config):
# #
# Split up the URL we are being asked to download. # Split up the URL we are being asked to download.
# #
url_path = urlparse.urlsplit(url)[2] url_path = urllib_parse.urlsplit(url)[2]
slash = url_path.rfind('/') slash = url_path.rfind('/')
if slash < 0: if slash < 0:
url_file = url_path url_file = url_path
@ -580,7 +589,7 @@ def get_file(url, local, opts, config):
for base in url_bases: for base in url_bases:
if base[-1:] != '/': if base[-1:] != '/':
base += '/' base += '/'
next_url = urlparse.urljoin(base, url_file) next_url = urllib_parse.urljoin(base, url_file)
log.trace('url: %s' %(next_url)) log.trace('url: %s' %(next_url))
urls.append(next_url) urls.append(next_url)
urls += url.split() urls += url.split()

View File

@ -17,6 +17,8 @@
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
from __future__ import print_function
# #
# Various errors we can raise. # Various errors we can raise.
# #
@ -46,9 +48,9 @@ class exit(error):
if __name__ == '__main__': if __name__ == '__main__':
try: try:
raise general('a general error') raise general('a general error')
except general, gerr: except general as gerr:
print 'caught:', gerr print('caught:', gerr)
try: try:
raise internal('an internal error') raise internal('an internal error')
except internal, ierr: except internal as ierr:
print 'caught:', ierr print('caught:', ierr)

View File

@ -1,6 +1,6 @@
# #
# RTEMS Tools Project (http://www.rtems.org/) # RTEMS Tools Project (http://www.rtems.org/)
# Copyright 2010-2012 Chris Johns (chrisj@rtems.org) # Copyright 2010-2016 Chris Johns (chrisj@rtems.org)
# All rights reserved. # All rights reserved.
# #
# This file is part of the RTEMS Tools package in 'rtems-tools'. # This file is part of the RTEMS Tools package in 'rtems-tools'.
@ -23,6 +23,9 @@
# Note, the subprocess module is only in Python 2.4 or higher. # Note, the subprocess module is only in Python 2.4 or higher.
# #
from __future__ import print_function
import functools
import os import os
import re import re
import sys import sys
@ -81,7 +84,7 @@ def arg_subst(command, substs):
def arg_subst_str(command, subst): def arg_subst_str(command, subst):
cmd = arg_subst(command, subst) cmd = arg_subst(command, subst)
def add(x, y): return x + ' ' + str(y) def add(x, y): return x + ' ' + str(y)
return reduce(add, cmd, '') return functools.reduce(add, cmd, '')
class execute: class execute:
"""Execute commands or scripts. The 'output' is a funtion """Execute commands or scripts. The 'output' is a funtion
@ -105,6 +108,9 @@ class execute:
count = 0 count = 0
while True: while True:
line = fh.readline() line = fh.readline()
# str and bytes are the same type in Python2
if type(line) is not str and type(line) is bytes:
line = line.decode(sys.stdout.encoding)
count += 1 count += 1
if len(line) == 0: if len(line) == 0:
break break
@ -155,7 +161,7 @@ class execute:
s = command s = command
if type(command) is list: if type(command) is list:
def add(x, y): return x + ' ' + str(y) def add(x, y): return x + ' ' + str(y)
s = reduce(add, command, '')[1:] s = functools.reduce(add, command, '')[1:]
what = 'spawn' what = 'spawn'
if shell: if shell:
what = 'shell' what = 'shell'
@ -191,7 +197,7 @@ class execute:
exit_code = self.capture(proc) exit_code = self.capture(proc)
if self.verbose: if self.verbose:
log.output('exit: ' + str(exit_code)) log.output('exit: ' + str(exit_code))
except OSError, ose: except OSError as ose:
exit_code = ose.errno exit_code = ose.errno
if self.verbose: if self.verbose:
log.output('exit: ' + str(ose)) log.output('exit: ' + str(ose))
@ -325,9 +331,9 @@ if __name__ == "__main__":
ec, proc = e.command(commands['pipe'][0], commands['pipe'][1], ec, proc = e.command(commands['pipe'][0], commands['pipe'][1],
capture = False, stdin = subprocess.PIPE) capture = False, stdin = subprocess.PIPE)
if ec == 0: if ec == 0:
print 'piping input into ' + commands['pipe'][0] + ': ' + \ print('piping input into ' + commands['pipe'][0] + ': ' + \
commands['pipe'][2] commands['pipe'][2])
proc.stdin.write(commands['pipe'][2]) proc.stdin.write(bytes(commands['pipe'][2], sys.stdin.encoding))
proc.stdin.close() proc.stdin.close()
e.capture(proc) e.capture(proc)
del proc del proc
@ -352,10 +358,10 @@ if __name__ == "__main__":
('date %0 %1', ['-u', '+%d %D %S'])] ('date %0 %1', ['-u', '+%d %D %S'])]
commands['unix']['pipe'] = ('grep', 'hello', 'hello world') commands['unix']['pipe'] = ('grep', 'hello', 'hello world')
print arg_list('cmd a1 a2 "a3 is a string" a4') print(arg_list('cmd a1 a2 "a3 is a string" a4'))
print arg_list('cmd b1 b2 "b3 is a string a4') print(arg_list('cmd b1 b2 "b3 is a string a4'))
print arg_subst(['nothing', 'xx-%0-yyy', '%1', '%2-something'], print(arg_subst(['nothing', 'xx-%0-yyy', '%1', '%2-something'],
['subst0', 'subst1', 'subst2']) ['subst0', 'subst1', 'subst2']))
e = execute(error_prefix = 'ERR: ', verbose = True) e = execute(error_prefix = 'ERR: ', verbose = True)
if sys.platform == "win32": if sys.platform == "win32":

View File

@ -1,6 +1,6 @@
# #
# RTEMS Tools Project (http://www.rtems.org/) # RTEMS Tools Project (http://www.rtems.org/)
# Copyright 2010-2013 Chris Johns (chrisj@rtems.org) # Copyright 2010-2016 Chris Johns (chrisj@rtems.org)
# All rights reserved. # All rights reserved.
# #
# This file is part of the RTEMS Tools package in 'rtems-tools'. # This file is part of the RTEMS Tools package in 'rtems-tools'.
@ -21,6 +21,8 @@
# Provide some basic access to the git command. # Provide some basic access to the git command.
# #
from __future__ import print_function
import os import os
import error import error
@ -201,10 +203,10 @@ if __name__ == '__main__':
import sys import sys
opts = options.load(sys.argv) opts = options.load(sys.argv)
g = repo('.', opts) g = repo('.', opts)
print g.git_version() print(g.git_version())
print g.valid() print(g.valid())
print g.status() print(g.status())
print g.clean() print(g.clean())
print g.remotes() print(g.remotes())
print g.email() print(g.email())
print g.head() print(g.head())

View File

@ -121,7 +121,7 @@ def load():
'__chown': ('exe', 'required', '/usr/sbin/chown') }, '__chown': ('exe', 'required', '/usr/sbin/chown') },
} }
if variations.has_key(distro): if distro in variations:
for v in variations[distro]: for v in variations[distro]:
if path.exists(variations[distro][v][2]): if path.exists(variations[distro][v][2]):
defines[v] = variations[distro][v] defines[v] = variations[distro][v]

View File

@ -21,6 +21,8 @@
# Log output to stdout and/or a file. # Log output to stdout and/or a file.
# #
from __future__ import print_function
import os import os
import sys import sys
@ -56,16 +58,16 @@ def _output(text = os.linesep, log = None):
default.output(text) default.output(text)
else: else:
for l in text.replace(chr(13), '').splitlines(): for l in text.replace(chr(13), '').splitlines():
print l print(l)
sys.stdout.flush() sys.stdout.flush()
def stdout_raw(text = os.linesep): def stdout_raw(text = os.linesep):
print text, print(text, end=' ')
sys.stdout.flush() sys.stdout.flush()
def stderr(text = os.linesep, log = None): def stderr(text = os.linesep, log = None):
for l in text.replace(chr(13), '').splitlines(): for l in text.replace(chr(13), '').splitlines():
print >> sys.stderr, l print(l, file = sys.stderr)
sys.stderr.flush() sys.stderr.flush()
def output(text = os.linesep, log = None): def output(text = os.linesep, log = None):
@ -75,7 +77,7 @@ def output(text = os.linesep, log = None):
def notice(text = os.linesep, log = None): def notice(text = os.linesep, log = None):
if not quiet and default is not None and not default.has_stdout(): if not quiet and default is not None and not default.has_stdout():
for l in text.replace(chr(13), '').splitlines(): for l in text.replace(chr(13), '').splitlines():
print l print(l)
sys.stdout.flush() sys.stdout.flush()
_output(text, log) _output(text, log)
@ -114,8 +116,8 @@ class log:
self.fhs[1] = sys.stderr self.fhs[1] = sys.stderr
else: else:
try: try:
self.fhs.append(file(s, 'w')) self.fhs.append(open(s, 'w'))
except IOError, ioe: except IOError as ioe:
raise error.general("creating log file '" + s + \ raise error.general("creating log file '" + s + \
"': " + str(ioe)) "': " + str(ioe))
@ -168,41 +170,41 @@ if __name__ == "__main__":
l.output('log: hello world CRLF\r\n') l.output('log: hello world CRLF\r\n')
l.output('log: hello world NONE') l.output('log: hello world NONE')
l.flush() l.flush()
print '=-' * 40 print('=-' * 40)
print 'tail: %d' % (len(l.tail)) print('tail: %d' % (len(l.tail)))
print l print(l)
print '=-' * 40 print('=-' * 40)
for i in range(0, 10): for i in range(0, 10):
l.output('log: hello world 2: %d\n' % (i)) l.output('log: hello world 2: %d\n' % (i))
l.flush() l.flush()
print '=-' * 40 print('=-' * 40)
print 'tail: %d' % (len(l.tail)) print('tail: %d' % (len(l.tail)))
print l print(l)
print '=-' * 40 print('=-' * 40)
for i in [0, 1]: for i in [0, 1]:
quiet = False quiet = False
tracing = False tracing = False
print '- quiet:%s - trace:%s %s' % (str(quiet), str(tracing), '-' * 30) print('- quiet:%s - trace:%s %s' % (str(quiet), str(tracing), '-' * 30))
trace('trace with quiet and trace off') trace('trace with quiet and trace off')
notice('notice with quiet and trace off') notice('notice with quiet and trace off')
quiet = True quiet = True
tracing = False tracing = False
print '- quiet:%s - trace:%s %s' % (str(quiet), str(tracing), '-' * 30) print('- quiet:%s - trace:%s %s' % (str(quiet), str(tracing), '-' * 30))
trace('trace with quiet on and trace off') trace('trace with quiet on and trace off')
notice('notice with quiet on and trace off') notice('notice with quiet on and trace off')
quiet = False quiet = False
tracing = True tracing = True
print '- quiet:%s - trace:%s %s' % (str(quiet), str(tracing), '-' * 30) print('- quiet:%s - trace:%s %s' % (str(quiet), str(tracing), '-' * 30))
trace('trace with quiet off and trace on') trace('trace with quiet off and trace on')
notice('notice with quiet off and trace on') notice('notice with quiet off and trace on')
quiet = True quiet = True
tracing = True tracing = True
print '- quiet:%s - trace:%s %s' % (str(quiet), str(tracing), '-' * 30) print('- quiet:%s - trace:%s %s' % (str(quiet), str(tracing), '-' * 30))
trace('trace with quiet on and trace on') trace('trace with quiet on and trace on')
notice('notice with quiet on and trace on') notice('notice with quiet on and trace on')
default = l default = l
print '=-' * 40 print('=-' * 40)
print 'tail: %d' % (len(l.tail)) print('tail: %d' % (len(l.tail)))
print l print(l)
print '=-' * 40 print('=-' * 40)
del l del l

View File

@ -21,6 +21,8 @@
# Macro tables. # Macro tables.
# #
from __future__ import print_function
import re import re
import os import os
import string import string
@ -41,7 +43,7 @@ class macros:
def __iter__(self): def __iter__(self):
return self return self
def next(self): def __next__(self):
if self.index < len(self.keys): if self.index < len(self.keys):
key = self.keys[self.index] key = self.keys[self.index]
self.index += 1 self.index += 1
@ -51,6 +53,19 @@ class macros:
def iterkeys(self): def iterkeys(self):
return self.keys return self.keys
def _unicode_to_str(self, us):
try:
if type(us) == unicode:
return us.encode('ascii', 'replace')
except:
pass
try:
if type(us) == bytes:
return us.encode('ascii', 'replace')
except:
pass
return us
def __init__(self, name = None, original = None, sbdir = '.'): def __init__(self, name = None, original = None, sbdir = '.'):
self.files = [] self.files = []
self.macro_filter = re.compile(r'%{[^}]+}') self.macro_filter = re.compile(r'%{[^}]+}')
@ -124,7 +139,7 @@ class macros:
return text return text
def __iter__(self): def __iter__(self):
return macros.macro_iterator(self.keys()) return macros.macro_iterator(list(self.keys()))
def __getitem__(self, key): def __getitem__(self, key):
macro = self.get(key) macro = self.get(key)
@ -133,14 +148,20 @@ class macros:
return macro[2] return macro[2]
def __setitem__(self, key, value): def __setitem__(self, key, value):
key = self._unicode_to_str(key)
if type(key) is not str: if type(key) is not str:
raise TypeError('bad key type (want str): %s' % (type(key))) raise TypeError('bad key type (want str): %s' % (type(key)))
if type(value) is not tuple:
value = self._unicode_to_str(value)
if type(value) is str: if type(value) is str:
value = ('none', 'none', value) value = ('none', 'none', value)
if type(value) is not tuple: if type(value) is not tuple:
raise TypeError('bad value type (want tuple): %s' % (type(value))) raise TypeError('bad value type (want tuple): %s' % (type(value)))
if len(value) != 3: if len(value) != 3:
raise TypeError('bad value tuple (len not 3): %d' % (len(value))) raise TypeError('bad value tuple (len not 3): %d' % (len(value)))
value = (self._unicode_to_str(value[0]),
self._unicode_to_str(value[1]),
self._unicode_to_str(value[2]))
if type(value[0]) is not str: if type(value[0]) is not str:
raise TypeError('bad value tuple type field: %s' % (type(value[0]))) raise TypeError('bad value tuple type field: %s' % (type(value[0])))
if type(value[1]) is not str: if type(value[1]) is not str:
@ -163,11 +184,11 @@ class macros:
return self.has_key(key) return self.has_key(key)
def __len__(self): def __len__(self):
return len(self.keys()) return len(list(self.keys()))
def keys(self, globals = True): def keys(self, globals = True):
if globals: if globals:
keys = self.macros['global'].keys() keys = list(self.macros['global'].keys())
else: else:
keys = [] keys = []
for rm in self.get_read_maps(): for rm in self.get_read_maps():
@ -182,7 +203,7 @@ class macros:
def has_key(self, key): def has_key(self, key):
if type(key) is not str: if type(key) is not str:
raise TypeError('bad key type (want str): %s' % (type(key))) raise TypeError('bad key type (want str): %s' % (type(key)))
if self.key_filter(key) not in self.keys(): if self.key_filter(key) not in list(self.keys()):
return False return False
return True return True
@ -195,7 +216,7 @@ class macros:
self.macros.pop(_map, None) self.macros.pop(_map, None)
def maps(self): def maps(self):
return self.macros.keys() return list(self.macros.keys())
def map_keys(self, _map): def map_keys(self, _map):
if _map in self.macros: if _map in self.macros:
@ -226,7 +247,7 @@ class macros:
trace_me = False trace_me = False
if trace_me: if trace_me:
print '[[[[]]]] parsing macros' print('[[[[]]]] parsing macros')
macros = { 'global': {} } macros = { 'global': {} }
map = 'global' map = 'global'
lc = 0 lc = 0
@ -238,11 +259,12 @@ class macros:
#print 'l:%s' % (l[:-1]) #print 'l:%s' % (l[:-1])
if len(l) == 0: if len(l) == 0:
continue continue
l = self._unicode_to_str(l)
l_remaining = l l_remaining = l
for c in l: for c in l:
if trace_me: if trace_me:
print ']]]]]]]] c:%s(%d) s:%s t:"%s" m:%r M:%s' % \ print(']]]]]]]] c:%s(%d) s:%s t:"%s" m:%r M:%s' % \
(c, ord(c), state, token, macro, map) (c, ord(c), state, token, macro, map))
l_remaining = l_remaining[1:] l_remaining = l_remaining[1:]
if c is '#' and not state.startswith('value'): if c is '#' and not state.startswith('value'):
break break
@ -345,7 +367,10 @@ class macros:
else: else:
raise error.internal('bad state: %s' % (state)) raise error.internal('bad state: %s' % (state))
if state is 'macro': if state is 'macro':
macros[map][macro[0].lower()] = (macro[1], macro[2], macro[3]) macros[map][self._unicode_to_str(macro[0].lower())] = \
(self._unicode_to_str(macro[1]),
self._unicode_to_str(macro[2]),
self._unicode_to_str(macro[3]))
macro = [] macro = []
token = '' token = ''
state = 'key' state = 'key'
@ -365,7 +390,7 @@ class macros:
mc.close() mc.close()
self.files += [n] self.files += [n]
return return
except IOError, err: except IOError as err:
pass pass
raise error.general('opening macro file: %s' % \ raise error.general('opening macro file: %s' % \
(path.host(self.expand(name)))) (path.host(self.expand(name))))
@ -481,22 +506,22 @@ class macros:
if __name__ == "__main__": if __name__ == "__main__":
import copy import copy
import sys import sys
m = macros(name = 'defaults.mc') m = macros()
d = copy.copy(m) d = copy.copy(m)
m['test1'] = 'something' m['test1'] = 'something'
if d.has_key('test1'): if 'test1' in d:
print 'error: copy failed.' print('error: copy failed.')
sys.exit(1) sys.exit(1)
m.parse("[test]\n" \ m.parse("[test]\n" \
"test1: none, undefine, ''\n" \ "test1: none, undefine, ''\n" \
"name: none, override, 'pink'\n") "name: none, override, 'pink'\n")
print 'set test:', m.set_read_map('test') print('set test:', m.set_read_map('test'))
if m['name'] != 'pink': if m['name'] != 'pink':
print 'error: override failed. name is %s' % (m['name']) print('error: override failed. name is %s' % (m['name']))
sys.exit(1) sys.exit(1)
if m.has_key('test1'): if 'test1' in m:
print 'error: map undefine failed.' print('error: map undefine failed.')
sys.exit(1) sys.exit(1)
print 'unset test:', m.unset_read_map('test') print('unset test:', m.unset_read_map('test'))
print m print(m)
print m.keys() print(list(m.keys()))

View File

@ -21,6 +21,8 @@
# Manage emailing results or reports. # Manage emailing results or reports.
# #
from __future__ import print_function
import os import os
import smtplib import smtplib
import socket import socket
@ -64,7 +66,7 @@ class mail:
mrc = open(mailrc, 'r') mrc = open(mailrc, 'r')
lines = mrc.readlines() lines = mrc.readlines()
mrc.close() mrc.close()
except IOError, err: except IOError as err:
raise error.general('error reading: %s' % (mailrc)) raise error.general('error reading: %s' % (mailrc))
for l in lines: for l in lines:
l = _clean(l) l = _clean(l)
@ -93,9 +95,9 @@ class mail:
try: try:
s = smtplib.SMTP(self.smtp_host()) s = smtplib.SMTP(self.smtp_host())
s.sendmail(from_addr, [to_addr], msg) s.sendmail(from_addr, [to_addr], msg)
except smtplib.SMTPException, se: except smtplib.SMTPException as se:
raise error.general('sending mail: %s' % (str(se))) raise error.general('sending mail: %s' % (str(se)))
except socket.error, se: except socket.error as se:
raise error.general('sending mail: %s' % (str(se))) raise error.general('sending mail: %s' % (str(se)))
if __name__ == '__main__': if __name__ == '__main__':
@ -104,6 +106,6 @@ if __name__ == '__main__':
append_options(optargs) append_options(optargs)
opts = options.load(sys.argv, optargs = optargs, defaults = 'defaults.mc') opts = options.load(sys.argv, optargs = optargs, defaults = 'defaults.mc')
m = mail(opts) m = mail(opts)
print 'From: %s' % (m.from_address()) print('From: %s' % (m.from_address()))
print 'SMTP Host: %s' % (m.smtp_host()) print('SMTP Host: %s' % (m.smtp_host()))
m.send(m.from_address(), 'Test mailer.py', 'This is a test') m.send(m.from_address(), 'Test mailer.py', 'This is a test')

View File

@ -1,6 +1,6 @@
# #
# RTEMS Tools Project (http://www.rtems.org/) # RTEMS Tools Project (http://www.rtems.org/)
# Copyright 2010-2013 Chris Johns (chrisj@rtems.org) # Copyright 2010-2016 Chris Johns (chrisj@rtems.org)
# All rights reserved. # All rights reserved.
# #
# This file is part of the RTEMS Tools package in 'rtems-tools'. # This file is part of the RTEMS Tools package in 'rtems-tools'.
@ -21,6 +21,8 @@
# Determine the defaults and load the specific file. # Determine the defaults and load the specific file.
# #
from __future__ import print_function
import datetime import datetime
import glob import glob
import pprint import pprint
@ -41,9 +43,10 @@ import version
basepath = 'sb' basepath = 'sb'
# #
# Save the host state. # Save the host and POSIX state.
# #
host_windows = False host_windows = False
host_posix = True
class command_line: class command_line:
"""Process the command line in a common way for all Tool Builder commands.""" """Process the command line in a common way for all Tool Builder commands."""
@ -96,7 +99,7 @@ class command_line:
def __str__(self): def __str__(self):
def _dict(dd): def _dict(dd):
s = '' s = ''
ddl = dd.keys() ddl = list(dd.keys())
ddl.sort() ddl.sort()
for d in ddl: for d in ddl:
s += ' ' + d + ': ' + str(dd[d]) + '\n' s += ' ' + d + ': ' + str(dd[d]) + '\n'
@ -189,44 +192,44 @@ class command_line:
self.help() self.help()
def help(self): def help(self):
print '%s: [options] [args]' % (self.command_name) print('%s: [options] [args]' % (self.command_name))
print 'RTEMS Source Builder, an RTEMS Tools Project (c) 2012-2015 Chris Johns' print('RTEMS Source Builder, an RTEMS Tools Project (c) 2012-2015 Chris Johns')
print 'Options and arguments:' print('Options and arguments:')
print '--force : Force the build to proceed' print('--force : Force the build to proceed')
print '--quiet : Quiet output (not used)' print('--quiet : Quiet output (not used)')
print '--trace : Trace the execution' print('--trace : Trace the execution')
print '--dry-run : Do everything but actually run the build' print('--dry-run : Do everything but actually run the build')
print '--warn-all : Generate warnings' print('--warn-all : Generate warnings')
print '--no-clean : Do not clean up the build tree' print('--no-clean : Do not clean up the build tree')
print '--always-clean : Always clean the build tree, even with an error' print('--always-clean : Always clean the build tree, even with an error')
print '--keep-going : Do not stop on an error.' print('--keep-going : Do not stop on an error.')
print '--regression : Set --no-install, --keep-going and --always-clean' print('--regression : Set --no-install, --keep-going and --always-clean')
print '--jobs : Run with specified number of jobs, default: num CPUs.' print('--jobs : Run with specified number of jobs, default: num CPUs.')
print '--host : Set the host triplet' print('--host : Set the host triplet')
print '--build : Set the build triplet' print('--build : Set the build triplet')
print '--target : Set the target triplet' print('--target : Set the target triplet')
print '--prefix path : Tools build prefix, ie where they are installed' print('--prefix path : Tools build prefix, ie where they are installed')
print '--topdir path : Top of the build tree, default is $PWD' print('--topdir path : Top of the build tree, default is $PWD')
print '--configdir path : Path to the configuration directory, default: ./config' print('--configdir path : Path to the configuration directory, default: ./config')
print '--builddir path : Path to the build directory, default: ./build' print('--builddir path : Path to the build directory, default: ./build')
print '--sourcedir path : Path to the source directory, default: ./source' print('--sourcedir path : Path to the source directory, default: ./source')
print '--tmppath path : Path to the temp directory, default: ./tmp' print('--tmppath path : Path to the temp directory, default: ./tmp')
print '--macros file[,[file] : Macro format files to load after the defaults' print('--macros file[,[file] : Macro format files to load after the defaults')
print '--log file : Log file where all build out is written too' print('--log file : Log file where all build out is written too')
print '--url url[,url] : URL to look for source' print('--url url[,url] : URL to look for source')
print '--no-download : Disable the source downloader' print('--no-download : Disable the source downloader')
print '--no-install : Do not install the packages to the prefix' print('--no-install : Do not install the packages to the prefix')
print '--targetcflags flags : List of C flags for the target code' print('--targetcflags flags : List of C flags for the target code')
print '--targetcxxflags flags : List of C++ flags for the target code' print('--targetcxxflags flags : List of C++ flags for the target code')
print '--libstdcxxflags flags : List of C++ flags to build the target libstdc++ code' print('--libstdcxxflags flags : List of C++ flags to build the target libstdc++ code')
print '--with-<label> : Add the --with-<label> to the build' print('--with-<label> : Add the --with-<label> to the build')
print '--without-<label> : Add the --without-<label> to the build' print('--without-<label> : Add the --without-<label> to the build')
print '--rtems-tools path : Path to an install RTEMS tool set' print('--rtems-tools path : Path to an install RTEMS tool set')
print '--rtems-bsp arc/bsp : Standard RTEMS architecure and BSP specifier' print('--rtems-bsp arc/bsp : Standard RTEMS architecure and BSP specifier')
print '--rtems-version ver : The RTEMS major/minor version string' print('--rtems-version ver : The RTEMS major/minor version string')
if self.optargs: if self.optargs:
for a in self.optargs: for a in self.optargs:
print '%-22s : %s' % (a, self.optargs[a]) print('%-22s : %s' % (a, self.optargs[a]))
raise error.exit() raise error.exit()
def process(self): def process(self):
@ -483,7 +486,7 @@ class command_line:
# #
config = path.shell(config) config = path.shell(config)
if '*' in config or '?' in config: if '*' in config or '?' in config:
print config print(config)
configdir = path.dirname(config) configdir = path.dirname(config)
configbase = path.basename(config) configbase = path.basename(config)
if len(configbase) == 0: if len(configbase) == 0:
@ -562,6 +565,7 @@ def load(args, optargs = None, defaults = '%{_sbdir}/defaults.mc'):
""" """
global host_windows global host_windows
global host_posix
# #
# The path to this command. # The path to this command.
@ -586,12 +590,17 @@ def load(args, optargs = None, defaults = '%{_sbdir}/defaults.mc'):
import windows import windows
overrides = windows.load() overrides = windows.load()
host_windows = True host_windows = True
host_posix = False
except: except:
raise error.general('failed to load Windows host support') raise error.general('failed to load Windows host support')
elif os.name == 'posix': elif os.name == 'posix':
uname = os.uname() uname = os.uname()
try: try:
if uname[0].startswith('CYGWIN_NT'): if uname[0].startswith('MINGW64_NT'):
import windows
overrides = windows.load()
host_windows = True
elif uname[0].startswith('CYGWIN_NT'):
import windows import windows
overrides = windows.load() overrides = windows.load()
elif uname[0] == 'Darwin': elif uname[0] == 'Darwin':
@ -642,13 +651,13 @@ def run(args):
log.notice(str(_opts.defaults)) log.notice(str(_opts.defaults))
log.notice('with-opt1: %r' % (_opts.with_arg('opt1'))) log.notice('with-opt1: %r' % (_opts.with_arg('opt1')))
log.notice('without-opt2: %r' % (_opts.with_arg('opt2'))) log.notice('without-opt2: %r' % (_opts.with_arg('opt2')))
except error.general, gerr: except error.general as gerr:
print gerr print(gerr)
sys.exit(1) sys.exit(1)
except error.internal, ierr: except error.internal as ierr:
print ierr print(ierr)
sys.exit(1) sys.exit(1)
except error.exit, eerr: except error.exit as eerr:
pass pass
except KeyboardInterrupt: except KeyboardInterrupt:
_notice(opts, 'abort: user terminated') _notice(opts, 'abort: user terminated')

View File

@ -1,6 +1,6 @@
# #
# RTEMS Tools Project (http://www.rtems.org/) # RTEMS Tools Project (http://www.rtems.org/)
# Copyright 2010-2015 Chris Johns (chrisj@rtems.org) # Copyright 2010-2016 Chris Johns (chrisj@rtems.org)
# All rights reserved. # All rights reserved.
# #
# This file is part of the RTEMS Tools package in 'rtems-tools'. # This file is part of the RTEMS Tools package in 'rtems-tools'.
@ -23,6 +23,8 @@
# level. This allows macro expansion to work. # level. This allows macro expansion to work.
# #
from __future__ import print_function
import log import log
import os import os
import shutil import shutil
@ -119,18 +121,18 @@ def mkdir(path):
if windows: if windows:
try: try:
os.makedirs(host(path)) os.makedirs(host(path))
except IOError, err: except IOError as err:
raise error.general('cannot make directory: %s' % (path)) raise error.general('cannot make directory: %s' % (path))
except OSError, err: except OSError as err:
raise error.general('cannot make directory: %s' % (path)) raise error.general('cannot make directory: %s' % (path))
except WindowsError, err: except WindowsError as err:
raise error.general('cannot make directory: %s' % (path)) raise error.general('cannot make directory: %s' % (path))
else: else:
try: try:
os.makedirs(host(path)) os.makedirs(host(path))
except IOError, err: except IOError as err:
raise error.general('cannot make directory: %s' % (path)) raise error.general('cannot make directory: %s' % (path))
except OSError, err: except OSError as err:
raise error.general('cannot make directory: %s' % (path)) raise error.general('cannot make directory: %s' % (path))
def removeall(path): def removeall(path):
@ -172,7 +174,7 @@ def copy(src, dst):
hdst = host(dst) hdst = host(dst)
try: try:
shutil.copy(hsrc, hdst) shutil.copy(hsrc, hdst)
except OSError, why: except OSError as why:
if windows: if windows:
if WindowsError is not None and isinstance(why, WindowsError): if WindowsError is not None and isinstance(why, WindowsError):
pass pass
@ -191,19 +193,19 @@ def copy_tree(src, dst):
names = [] names = []
if trace: if trace:
print 'path.copy_tree:' print('path.copy_tree:')
print ' src: %s' % (src) print(' src: %s' % (src))
print ' hsrc: %s' % (hsrc) print(' hsrc: %s' % (hsrc))
print ' dst: %s' % (dst) print(' dst: %s' % (dst))
print ' hdst: %s' % (hdst) print(' hdst: %s' % (hdst))
print ' names: %r' % (names) print(' names: %r' % (names))
if not os.path.isdir(hdst): if not os.path.isdir(hdst):
if trace: if trace:
print ' mkdir: %s' % (hdst) print(' mkdir: %s' % (hdst))
try: try:
os.makedirs(hdst) os.makedirs(hdst)
except OSError, why: except OSError as why:
raise error.general('copying tree: cannot create target directory %s: %s' % \ raise error.general('copying tree: cannot create target directory %s: %s' % \
(hdst, str(why))) (hdst, str(why)))
@ -230,15 +232,15 @@ def copy_tree(src, dst):
copy_tree(srcname, dstname) copy_tree(srcname, dstname)
else: else:
shutil.copy2(host(srcname), host(dstname)) shutil.copy2(host(srcname), host(dstname))
except shutil.Error, err: except shutil.Error as err:
raise error.general('copying tree: %s -> %s: %s' % \ raise error.general('copying tree: %s -> %s: %s' % \
(hsrc, hdst, str(err))) (hsrc, hdst, str(err)))
except EnvironmentError, why: except EnvironmentError as why:
raise error.general('copying tree: %s -> %s: %s' % \ raise error.general('copying tree: %s -> %s: %s' % \
(srcname, dstname, str(why))) (srcname, dstname, str(why)))
try: try:
shutil.copystat(hsrc, hdst) shutil.copystat(hsrc, hdst)
except OSError, why: except OSError as why:
if windows: if windows:
if WindowsError is not None and isinstance(why, WindowsError): if WindowsError is not None and isinstance(why, WindowsError):
pass pass
@ -246,17 +248,17 @@ def copy_tree(src, dst):
raise error.general('copying tree: %s -> %s: %s' % (hsrc, hdst, str(why))) raise error.general('copying tree: %s -> %s: %s' % (hsrc, hdst, str(why)))
if __name__ == '__main__': if __name__ == '__main__':
print host('/a/b/c/d-e-f') print(host('/a/b/c/d-e-f'))
print host('//a/b//c/d-e-f') print(host('//a/b//c/d-e-f'))
print shell('/w/x/y/z') print(shell('/w/x/y/z'))
print basename('/as/sd/df/fg/me.txt') print(basename('/as/sd/df/fg/me.txt'))
print dirname('/as/sd/df/fg/me.txt') print(dirname('/as/sd/df/fg/me.txt'))
print join('/d', 'g', '/tyty/fgfg') print(join('/d', 'g', '/tyty/fgfg'))
windows = True windows = True
print host('/a/b/c/d-e-f') print(host('/a/b/c/d-e-f'))
print host('//a/b//c/d-e-f') print(host('//a/b//c/d-e-f'))
print shell('/w/x/y/z') print(shell('/w/x/y/z'))
print shell('w:/x/y/z') print(shell('w:/x/y/z'))
print basename('x:/sd/df/fg/me.txt') print(basename('x:/sd/df/fg/me.txt'))
print dirname('x:/sd/df/fg/me.txt') print(dirname('x:/sd/df/fg/me.txt'))
print join('s:/d/e\\f/g', '/h', '/tyty/zxzx', '\\mm\\nn/p') print(join('s:/d/e\\f/g', '/h', '/tyty/zxzx', '\\mm\\nn/p'))

View File

@ -1,7 +1,7 @@
#! /usr/bin/env python #! /usr/bin/env python
# #
# RTEMS Tools Project (http://www.rtems.org/) # RTEMS Tools Project (http://www.rtems.org/)
# Copyright 2014 Chris Johns (chrisj@rtems.org) # Copyright 2014-2016 Chris Johns (chrisj@rtems.org)
# All rights reserved. # All rights reserved.
# #
# This file is part of the RTEMS Tools package in 'rtems-tools'. # This file is part of the RTEMS Tools package in 'rtems-tools'.
@ -34,6 +34,8 @@
# provided by the full pkg-config so packages can configure and build. # provided by the full pkg-config so packages can configure and build.
# #
from __future__ import print_function
import copy import copy
import os import os
import os.path import os.path
@ -196,7 +198,7 @@ class package(object):
@staticmethod @staticmethod
def dump_loaded(): def dump_loaded():
for n in sorted(package.loaded): for n in sorted(package.loaded):
print package.loaded[n]._str() print(package.loaded[n]._str())
def __init__(self, name = None, prefix = None, def __init__(self, name = None, prefix = None,
libs_scan = False, output = None, src = None): libs_scan = False, output = None, src = None):
@ -458,7 +460,7 @@ class package(object):
lhs = l[:d].lower() lhs = l[:d].lower()
rhs = l[d + 1:] rhs = l[d + 1:]
if tm: if tm:
print('define: ' + str(define) + ', lhs: ' + lhs + ', ' + rhs) print(('define: ' + str(define) + ', lhs: ' + lhs + ', ' + rhs))
if define: if define:
self.defines[lhs] = rhs self.defines[lhs] = rhs
else: else:

View File

@ -22,6 +22,8 @@
# installed not to be package unless you run a packager around this. # installed not to be package unless you run a packager around this.
# #
from __future__ import print_function
import copy import copy
import datetime import datetime
import os import os
@ -43,10 +45,10 @@ try:
import sources import sources
import version import version
except KeyboardInterrupt: except KeyboardInterrupt:
print 'user terminated' print('user terminated', file = sys.stderr)
sys.exit(1) sys.exit(1)
except: except:
print 'error: unknown application load error' print('error: unknown application load error', file = sys.stderr)
sys.exit(1) sys.exit(1)
_line_len = 78 _line_len = 78
@ -104,7 +106,7 @@ class formatter(object):
return return
def buildset_start(self, nest_level, name): def buildset_start(self, nest_level, name):
self.line('=-' * (_line_len / 2)) self.line('=-' * int(_line_len / 2))
self.line('Build Set: (%d) %s' % (nest_level, name)) self.line('Build Set: (%d) %s' % (nest_level, name))
def buildset_end(self, nest_level, name): def buildset_end(self, nest_level, name):
@ -216,7 +218,7 @@ class asciidoc_formatter(formatter):
def buildset_start(self, nest_level, name): def buildset_start(self, nest_level, name):
h = '%s' % (name) h = '%s' % (name)
self.line('=%s %s' % ('=' * nest_level, h)) self.line('=%s %s' % ('=' * int(nest_level), h))
def info(self, nest_level, name, info, separated): def info(self, nest_level, name, info, separated):
end = '' end = ''
@ -266,9 +268,9 @@ class html_formatter(asciidoc_formatter):
return '.html' return '.html'
def post_process(self): def post_process(self):
import StringIO import io
infile = StringIO.StringIO(self.content) infile = io.StringIO(self.content)
outfile = StringIO.StringIO() outfile = io.StringIO()
try: try:
import asciidocapi import asciidocapi
except: except:
@ -647,12 +649,12 @@ class report:
tree['file'] += [_config.file_name()] tree['file'] += [_config.file_name()]
if len(sources): if len(sources):
if 'sources' in tree: if 'sources' in tree:
tree['sources'] = dict(tree['sources'].items() + sources.items()) tree['sources'] = dict(list(tree['sources'].items()) + list(sources.items()))
else: else:
tree['sources'] = sources tree['sources'] = sources
if len(patches): if len(patches):
if 'patches' in tree: if 'patches' in tree:
tree['patches'] = dict(tree['patches'].items() + patches.items()) tree['patches'] = dict(list(tree['patches'].items()) + list(patches.items()))
else: else:
tree['patches'] = patches tree['patches'] = patches
self.config_start(name, _config) self.config_start(name, _config)
@ -682,7 +684,7 @@ class report:
if len(files): if len(files):
for f in range(0, len(files) - 1): for f in range(0, len(files) - 1):
self.output('; %s |- %s' % (prefix, files[f])) self.output('; %s |- %s' % (prefix, files[f]))
if 'bset' in tree and len(tree['bset'].keys()): if 'bset' in tree and len(list(tree['bset'].keys())):
c = '|' c = '|'
else: else:
c = '+' c = '+'
@ -717,7 +719,7 @@ class report:
self.output(' %s = %s' % (source[0], hash)) self.output(' %s = %s' % (source[0], hash))
def generate_ini(self): def generate_ini(self):
nodes = sorted([node for node in self.tree.keys() if node != 'bset']) nodes = sorted([node for node in list(self.tree.keys()) if node != 'bset'])
self.output(';') self.output(';')
self.output('; Configuration Tree:') self.output('; Configuration Tree:')
for node in range(0, len(nodes)): for node in range(0, len(nodes)):
@ -742,7 +744,7 @@ class report:
o.write(self.out) o.write(self.out)
o.close() o.close()
del o del o
except IOError, err: except IOError as err:
raise error.general('writing output file: %s: %s' % (name, err)) raise error.general('writing output file: %s: %s' % (name, err))
def generate(self, name, tree = None, opts = None, macros = None): def generate(self, name, tree = None, opts = None, macros = None):
@ -787,7 +789,7 @@ def run(args):
opts = options.load(args, optargs) opts = options.load(args, optargs)
if opts.get_arg('--output') and len(opts.params()) > 1: if opts.get_arg('--output') and len(opts.params()) > 1:
raise error.general('--output can only be used with a single config') raise error.general('--output can only be used with a single config')
print 'RTEMS Source Builder, Reporter, %s' % (version.str()) print('RTEMS Source Builder, Reporter, %s' % (version.str()))
opts.log_info() opts.log_info()
if not check.host_setup(opts): if not check.host_setup(opts):
log.warning('forcing build with known host setup problems') log.warning('forcing build with known host setup problems')
@ -827,13 +829,13 @@ def run(args):
del r del r
else: else:
raise error.general('invalid config type: %s' % (config)) raise error.general('invalid config type: %s' % (config))
except error.general, gerr: except error.general as gerr:
print gerr print(gerr)
sys.exit(1) sys.exit(1)
except error.internal, ierr: except error.internal as ierr:
print ierr print(ierr)
sys.exit(1) sys.exit(1)
except error.exit, eerr: except error.exit as eerr:
pass pass
except KeyboardInterrupt: except KeyboardInterrupt:
log.notice('abort: user terminated') log.notice('abort: user terminated')

View File

@ -1,6 +1,6 @@
# #
# RTEMS Tools Project (http://www.rtems.org/) # RTEMS Tools Project (http://www.rtems.org/)
# Copyright 2013 Chris Johns (chrisj@rtems.org) # Copyright 2013-2016 Chris Johns (chrisj@rtems.org)
# All rights reserved. # All rights reserved.
# #
# This file is part of the RTEMS Tools package in 'rtems-tools'. # This file is part of the RTEMS Tools package in 'rtems-tools'.
@ -18,6 +18,8 @@
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
# #
from __future__ import print_function
import datetime import datetime
import operator import operator
import os import os
@ -46,7 +48,7 @@ def _grep(file, pattern):
f = open(path.host(file), 'r') f = open(path.host(file), 'r')
matches = [rege.match(l) != None for l in f.readlines()] matches = [rege.match(l) != None for l in f.readlines()]
f.close() f.close()
except IOError, err: except IOError as err:
raise error.general('error reading: %s' % (file)) raise error.general('error reading: %s' % (file))
return True in matches return True in matches
@ -86,7 +88,7 @@ class command:
try: try:
cmd = [self.opts.defaults.expand(c) for c in self.cmd] cmd = [self.opts.defaults.expand(c) for c in self.cmd]
self.output = subprocess.check_output(cmd, cwd = self.cwd) self.output = subprocess.check_output(cmd, cwd = self.cwd)
except subprocess.CalledProcessError, cpe: except subprocess.CalledProcessError as cpe:
self.exit_code = cpe.returncode self.exit_code = cpe.returncode
self.output = cpe.output self.output = cpe.output
self.end_time = datetime.datetime.now() self.end_time = datetime.datetime.now()
@ -168,7 +170,7 @@ class bsp_config:
return _keys return _keys
def find(self, name): def find(self, name):
_keys = self.keys() _keys = list(self.keys())
nl = name.lower() nl = name.lower()
if nl in _keys and not nl in bsp_config.filter_out: if nl in _keys and not nl in bsp_config.filter_out:
return self.configs[_keys[nl]] return self.configs[_keys[nl]]
@ -193,20 +195,20 @@ def run(args):
if opts.get_arg('--list'): if opts.get_arg('--list'):
log.notice('RTEMS Source Builder - RTEMS Configuration, %s' % (version.str())) log.notice('RTEMS Source Builder - RTEMS Configuration, %s' % (version.str()))
opts.log_info() opts.log_info()
configs = bsp.keys() configs = list(bsp.keys())
for c in sorted(configs.keys()): for c in sorted(configs.keys()):
print c print(c)
else: else:
for p in opts.params(): for p in opts.params():
print bsp.find(p) print(bsp.find(p))
except error.general, gerr: except error.general as gerr:
print gerr print(gerr)
sys.exit(1) sys.exit(1)
except error.internal, ierr: except error.internal as ierr:
print ierr print(ierr)
sys.exit(1) sys.exit(1)
except error.exit, eerr: except error.exit as eerr:
pass pass
except KeyboardInterrupt: except KeyboardInterrupt:
log.notice('abort: user terminated') log.notice('abort: user terminated')

View File

@ -1,6 +1,6 @@
# #
# RTEMS Tools Project (http://www.rtems.org/) # RTEMS Tools Project (http://www.rtems.org/)
# Copyright 2010-2013 Chris Johns (chrisj@rtems.org) # Copyright 2010-2016 Chris Johns (chrisj@rtems.org)
# All rights reserved. # All rights reserved.
# #
# This file is part of the RTEMS Tools package in 'rtems-tools'. # This file is part of the RTEMS Tools package in 'rtems-tools'.
@ -22,6 +22,8 @@
# set lists the various tools. These are specific tool configurations. # set lists the various tools. These are specific tool configurations.
# #
from __future__ import print_function
import copy import copy
import datetime import datetime
import glob import glob
@ -41,10 +43,11 @@ try:
import sources import sources
import version import version
except KeyboardInterrupt: except KeyboardInterrupt:
print 'abort: user terminated' print('abort: user terminated', file = sys.stderr)
sys.exit(1) sys.exit(1)
except: except:
print 'error: unknown application load error' raise
print('error: unknown application load error', file = sys.stderr)
sys.exit(1) sys.exit(1)
class buildset: class buildset:
@ -225,7 +228,7 @@ class buildset:
try: try:
log.trace('_bset: %s: open: %s' % (self.bset, bsetname)) log.trace('_bset: %s: open: %s' % (self.bset, bsetname))
bset = open(path.host(bsetname), 'r') bset = open(path.host(bsetname), 'r')
except IOError, err: except IOError as err:
raise error.general('error opening bset file: %s' % (bsetname)) raise error.general('error opening bset file: %s' % (bsetname))
configs = [] configs = []
@ -363,7 +366,7 @@ class buildset:
builds += [b] builds += [b]
else: else:
raise error.general('invalid config type: %s' % (configs[s])) raise error.general('invalid config type: %s' % (configs[s]))
except error.general, gerr: except error.general as gerr:
have_errors = True have_errors = True
if b is not None: if b is not None:
if self.build_failure is None: if self.build_failure is None:
@ -405,7 +408,7 @@ class buildset:
b.cleanup() b.cleanup()
for b in builds: for b in builds:
del b del b
except error.general, gerr: except error.general as gerr:
if not build_error: if not build_error:
log.stderr(str(gerr)) log.stderr(str(gerr))
raise raise
@ -447,10 +450,10 @@ def list_bset_cfg_files(opts, configs):
else: else:
ext = '.bset' ext = '.bset'
for p in configs['paths']: for p in configs['paths']:
print 'Examining: %s' % (os.path.relpath(p)) print('Examining: %s' % (os.path.relpath(p)))
for c in configs['files']: for c in configs['files']:
if c.endswith(ext): if c.endswith(ext):
print ' %s' % (c) print(' %s' % (c))
return True return True
return False return False
@ -497,18 +500,18 @@ def run():
c = 0 c = 0
for d in sorted(set(deps)): for d in sorted(set(deps)):
c += 1 c += 1
print 'dep[%d]: %s' % (c, d) print('dep[%d]: %s' % (c, d))
except error.general, gerr: except error.general as gerr:
if not setbuilder_error: if not setbuilder_error:
log.stderr(str(gerr)) log.stderr(str(gerr))
log.stderr('Build FAILED') log.stderr('Build FAILED')
ec = 1 ec = 1
except error.internal, ierr: except error.internal as ierr:
if not setbuilder_error: if not setbuilder_error:
log.stderr(str(ierr)) log.stderr(str(ierr))
log.stderr('Internal Build FAILED') log.stderr('Internal Build FAILED')
ec = 1 ec = 1
except error.exit, eerr: except error.exit as eerr:
pass pass
except KeyboardInterrupt: except KeyboardInterrupt:
log.notice('abort: user terminated') log.notice('abort: user terminated')

View File

@ -1,6 +1,6 @@
# #
# RTEMS Tools Project (http://www.rtems.org/) # RTEMS Tools Project (http://www.rtems.org/)
# Copyright 2010-2015 Chris Johns (chrisj@rtems.org) # Copyright 2010-2016 Chris Johns (chrisj@rtems.org)
# All rights reserved. # All rights reserved.
# #
# This file is part of the RTEMS Tools package in 'rtems-tools'. # This file is part of the RTEMS Tools package in 'rtems-tools'.
@ -22,6 +22,8 @@
# to the top directory. # to the top directory.
# #
from __future__ import print_function
import sys import sys
import error import error
@ -48,8 +50,8 @@ def _load_released_version_config():
top = _top() top = _top()
for ver in [top, '..']: for ver in [top, '..']:
if path.exists(path.join(ver, 'VERSION')): if path.exists(path.join(ver, 'VERSION')):
import ConfigParser import configparser
v = ConfigParser.SafeConfigParser() v = configparser.SafeConfigParser()
v.read(path.join(ver, 'VERSION')) v.read(path.join(ver, 'VERSION'))
return v return v
return None return None
@ -107,4 +109,4 @@ def load_release_hashes(macros):
sources.hash((hs[0], hash[0], hs[1]), macros, hash_error) sources.hash((hs[0], hash[0], hs[1]), macros, hash_error)
if __name__ == '__main__': if __name__ == '__main__':
print 'Version: %s' % (str()) print('Version: %s' % (str()))

View File

@ -30,7 +30,7 @@ import execute
def load(): def load():
# Default to the native Windows Python. # Default to the native Windows Python.
uname = 'win32' uname = 'win32'
if os.environ.has_key('PROCESSOR_ARCHITECTURE'): if 'PROCESSOR_ARCHITECTURE' in os.environ:
if os.environ['PROCESSOR_ARCHITECTURE'] == 'AMD64': if os.environ['PROCESSOR_ARCHITECTURE'] == 'AMD64':
hosttype = 'x86_64' hosttype = 'x86_64'
machsize = '64' machsize = '64'
@ -41,30 +41,30 @@ def load():
hosttype = 'x86_64' hosttype = 'x86_64'
machsize = '32' machsize = '32'
# See if this is actually Cygwin Python uname = 'mingw32'
if os.name == 'posix': machine = 'w%s' % (machsize)
try:
uname = os.uname()
hosttype = uname[4]
uname = uname[0]
if uname.startswith('CYGWIN'):
uname = 'cygwin'
host_triple = hosttype + '-pc-' + uname
build_triple = hosttype + '-pc-' + uname
else:
raise error.general('invalid POSIX python')
except:
pass
else:
host_triple = '%s-w%s-mingw32' % (hosttype, machsize)
build_triple = '%s-w%s-mingw32' % (hosttype, machsize)
if os.environ.has_key('NUMBER_OF_PROCESSORS'): # See if this is actually MSYS2/Cygwin Python
if os.name == 'posix':
_uname = os.uname()
if _uname[0].startswith('MINGW'):
pass
elif _uname[0].startswith('CYGWIN'):
hosttype = _uname[4]
uname = 'cygwin'
machine = 'pc'
else:
raise error.general('invalid POSIX python for Windows')
host_triple = '%s-%s-%s' % (hosttype, machine, uname)
build_triple = '%s-%s-%s' % (hosttype, machine, uname)
if 'NUMBER_OF_PROCESSORS' in os.environ:
ncpus = os.environ['NUMBER_OF_PROCESSORS'] ncpus = os.environ['NUMBER_OF_PROCESSORS']
else: else:
ncpus = '1' ncpus = '1'
if os.environ.has_key('MSYSTEM'): if 'MSYSTEM' in os.environ:
os.environ.pop('NUMBER_OF_PROCESSORS') os.environ.pop('NUMBER_OF_PROCESSORS')
version = uname[2] version = uname[2]