summaryrefslogtreecommitdiffstats
path: root/source-builder/sb/path.py
diff options
context:
space:
mode:
authorChris Johns <chrisj@rtems.org>2016-03-07 11:56:02 +1100
committerChris Johns <chrisj@rtems.org>2016-03-07 13:16:17 +1100
commitf88fcf3ae04f366d1f1faaa4f567c43627d063d2 (patch)
tree85625ff5ad44270dedf56b9909b51ef2958aff2d /source-builder/sb/path.py
parentsb: Remove http query flags from the file name if present. (diff)
downloadrtems-source-builder-f88fcf3ae04f366d1f1faaa4f567c43627d063d2.tar.bz2
sb: Update code base to support Python3 and Python2.
Fix Windows support to allow MSYS2 Python to be used. Updates #2619.
Diffstat (limited to 'source-builder/sb/path.py')
-rw-r--r--source-builder/sb/path.py64
1 files changed, 33 insertions, 31 deletions
diff --git a/source-builder/sb/path.py b/source-builder/sb/path.py
index df76634..43f41eb 100644
--- a/source-builder/sb/path.py
+++ b/source-builder/sb/path.py
@@ -1,6 +1,6 @@
#
# 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.
#
# This file is part of the RTEMS Tools package in 'rtems-tools'.
@@ -23,6 +23,8 @@
# level. This allows macro expansion to work.
#
+from __future__ import print_function
+
import log
import os
import shutil
@@ -119,18 +121,18 @@ def mkdir(path):
if windows:
try:
os.makedirs(host(path))
- except IOError, err:
+ except IOError as err:
raise error.general('cannot make directory: %s' % (path))
- except OSError, err:
+ except OSError as err:
raise error.general('cannot make directory: %s' % (path))
- except WindowsError, err:
+ except WindowsError as err:
raise error.general('cannot make directory: %s' % (path))
else:
try:
os.makedirs(host(path))
- except IOError, err:
+ except IOError as err:
raise error.general('cannot make directory: %s' % (path))
- except OSError, err:
+ except OSError as err:
raise error.general('cannot make directory: %s' % (path))
def removeall(path):
@@ -172,7 +174,7 @@ def copy(src, dst):
hdst = host(dst)
try:
shutil.copy(hsrc, hdst)
- except OSError, why:
+ except OSError as why:
if windows:
if WindowsError is not None and isinstance(why, WindowsError):
pass
@@ -191,19 +193,19 @@ def copy_tree(src, dst):
names = []
if trace:
- print 'path.copy_tree:'
- print ' src: %s' % (src)
- print ' hsrc: %s' % (hsrc)
- print ' dst: %s' % (dst)
- print ' hdst: %s' % (hdst)
- print ' names: %r' % (names)
+ print('path.copy_tree:')
+ print(' src: %s' % (src))
+ print(' hsrc: %s' % (hsrc))
+ print(' dst: %s' % (dst))
+ print(' hdst: %s' % (hdst))
+ print(' names: %r' % (names))
if not os.path.isdir(hdst):
if trace:
- print ' mkdir: %s' % (hdst)
+ print(' mkdir: %s' % (hdst))
try:
os.makedirs(hdst)
- except OSError, why:
+ except OSError as why:
raise error.general('copying tree: cannot create target directory %s: %s' % \
(hdst, str(why)))
@@ -230,15 +232,15 @@ def copy_tree(src, dst):
copy_tree(srcname, dstname)
else:
shutil.copy2(host(srcname), host(dstname))
- except shutil.Error, err:
+ except shutil.Error as err:
raise error.general('copying tree: %s -> %s: %s' % \
(hsrc, hdst, str(err)))
- except EnvironmentError, why:
+ except EnvironmentError as why:
raise error.general('copying tree: %s -> %s: %s' % \
(srcname, dstname, str(why)))
try:
shutil.copystat(hsrc, hdst)
- except OSError, why:
+ except OSError as why:
if windows:
if WindowsError is not None and isinstance(why, WindowsError):
pass
@@ -246,17 +248,17 @@ def copy_tree(src, dst):
raise error.general('copying tree: %s -> %s: %s' % (hsrc, hdst, str(why)))
if __name__ == '__main__':
- print host('/a/b/c/d-e-f')
- print host('//a/b//c/d-e-f')
- print shell('/w/x/y/z')
- print basename('/as/sd/df/fg/me.txt')
- print dirname('/as/sd/df/fg/me.txt')
- print join('/d', 'g', '/tyty/fgfg')
+ print(host('/a/b/c/d-e-f'))
+ print(host('//a/b//c/d-e-f'))
+ print(shell('/w/x/y/z'))
+ print(basename('/as/sd/df/fg/me.txt'))
+ print(dirname('/as/sd/df/fg/me.txt'))
+ print(join('/d', 'g', '/tyty/fgfg'))
windows = True
- 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('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(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('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'))