Fix: "except" issue for Python 2/3 compatible code

change 'except error,e' to 'exept error as e'

Story: 2003433
Task:28374

Change-Id: Ic14fc3cdad4199560eec19b2598b9c750117a2a1
Signed-off-by: Sun Austin <austin.sun@intel.com>
This commit is contained in:
Sun Austin
2018-12-11 14:06:09 +08:00
parent eeff51a8bb
commit 92f3f4a823
6 changed files with 7 additions and 8 deletions

View File

@@ -521,7 +521,7 @@ def remove_from_archive(archive, unwanted):
subprocess.check_call(["tar", "--delete",
"--file=" + archive,
unwanted])
except subprocess.CalledProcessError, e:
except subprocess.CalledProcessError as e:
LOG.error("Delete of {} failed: {}".format(unwanted, e.output))
raise CloneFail("Failed to modify backup archive")

View File

@@ -61,7 +61,7 @@ def directory_get_size(start_dir, regex=None):
filep = os.path.join(dirpath, filename)
try:
total_size += os.path.getsize(filep)
except OSError, e:
except OSError as e:
if e.errno != errno.ENOENT:
raise e
return total_size

View File

@@ -39,7 +39,6 @@ commands = flake8 {posargs}
# H101: Use TODO(NAME)
# H102: Apache 2.0 license header not found
# H104: File contains nothing but comments
# H231: Python 3.x incompatible 'except x,y:' construct
# H232: Python 3.x incompatible octal 400 should be written as 0o400
# H238: old style class declaration, use new style (inherit from `object`)
# H301: one import per line
@@ -48,7 +47,7 @@ commands = flake8 {posargs}
# H403: multi line docstrings should end on a new line
# H404: multi line docstring should start without a leading new line
# H405: multi line docstring summary not separated with an empty line
ignore = H101,H102,H104,H231,H232,H238,H301,H306,H401,H403,H404,H405,
ignore = H101,H102,H104,H232,H238,H301,H306,H401,H403,H404,H405,
W503
[testenv:py27]

View File

@@ -787,7 +787,7 @@ def notify_mtc_and_recv(mtc_address, mtc_port, idict):
LOG.exception("Mtc Response Error: %s" % mtc_response)
pass
except socket.error, e:
except socket.error as e:
LOG.exception(_("Socket Error: %s on %s:%s for %s") % (e,
mtc_address, mtc_port, serialized_idict))
# if e not in [errno.EWOULDBLOCK, errno.EINTR]:
@@ -815,7 +815,7 @@ def symlink_force(source, link_name):
"""
try:
os.symlink(source, link_name)
except OSError, e:
except OSError as e:
if e.errno == errno.EEXIST:
os.remove(link_name)
os.symlink(source, link_name)

View File

@@ -203,7 +203,7 @@ def trycmd(*args, **kwargs):
try:
out, err = execute(*args, **kwargs)
failed = False
except ProcessExecutionError, exn:
except ProcessExecutionError as exn:
out, err = '', str(exn)
failed = True

View File

@@ -66,7 +66,7 @@ commands =
# H501: Do not use self.__dict__ for string formatting
[flake8]
ignore = E126,E127,E128,E402,E501,
H101,H102,H104,H105,H231,H232,H234,H235,H236,H237,H238,
H101,H102,H104,H105,H232,H234,H235,H236,H237,H238,
H301,H306,H401,H403,H404,H405,H501
builtins = _