From 25dee38f0ba4abb9a4c27330bfa4032cdc136965 Mon Sep 17 00:00:00 2001 From: Eric Barrett Date: Wed, 5 Jun 2019 12:11:18 -0400 Subject: [PATCH] Enable Python3 Compatibility Flake8 currently ignores the following errors: H237: module is removed in python3 H238: old style class declaration Enable them for python2/3 compatibility Change-Id: I4dd66c8ab388119b4abab83fda48a89e108f7821 Story: 2004515 Task: 29303 Signed-off-by: Eric Barrett --- .../cgcs-patch/cgcs_make_patch/make_patch_functions.py | 8 ++++---- cgcs-patch/cgcs-patch/cgcs_patch/base.py | 2 +- cgcs-patch/cgcs-patch/cgcs_patch/patch_functions.py | 8 ++++---- .../cgcs-patch/cgcs_patch_id/patch_id_allocator.py | 10 +++++----- .../cgcs_patch_id/patch_id_allocator_server.py | 2 +- .../patch-alarm/patch_alarm/patch_alarm_manager.py | 2 +- tox.ini | 4 +--- 7 files changed, 17 insertions(+), 19 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 33c95e28..7f99f4a9 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 @@ -191,7 +191,7 @@ class PatchRecipeCmdFail(PatchRecipeError): pass -class PatchList: +class PatchList(object): """ Patch List """ @@ -571,7 +571,7 @@ class PatchList: print("All patches built.") -class PackageData: +class PackageData(object): """ Package data """ @@ -792,7 +792,7 @@ class PackageData: sys.exit(2) -class RecipeData: +class RecipeData(object): """ Recipe data """ @@ -912,7 +912,7 @@ class RecipeData: return self.prebuilt -class PatchRecipeData: +class PatchRecipeData(object): """ Patch recipe data """ diff --git a/cgcs-patch/cgcs-patch/cgcs_patch/base.py b/cgcs-patch/cgcs-patch/cgcs_patch/base.py index 105d3e99..8e479053 100644 --- a/cgcs-patch/cgcs-patch/cgcs_patch/base.py +++ b/cgcs-patch/cgcs-patch/cgcs_patch/base.py @@ -16,7 +16,7 @@ import cgcs_patch.constants as constants from cgcs_patch.patch_functions import LOG -class PatchService: +class PatchService(object): def __init__(self): self.sock_out = None self.sock_in = None diff --git a/cgcs-patch/cgcs-patch/cgcs_patch/patch_functions.py b/cgcs-patch/cgcs-patch/cgcs_patch/patch_functions.py index 79037c3c..4ac6d804 100644 --- a/cgcs-patch/cgcs-patch/cgcs_patch/patch_functions.py +++ b/cgcs-patch/cgcs-patch/cgcs_patch/patch_functions.py @@ -210,7 +210,7 @@ class PackageVersion(object): return "%s%s-%s-%s.%s.rpm" % (prefix, pkgname, self.version, self.release, arch) -class BasePackageData: +class BasePackageData(object): """ Information about the base package data provided by the load """ @@ -265,7 +265,7 @@ class BasePackageData: return self.pkgs[sw_rel][pkgname][arch] -class PatchData: +class PatchData(object): """ Aggregated patch data """ @@ -623,7 +623,7 @@ class PatchData: return value -class PatchMetadata: +class PatchMetadata(object): """ Creating metadata for a single patch """ @@ -713,7 +713,7 @@ class PatchMetadata: write_xml_file(top, fname) -class PatchFile: +class PatchFile(object): """ Patch file """ diff --git a/cgcs-patch/cgcs-patch/cgcs_patch_id/patch_id_allocator.py b/cgcs-patch/cgcs-patch/cgcs_patch_id/patch_id_allocator.py index b4e56dd1..d553472f 100755 --- a/cgcs-patch/cgcs-patch/cgcs_patch_id/patch_id_allocator.py +++ b/cgcs-patch/cgcs-patch/cgcs_patch_id/patch_id_allocator.py @@ -6,7 +6,7 @@ # -import posixfile +import fcntl import string import time @@ -18,14 +18,14 @@ def get_unique_id(filename, digits=4): path = "%s/%s" % (directory, filename) try: # open for update - file = posixfile.open(path, "r+") - file.lock("w|", digits) + file = open(path, "r+") + fcntl.lockf(file, fcntl.LOCK_EX, digits) counter = int(file.read(digits)) + 1 except IOError: # create it try: - file = posixfile.open(path, "w") - file.lock("w|", digits) + file = open(path, "w") + fcntl.lockf(file, fcntl.LOCK_EX, digits) except IOError: print("creation of file '%s' failed" % path) return -1 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 aaadf614..84ae04d8 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 @@ -18,7 +18,7 @@ urls = ( ) -class get_patch_id: +class get_patch_id(object): def GET(self): data = web.input(sw_version=None, prefix="CGCS") output = pida.get_patch_id(data.sw_version, data.prefix) 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 b6ead911..6362950d 100644 --- a/patch-alarm/patch-alarm/patch_alarm/patch_alarm_manager.py +++ b/patch-alarm/patch-alarm/patch_alarm/patch_alarm_manager.py @@ -42,7 +42,7 @@ def start_polling(): ################### # CLASSES ################### -class PatchAlarmDaemon(): +class PatchAlarmDaemon(object): """ Daemon process representation of the patch monitoring program """ diff --git a/tox.ini b/tox.ini index 01d521b1..16b74e43 100644 --- a/tox.ini +++ b/tox.ini @@ -58,8 +58,6 @@ commands = # H101 Use TODO(NAME) # H102 Apache 2.0 license header not found # H105 Don't use author tags -# H237 module posixfile is removed in Python 3 -# H238 old style class declaration # H306 imports not in alphabetical order # H401 docstring should not start with a space # H404 multi line docstring should start without a leading new line @@ -69,7 +67,7 @@ commands = # F401 'XXXXX' imported but unused # F841 local variable 'XXXXXX' is assigned to but never used show-source = True -ignore = H101,H102,H105,H237,H238,H306,H401,H404,H405,E501,F401,F841 +ignore = H101,H102,H105,H306,H401,H404,H405,E501,F401,F841 exclude = .venv,.git,.tox,dist,doc,*lib/python*,*egg,build,release-tag-* # TODO: H106 Don’t put vim configuration in source files (off by default). # H203 Use assertIs(Not)None to check for None (off by default).