scripts: python3: use new style except statement

Changed old syle except statements 'except <exception>, var'
to new style 'except <exception> as var' as old style is not
supported in python3.

(From OE-Core rev: 438eabc248f272e3d272aecaa4c9cec177b172d5)

Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Ed Bartosh 2016-06-02 13:12:48 +03:00 committed by Richard Purdie
parent 07c97db272
commit ee31bad762
4 changed files with 14 additions and 14 deletions

View File

@ -190,7 +190,7 @@ def runcmd(cmd,destdir=None,printerr=True,out=None,env=None):
err = os.tmpfile() err = os.tmpfile()
try: try:
subprocess.check_call(cmd, stdout=out, stderr=err, cwd=destdir, shell=isinstance(cmd, str), env=env or os.environ) subprocess.check_call(cmd, stdout=out, stderr=err, cwd=destdir, shell=isinstance(cmd, str), env=env or os.environ)
except subprocess.CalledProcessError,e: except subprocess.CalledProcessError as e:
err.seek(0) err.seek(0)
if printerr: if printerr:
logger.error("%s" % err.read()) logger.error("%s" % err.read())
@ -429,7 +429,7 @@ file_exclude = %s''' % (name, file_filter or '<empty>', repo.get('file_exclude',
runcmd('git replace --graft %s %s' % (start, startrev)) runcmd('git replace --graft %s %s' % (start, startrev))
try: try:
runcmd(merge) runcmd(merge)
except Exception, error: except Exception as error:
logger.info('''Merging component repository history failed, perhaps because of merge conflicts. logger.info('''Merging component repository history failed, perhaps because of merge conflicts.
It may be possible to commit anyway after resolving these conflicts. It may be possible to commit anyway after resolving these conflicts.

View File

@ -37,9 +37,9 @@ def recipe_bbvars(recipe):
vset = set() vset = set()
try: try:
r = open(recipe) r = open(recipe)
except IOError as (errno, strerror): except IOError as err:
print('WARNING: Failed to open recipe ', recipe) print('WARNING: Failed to open recipe ', recipe)
print(strerror) print(err.args[1])
for line in r: for line in r:
# Strip any comments from the line # Strip any comments from the line
@ -71,9 +71,9 @@ def bbvar_is_documented(var, docfiles):
for doc in docfiles: for doc in docfiles:
try: try:
f = open(doc) f = open(doc)
except IOError as (errno, strerror): except IOError as err:
print('WARNING: Failed to open doc ', doc) print('WARNING: Failed to open doc ', doc)
print(strerror) print(err.args[1])
for line in f: for line in f:
if prog.match(line): if prog.match(line):
return True return True
@ -87,8 +87,8 @@ def bbvar_doctag(var, docconf):
try: try:
f = open(docconf) f = open(docconf)
except IOError as (errno, strerror): except IOError as err:
return strerror return err.args[1]
for line in f: for line in f:
m = prog.search(line) m = prog.search(line)
@ -109,7 +109,7 @@ def main():
# Collect and validate input # Collect and validate input
try: try:
opts, args = getopt.getopt(sys.argv[1:], "d:hm:t:T", ["help"]) opts, args = getopt.getopt(sys.argv[1:], "d:hm:t:T", ["help"])
except getopt.GetoptError, err: except getopt.GetoptError as err:
print('%s' % str(err)) print('%s' % str(err))
usage() usage()
sys.exit(2) sys.exit(2)

View File

@ -33,16 +33,16 @@ def copytree(src, dst, symlinks=False, ignore=None):
shutil.copy2(srcname, dstname) shutil.copy2(srcname, dstname)
# catch the Error from the recursive copytree so that we can # catch the Error from the recursive copytree so that we can
# continue with other files # continue with other files
except shutil.Error, err: except shutil.Error as err:
errors.extend(err.args[0]) errors.extend(err.args[0])
except EnvironmentError, why: except EnvironmentError as why:
errors.append((srcname, dstname, str(why))) errors.append((srcname, dstname, str(why)))
try: try:
shutil.copystat(src, dst) shutil.copystat(src, dst)
except OSError, why: except OSError as why:
errors.extend((src, dst, str(why))) errors.extend((src, dst, str(why)))
if errors: if errors:
raise shutil.Error, errors raise shutil.Error(errors)
try: try:
copytree(sys.argv[1], sys.argv[2]) copytree(sys.argv[1], sys.argv[2])

View File

@ -133,7 +133,7 @@ class Report:
def main(): def main():
try: try:
opts, args = getopt.getopt(sys.argv[1:], "dh", ["help"]) opts, args = getopt.getopt(sys.argv[1:], "dh", ["help"])
except getopt.GetoptError, err: except getopt.GetoptError as err:
print('%s' % str(err)) print('%s' % str(err))
usage() usage()
sys.exit(2) sys.exit(2)