From bae8691911a8c58df160b5179c7603f5ae980b52 Mon Sep 17 00:00:00 2001 From: Sun Austin Date: Mon, 10 Sep 2018 16:25:51 +0800 Subject: [PATCH] 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 --- .../cgcs_make_patch/make_patch_functions.py | 20 +++++++++---------- cgcs-patch/cgcs-patch/cgcs_patch/base.py | 2 +- cgcs-patch/cgcs-patch/cgcs_patch/constants.py | 2 +- .../cgcs-patch/cgcs_patch/patch_agent.py | 10 +++++----- .../cgcs-patch/cgcs_patch/patch_client.py | 2 +- .../cgcs-patch/cgcs_patch/patch_controller.py | 14 ++++++------- .../cgcs-patch/cgcs_patch/patch_functions.py | 6 +++--- cgcs-patch/cgcs-patch/cgcs_patch/utils.py | 4 ++-- .../patch_id_allocator_server.py | 1 + .../patch_alarm/patch_alarm_manager.py | 4 ++-- tox.ini | 17 ++-------------- 11 files changed, 35 insertions(+), 47 deletions(-) diff --git a/cgcs-patch/cgcs-patch/cgcs_make_patch/make_patch_functions.py b/cgcs-patch/cgcs-patch/cgcs_make_patch/make_patch_functions.py index 8837d156..33c95e28 100644 --- a/cgcs-patch/cgcs-patch/cgcs_make_patch/make_patch_functions.py +++ b/cgcs-patch/cgcs-patch/cgcs_make_patch/make_patch_functions.py @@ -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) diff --git a/cgcs-patch/cgcs-patch/cgcs_patch/base.py b/cgcs-patch/cgcs-patch/cgcs_patch/base.py index 8379c620..6f2fbb7d 100644 --- a/cgcs-patch/cgcs-patch/cgcs_patch/base.py +++ b/cgcs-patch/cgcs-patch/cgcs_patch/base.py @@ -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 diff --git a/cgcs-patch/cgcs-patch/cgcs_patch/constants.py b/cgcs-patch/cgcs-patch/cgcs_patch/constants.py index ad699d04..8060d9a1 100644 --- a/cgcs-patch/cgcs-patch/cgcs_patch/constants.py +++ b/cgcs-patch/cgcs-patch/cgcs_patch/constants.py @@ -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" diff --git a/cgcs-patch/cgcs-patch/cgcs_patch/patch_agent.py b/cgcs-patch/cgcs-patch/cgcs_patch/patch_agent.py index c3d63fb8..f45af7c9 100644 --- a/cgcs-patch/cgcs-patch/cgcs_patch/patch_agent.py +++ b/cgcs-patch/cgcs-patch/cgcs_patch/patch_agent.py @@ -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 diff --git a/cgcs-patch/cgcs-patch/cgcs_patch/patch_client.py b/cgcs-patch/cgcs-patch/cgcs_patch/patch_client.py index ce44e15f..82599481 100644 --- a/cgcs-patch/cgcs-patch/cgcs_patch/patch_client.py +++ b/cgcs-patch/cgcs-patch/cgcs_patch/patch_client.py @@ -74,7 +74,7 @@ def set_term_width(): width = int(output) if width > 60: TERM_WIDTH = width - 4 - except: + except Exception: pass diff --git a/cgcs-patch/cgcs-patch/cgcs_patch/patch_controller.py b/cgcs-patch/cgcs-patch/cgcs_patch/patch_controller.py index 60a75d17..e96b87e1 100644 --- a/cgcs-patch/cgcs-patch/cgcs_patch/patch_controller.py +++ b/cgcs-patch/cgcs-patch/cgcs_patch/patch_controller.py @@ -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() diff --git a/cgcs-patch/cgcs-patch/cgcs_patch/patch_functions.py b/cgcs-patch/cgcs-patch/cgcs_patch/patch_functions.py index c027f1cb..b603e7b1 100644 --- a/cgcs-patch/cgcs-patch/cgcs_patch/patch_functions.py +++ b/cgcs-patch/cgcs-patch/cgcs_patch/patch_functions.py @@ -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 [ ] ... " \ - % os.path.basename(sys.argv[0])) + print("Usage: %s [ ] ... " + % os.path.basename(sys.argv[0])) print("Options:") print("\t--id Patch ID") print("\t--release Platform release version") diff --git a/cgcs-patch/cgcs-patch/cgcs_patch/utils.py b/cgcs-patch/cgcs-patch/cgcs_patch/utils.py index 0b2d73ff..e68cf64d 100644 --- a/cgcs-patch/cgcs-patch/cgcs_patch/utils.py +++ b/cgcs-patch/cgcs-patch/cgcs_patch/utils.py @@ -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 diff --git a/cgcs-patch/cgcs-patch/cgcs_patch_id/patch_id_allocator_server.py b/cgcs-patch/cgcs-patch/cgcs_patch_id/patch_id_allocator_server.py index a10b53ab..aaadf614 100755 --- a/cgcs-patch/cgcs-patch/cgcs_patch_id/patch_id_allocator_server.py +++ b/cgcs-patch/cgcs-patch/cgcs_patch_id/patch_id_allocator_server.py @@ -40,5 +40,6 @@ def main(): app = MyApplication(urls, globals()) app.run(port=port) + if __name__ == "__main__": main() diff --git a/patch-alarm/patch-alarm/patch_alarm/patch_alarm_manager.py b/patch-alarm/patch-alarm/patch_alarm/patch_alarm_manager.py index fc0dba89..b6ead911 100644 --- a/patch-alarm/patch-alarm/patch_alarm/patch_alarm_manager.py +++ b/patch-alarm/patch-alarm/patch_alarm/patch_alarm_manager.py @@ -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") diff --git a/tox.ini b/tox.ini index b2de07f7..2316da28 100644 --- a/tox.ini +++ b/tox.ini @@ -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.