Fix pep8/flake8 Error

Fix below errors
    E128 continuation line under-indented for visual indent
    E305 expected 2 blank lines after class or function definition, found 1
    E502 the backslash is redundant between brackets
    E722 do not use bare except'
    E741 ambiguous variable name 'xxxxx'
    E999 SyntaxError: invalid token

Change-Id: Ic826a70aed2cda984cbafedae154c4812bfa37b5
Story: 2003429
Task: 24624
Signed-off-by: Sun Austin <austin.sun@intel.com>
This commit is contained in:
Sun Austin 2018-09-10 16:25:51 +08:00
parent 201b94d89f
commit bae8691911
11 changed files with 35 additions and 47 deletions

View File

@ -103,11 +103,11 @@ def rev_lt(num1, num2):
while True:
try:
n1 = int(n1w.pop(0))
except:
except Exception:
return True
try:
n2 = int(n2w.pop(0))
except:
except Exception:
return False
if n1 < n2:
return True
@ -1170,7 +1170,7 @@ class PatchRecipeData:
write_xml_file(e_top, fname)
def __str__(self):
return "[ patch_id: %s, context: %s, metadata: %s, requires: %s, recipies: %s ]" % (str(self.patch_id), str(self.build_context), str(self.metadata), str(self.requires), str(self.recipies, keys()))
return "[ patch_id: %s, context: %s, metadata: %s, requires: %s, recipies: %s ]" % (str(self.patch_id), str(self.build_context), str(self.metadata), str(self.requires), str(self.recipies.keys()))
def myprint(self, indent=""):
print("patch_id: %s" % str(self.patch_id))
@ -1282,8 +1282,8 @@ class PatchRecipeData:
if prev_patch_id is None:
delim = "_"
words = self.patch_id.split(delim)
l = len(words[-1])
words[-1] = '0' * l
word_lens = len(words[-1])
words[-1] = '0' * word_lens
prev_patch_id = delim.join(words)
prev_release_map = self._read_rpm_db(prev_patch_id)
release_map = self._read_rpm_db(self.patch_id)
@ -1399,9 +1399,9 @@ class PatchRecipeData:
return True
def _tag_build_context():
def _tag_build_context(patch_id):
os.chdir(srcdir)
issue_cmd("for e in . `wrgit all-core-gits` ; do (cd $e ; git tag v%s) done" % self.patch_id)
issue_cmd("for e in . `wrgit all-core-gits` ; do (cd $e ; git tag v%s) done" % patch_id)
def read_build_info():
@ -1426,7 +1426,7 @@ def read_build_info():
if var.startswith('"') and var.endswith('"'):
var = var[1:-1]
build_info[name] = var
except:
except Exception:
return False
return True
@ -1712,7 +1712,7 @@ def modify_patch():
print("press 'Release to Production'")
print("")
except:
except Exception:
print("Failed to modify patch!")
finally:
shutil.rmtree(workdir)
@ -1798,7 +1798,7 @@ def query_patch():
answer = PatchFile.query_patch(patch_path, field=field)
print(str(answer))
except:
except Exception:
print("Failed to query patch!")
finally:
shutil.rmtree(workdir)

View File

@ -132,7 +132,7 @@ class PatchService:
sock_in = self.setup_socket_ipv4()
self.socket_lock_release()
return sock_in
except:
except Exception:
LOG.exception("Failed to setup socket")
# Close sockets, if necessary

View File

@ -12,7 +12,7 @@ try:
INITIAL_CONFIG_COMPLETE_FLAG = os.path.join(
tsc.PLATFORM_CONF_PATH, ".initial_config_complete")
except:
except Exception:
pass
PATCH_AGENT_STATE_IDLE = "idle"

View File

@ -64,7 +64,7 @@ def setflag(fname):
try:
with open(fname, "w") as f:
f.write("%d\n" % os.getpid())
except:
except Exception:
LOG.exception("Failed to update %s flag" % fname)
@ -72,7 +72,7 @@ def clearflag(fname):
if os.path.exists(fname):
try:
os.remove(fname)
except:
except Exception:
LOG.exception("Failed to clear %s flag" % fname)
@ -753,9 +753,9 @@ class PatchAgent(PatchService):
shutil.rmtree(insvc_patch_scripts, ignore_errors=True)
if os.path.exists(insvc_patch_flags):
shutil.rmtree(insvc_patch_flags, ignore_errors=True)
os.mkdir(insvc_patch_scripts, 0700)
os.mkdir(insvc_patch_flags, 0700)
except:
os.mkdir(insvc_patch_scripts, 0o700)
os.mkdir(insvc_patch_flags, 0o700)
except Exception:
LOG.exception("Failed to create in-service patch directories")
# Send a hello to provide a state update

View File

@ -74,7 +74,7 @@ def set_term_width():
width = int(output)
if width > 60:
TERM_WIDTH = width - 4
except:
except Exception:
pass

View File

@ -588,7 +588,7 @@ class PatchController(PatchService):
def socket_lock_release(self):
try:
self.socket_lock.release()
except:
except Exception:
pass
def write_state_file(self):
@ -1960,7 +1960,7 @@ class PatchController(PatchService):
# Translated successfully, but IP isn't in the table.
# Raise an exception to drop out to the failure handling
raise PatchError("Host IP (%s) not in table" % ip)
except:
except Exception:
self.hosts_lock.release()
msg = "Unknown host specified: %s" % host_ip
msg_error += msg + "\n"
@ -2063,7 +2063,7 @@ class PatchController(PatchService):
# Translated successfully, but IP isn't in the table.
# Raise an exception to drop out to the failure handling
raise PatchError("Host IP (%s) not in table" % ip)
except:
except Exception:
self.hosts_lock.release()
msg = "Unknown host specified: %s" % host_ip
msg_error += msg + "\n"
@ -2167,7 +2167,7 @@ class PatchControllerApiThread(threading.Thread):
global keep_running
while keep_running:
self.wsgi.handle_request()
except:
except Exception:
# Log all exceptions
LOG.exception("Error occurred during request processing")
@ -2218,7 +2218,7 @@ class PatchControllerAuthApiThread(threading.Thread):
global keep_running
while keep_running:
self.wsgi.handle_request()
except:
except Exception:
# Log all exceptions
LOG.exception("Authorized API failure: Error occurred during request processing")
@ -2384,7 +2384,7 @@ class PatchControllerMainThread(threading.Thread):
query = PatchMessageQueryDetailed()
query.send(agent_sock)
agent_query_conns.append(agent_sock)
except:
except Exception:
# Put it back on the list
stale_hosts.append(ip)
@ -2425,7 +2425,7 @@ class PatchControllerMainThread(threading.Thread):
pc.interim_state[patch_id].remove(n)
pc.hosts_lock.release()
except:
except Exception:
# Log all exceptions
LOG.exception("Error occurred during request processing")
thread_death.set()

View File

@ -30,7 +30,7 @@ import rpm
try:
# The tsconfig module is only available at runtime
from tsconfig.tsconfig import SW_VERSION
except:
except Exception:
SW_VERSION = "unknown"
# Constants
@ -1188,8 +1188,8 @@ def patch_build():
'storage=',
'all-nodes='])
except getopt.GetoptError:
print("Usage: %s [ <args> ] ... <rpm list>" \
% os.path.basename(sys.argv[0]))
print("Usage: %s [ <args> ] ... <rpm list>"
% os.path.basename(sys.argv[0]))
print("Options:")
print("\t--id <id> Patch ID")
print("\t--release <version> Platform release version")

View File

@ -23,7 +23,7 @@ def gethostbyname(hostname):
""" gethostbyname with IPv6 support """
try:
return socket.getaddrinfo(hostname, None)[0][4][0]
except:
except Exception:
return None
@ -61,7 +61,7 @@ def ip_to_url(ip_address_string):
return "[%s]" % ip_address_string
else:
return ip_address_string
except:
except Exception:
return ip_address_string

View File

@ -40,5 +40,6 @@ def main():
app = MyApplication(urls, globals())
app.run(port=port)
if __name__ == "__main__":
main()

View File

@ -80,7 +80,7 @@ class PatchAlarmDaemon():
try:
req = requests.get(url)
except:
except Exception:
return
entity_instance_id = "%s=%s" % (fm_constants.FM_ENTITY_TYPE_HOST, "controller")
@ -171,7 +171,7 @@ class PatchAlarmDaemon():
try:
req = requests.get(url)
except:
except Exception:
return
entity_instance_id = "%s=%s" % (fm_constants.FM_ENTITY_TYPE_HOST, "controller")

17
tox.ini
View File

@ -49,27 +49,14 @@ commands =
-name \*.sh \
-print0 | xargs --no-run-if-empty -0 bashate -v -e 'E*' -iE006"
[pep8]
# Ignoring these warnings
# E501 line too long
ignore = E501
[flake8]
# ingore below errors , will fix flake8 errors in future
# E123, E125 skipped as they are invalid PEP-8.
# E128 continuation line under-indented for visual indent
# E305 expected 2 blank lines after class or function definition, found 1
# ignore below errors , will fix flake8 errors in future
# E501 skipped because some of the code files include templates
# that end up quite wide
# E502 the backslash is redundant between brackets
# E722 do not use bare except'
# E741 ambiguous variable name 'l'
# E999 SyntaxError: invalid token
# F401 'XXXXX' imported but unused
# F821 undefined name 'XXXX'
# F841 local variable 'XXXXXX' is assigned to but never used
show-source = True
ignore = E123,E125,E128,E305,E501,E502,E722,E741,E999,F401,F821,F841
ignore = E501,F401,F841
exclude = .venv,.git,.tox,dist,doc,*lib/python*,*egg,build,release-tag-*
# Use flake8 to replace pep8.