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 4235ff17..8837d156 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 @@ -220,7 +220,7 @@ class PatchList: return "[ data_path: %s, order_file: %s, patches_built: %s, patches_to_build: %s, xml_to_patch: %s, patch_to_xml: %s ]" % (str(self.data_path), str(self.order_file), str(self.patches_built), str(self.patches_to_build), str(self.xml_to_patch), str(self.patch_to_xml)) def myprint(self, indent=""): - print "%s%s" % (indent, str(self)) + print("%s%s" % (indent, str(self))) def _std_xml_patch_recipe_name(self, patch_id): xml_name = "%s.xml" % patch_id @@ -267,25 +267,25 @@ class PatchList: remote_patch = remote_order.pop(0) local_patch = local_order.pop(0) if remote_patch == local_patch: - print "_validate_patch_order: %s ok" % local_patch + print("_validate_patch_order: %s ok" % local_patch) validated_order.append(remote_patch) else: fix_local_order = True - print "_validate_patch_order: %s vs %s fail" % (local_patch, remote_patch) + print("_validate_patch_order: %s vs %s fail" % (local_patch, remote_patch)) local_order.insert(0, local_patch) break if fix_local_order: - print "_validate_patch_order: fix patch order" + print("_validate_patch_order: fix patch order") f = open(self._std_local_path(self.order_file), 'w') for patch_id in validated_order: f.write("%s\n" % patch_id) - print "_validate_patch_order: %s" % patch_id + print("_validate_patch_order: %s" % patch_id) f.close() # remove remaining local patches for patch_id in local_order: xml_path = self._std_local_path(self._std_xml_patch_recipe_name(patch_id)) - print "_validate_patch_order: rm %s" % xml_path + print("_validate_patch_order: rm %s" % xml_path) os.remove(xml_path) def _obtain_official_patches(self): @@ -329,7 +329,7 @@ class PatchList: with open(self._std_patch_git_path(self.order_file)) as f: for line in f: patch_id = line.strip() - print "remote patch_id = '%s'" % patch_id + print("remote patch_id = '%s'" % patch_id) xml_path = self._std_patch_git_path(self._std_xml_patch_recipe_name(patch_id)) self.add(xml_path, built=False, fix=True) @@ -337,12 +337,12 @@ class PatchList: for patch_id in self.patches_to_deliver: os.chdir(workdir) patch = "%s.patch" % patch_id - print "signing patch '%s'" % self._std_local_path(patch) + print("signing patch '%s'" % self._std_local_path(patch)) try: subprocess.check_call(["sign_patch_formal.sh", self._std_local_path(patch)]) except subprocess.CalledProcessError as e: - print "Failed to to sign official patch. Call to sign_patch_formal.sh process returned non-zero exit status %i" % e.returncode + print("Failed to to sign official patch. Call to sign_patch_formal.sh process returned non-zero exit status %i" % e.returncode) raise SystemExit(e.returncode) def deliver_official_patch(self): @@ -362,7 +362,7 @@ class PatchList: if answer is not None and "status" in answer: if answer["status"] == "REL": prevent_overwrite = True - print "Warning: '%s' already exists in git repo and is in released state! Cowardly refusing to overwrite it." % patch + print("Warning: '%s' already exists in git repo and is in released state! Cowardly refusing to overwrite it." % patch) if not prevent_overwrite: issue_cmd("cp %s %s" % (self._std_local_path(patch), self._std_patch_git_path("."))) @@ -383,61 +383,61 @@ class PatchList: with open(self._std_local_path(self.order_file)) as f: for line in f: patch_id = line.strip() - print "local patch_id = '%s'" % patch_id + print("local patch_id = '%s'" % patch_id) xml_path = self._std_local_path(self._std_xml_patch_recipe_name(patch_id)) self.add(xml_path, built=True, fix=False) def get_implicit_requires(self, patch_id, recipies): list = [] for r in recipies: - print "get_implicit_requires r=%s" % r + print("get_implicit_requires r=%s" % r) for patch in self.patches_built: if patch == patch_id: continue if self.patch_data[patch].has_common_recipies(recipies): - print "get_implicit_requires built patch '%s' provides one of %s" % (patch, str(recipies)) + print("get_implicit_requires built patch '%s' provides one of %s" % (patch, str(recipies))) list.append(patch) for patch in self.patches_to_build: if patch == patch_id: continue if self.patch_data[patch].has_common_recipies(recipies): - print "get_implicit_requires unbuilt patch '%s' provides one of %s" % (patch, str(recipies)) + print("get_implicit_requires unbuilt patch '%s' provides one of %s" % (patch, str(recipies))) list.append(patch) return list def is_built(self, patch): if patch not in self.patches_built: - print "Queried patch '%s' is not built" % patch + print("Queried patch '%s' is not built" % patch) return False return True def is_known(self, patch): if patch not in self.patches_built: if patch not in self.patches_to_build: - print "Queried patch '%s' is not known" % patch + print("Queried patch '%s' is not known" % patch) return False return True def add(self, patch_xml, built=False, fix=False, rebuild=False, require_context=True): - print "processing patch_xml %s, built=%s, fix=%s, rebuild=%s, require_context=%s" % (patch_xml, str(built), str(fix), str(rebuild), str(require_context)) + print("processing patch_xml %s, built=%s, fix=%s, rebuild=%s, require_context=%s" % (patch_xml, str(built), str(fix), str(rebuild), str(require_context))) prd = PatchRecipeData(built, self) prd.parse_xml(patch_xml) if prd.patch_id is None: msg = "Invalid patch '%s' patch_xml contains no patch_id" % patch_xml LOG.exception(msg) - print msg + print(msg) raise PatchRecipeXMLFail(msg) sys.exit(2) if len(prd.recipies) <= 0: msg = "Invalid patch '%s' contains no recipies" % prd.patch_id LOG.exception(msg) - print msg + print(msg) raise PatchRecipeXMLFail(msg) sys.exit(2) if require_context and prd.build_context is None: msg = "Invalid patch '%s' contains no context" % prd.patch_id LOG.exception(msg) - print msg + print(msg) raise PatchRecipeXMLFail(msg) sys.exit(2) if not rebuild: @@ -445,19 +445,19 @@ class PatchList: if self.patch_to_xml[prd.patch_id] == patch_xml: msg = "Previously added patch '%s' from same xml '%s'" % (prd.patch_id, patch_xml) LOG.warn(msg) - print "%s\n" % msg + print("%s\n" % msg) return rc = issue_cmd_rc("diff %s %s" % (self.patch_to_xml[prd.patch_id], patch_xml)) if rc != 0: msg = "Previously added patch '%s' from different xml '%s' and different content" % (prd.patch_id, patch_xml) LOG.exception(msg) - print "%s\n" % msg + print("%s\n" % msg) raise PatchRecipeXMLFail(msg) sys.exit(2) else: msg = "Previously added patch '%s' from different xml '%s' but same content" % (prd.patch_id, patch_xml) LOG.warn(msg) - print "%s\n" % msg + print("%s\n" % msg) return if prd.patch_id in self.patch_data.keys(): if not rebuild: @@ -466,7 +466,7 @@ class PatchList: if (fix and (rc2 > MAJOR_DIFF)) or (not fix and (rc2 > MINOR_DIFF)): msg = "Patch '%s' added twice with differing content" LOG.exception(msg) - print msg + print(msg) raise PatchRequirementFail(msg) sys.exit(2) if fix and (rc2 > MINOR_DIFF): @@ -478,7 +478,7 @@ class PatchList: if rc2 > MINOR_DIFF: msg = "Failed to resolve patch difference by status update for patch '%s'" % prd.patch_id LOG.exception(msg) - print msg + print(msg) raise PatchRequirementFail(msg) sys.exit(2) # TODO write revised xml to local/remote ? @@ -496,14 +496,14 @@ class PatchList: if not rc: msg = "Can't proceed because patch %s has requirements on an unknown patch." % prd.patch_id LOG.exception(msg) - print msg + print(msg) raise PatchRequirementFail(msg) sys.exit(2) rc = prd.check_requires_built(self) if built and not rc: msg = "Patch %s claims to be built yet it requires a patch that is unbuilt." LOG.exception(msg) - print msg + print(msg) raise PatchRequirementFail(msg) sys.exit(2) @@ -511,7 +511,7 @@ class PatchList: if not rc: msg = "Can't proceed because patch %s has requirements on a patch that lacks a build context." % prd.patch_id LOG.exception(msg) - print msg + print(msg) raise PatchRequirementFail(msg) sys.exit(2) @@ -531,16 +531,16 @@ class PatchList: for patch_id in self.patches_to_build: prd = self.patch_data[patch_id] rc = prd.check_requires_built(self) - print "check_requires_built(%s) -> %s" % (patch_id, str(rc)) + print("check_requires_built(%s) -> %s" % (patch_id, str(rc))) if rc: # This patch is ready to build, build it now - print "Ready to build patch %s." % patch_id + print("Ready to build patch %s." % patch_id) rc = prd.build_patch() if rc: # append new built patch to order file issue_cmd("sed -i '/^%s$/d' %s" % (patch_id, self._std_local_path(self.order_file))) issue_cmd("echo %s >> %s" % (patch_id, self._std_local_path(self.order_file))) - print "Built patch %s." % patch_id + print("Built patch %s." % patch_id) self.patches_built.append(patch_id) self.patches_to_deliver.append(patch_id) self.patches_to_build.remove(patch_id) @@ -559,16 +559,16 @@ class PatchList: else: msg = "Failed to build patch %s" % patch_id LOG.exception(msg) - print msg + print(msg) raise PatchBuildFail(msg) sys.exit(2) if built == 0: msg = "No patches are buildable, Remaining patches: %s" % str(self.patches_to_build) LOG.exception(msg) - print msg + print(msg) raise PatchBuildFail(msg) sys.exit(2) - print "All patches built." + print("All patches built.") class PackageData: @@ -585,7 +585,7 @@ class PackageData: return "[ name: %s, personalities: %s, architectures: %s ]" % (str(self.name), str(self.personalities), str(self.architectures)) def myprint(self, indent=""): - print "%s%s" % (indent, str(self)) + print("%s%s" % (indent, str(self))) def compare(self, package): rc = SAME @@ -612,7 +612,7 @@ class PackageData: else: msg = "Unknow attribute '%s' in " % key LOG.exception(msg) - print msg + print(msg) raise PatchRecipeXMLFail(msg) sys.exit(2) @@ -623,7 +623,7 @@ class PackageData: if txt is None: msg = "personality missing under " LOG.exception(msg) - print msg + print(msg) raise PatchRecipeXMLFail(msg) sys.exit(2) self.personalities.append(txt) @@ -632,14 +632,14 @@ class PackageData: if txt is None: msg = "personality missing under " LOG.exception(msg) - print msg + print(msg) raise PatchRecipeXMLFail(msg) sys.exit(2) self.architectures.append(txt) else: msg = "Unknow tag '%s' under " % child.tag LOG.exception(msg) - print msg + print(msg) raise PatchRecipeXMLFail(msg) sys.exit(2) @@ -658,36 +658,36 @@ class PackageData: rpm_dir = "%s/%s/repo/cgcs-centos-repo/Data" % (workdir, build_type) else: rpm_dir = "%s/%s/%s" % (workdir, build_type, RPM_DIR) - print "================= rpm_dir=%s ============" % rpm_dir + print("================= rpm_dir=%s ============" % rpm_dir) return rpm_dir def _clean_rpms(self, prebuilt=False): global BUILD_TYPES - print "cleaning self.name %s\n" % self.name + print("cleaning self.name %s\n" % self.name) for build_type in BUILD_TYPES: for arch in self.architectures: rpm_dir = self._get_rpm_dir(build_type=build_type, arch=arch, prebuilt=prebuilt) rpm_search_pattern = "%s-*%s.rpm" % (self.name, arch) - print "cleaning arch %s\n" % arch - print "cleaning dir %s\n" % rpm_dir - print "cleaning rpm_search_pattern %s\n" % rpm_search_pattern + print("cleaning arch %s\n" % arch) + print("cleaning dir %s\n" % rpm_dir) + print("cleaning rpm_search_pattern %s\n" % rpm_search_pattern) for file in os.listdir(rpm_dir): if fnmatch.fnmatch(file, rpm_search_pattern): file_path = "%s/%s" % (rpm_dir, file) if os.path.isfile(file_path): - print "cleaning match %s\n" % file + print("cleaning match %s\n" % file) rpm_name_cmd = ["rpm", "-qp", "--dbpath", temp_rpm_db_dir, "--queryformat", "%{NAME}", "%s" % file_path] rpm_name = issue_cmd_w_stdout(rpm_name_cmd) if rpm_name == self.name: rpm_release_cmd = ["rpm", "-qp", "--dbpath", temp_rpm_db_dir, "--queryformat", "%{RELEASE}", "%s" % file_path] rpm_release = issue_cmd_w_stdout(rpm_release_cmd) - print "cleaning release %s" % rpm_release + print("cleaning release %s" % rpm_release) rm_cmd = "rm -f %s/%s-*-%s.%s.rpm" % (rpm_dir, self.name, rpm_release, arch) issue_cmd(rm_cmd) def clean(self, prebuilt=False): - print "package clean" + print("package clean") self._clean_rpms(prebuilt=prebuilt) def _add_rpms(self, pf, arch=ARCH_DEFAULT, fatal=True, prebuilt=False): @@ -720,7 +720,7 @@ class PackageData: else: exclude_search_pattern = "*%s*" % (exclude) if fnmatch.fnmatch(file, exclude_search_pattern): - print "reject file '%s' due to pattern '%s' -> '%s'" % (file, exclude, exclude_search_pattern) + print("reject file '%s' due to pattern '%s' -> '%s'" % (file, exclude, exclude_search_pattern)) reject = True break if reject: @@ -733,7 +733,7 @@ class PackageData: continue include_search_pattern = "%s-[0-9]*.rpm" % (line) if fnmatch.fnmatch(file, include_search_pattern): - print "Including file '%s' due to match in IMAGE_INC_FILE '%s'" % (file, SRCDIR_IMAGE_INC_FILE) + print("Including file '%s' due to match in IMAGE_INC_FILE '%s'" % (file, SRCDIR_IMAGE_INC_FILE)) reject = False break @@ -748,30 +748,30 @@ class PackageData: rpm_name_cmd = ["rpm", "-qp", "--dbpath", temp_rpm_db_dir, "--queryformat", "%{NAME}", "%s/%s" % (rpm_dir, file)] rpm_name = issue_cmd_w_stdout(rpm_name_cmd) if rpm_name != self.name: - print "reject file '%s' due to rpm_name '%s'" % (file, rpm_name) + print("reject file '%s' due to rpm_name '%s'" % (file, rpm_name)) reject = True if reject: # proceed to next matching file continue - print "accept file '%s'" % file + print("accept file '%s'" % file) rpm_path = "%s/%s" % (rpm_dir, file) if len(self.personalities) > 0: - print "pf.add_rpm(%s, personality=%s)" % (rpm_path, str(self.personalities)) + print("pf.add_rpm(%s, personality=%s)" % (rpm_path, str(self.personalities))) pf.add_rpm(rpm_path, personality=self.personalities) added += 1 else: - print "pf.add_rpm(%s)" % (rpm_path) + print("pf.add_rpm(%s)" % (rpm_path)) pf.add_rpm(rpm_path) added += 1 if added == 0: if fatal: msg = "No rpms found matching %s/%s" % (rpm_dir, rpm_search_pattern) LOG.exception(msg) - print msg + print(msg) raise PatchPackagingFail(msg) sys.exit(2) msg = "No rpms found matching %s/%s" % (rpm_dir, rpm_search_pattern) - print msg + print(msg) raise PatchPackagingMiss(msg) def build_patch(self, pf, fatal=True, prebuilt=False): @@ -787,7 +787,7 @@ class PackageData: if not rev_lt(prev_release_map[self.name], release_map[self.name]): msg = "Failed to upversion rpm %s in recipe %s: old release %s, new release %s" % (self.name, recipe_name, prev_release_map[self.name], release_map[self.name]) LOG.exception(msg) - print msg + print(msg) raise PatchPackagingFail(msg) sys.exit(2) @@ -806,7 +806,7 @@ class RecipeData: return "name: %s, packages: %s" % (self.name, str(self.packages.keys())) def myprint(self, indent=""): - print "%sname: %s" % (indent, self.name) + print("%sname: %s" % (indent, self.name)) for key in self.packages: self.packages[key].myprint("%s " % indent) @@ -843,7 +843,7 @@ class RecipeData: else: msg = "Unknow attribute '%s' in " % key LOG.exception(msg) - print msg + print(msg) raise PatchRecipeXMLFail(msg) sys.exit(2) @@ -854,11 +854,11 @@ class RecipeData: self.packages[p.name] = p elif child.tag == "PREBUILT": self.prebuilt = True - print "=========== set prebuilt=%s for %s =============" % (self.prebuilt, self.name) + print("=========== set prebuilt=%s for %s =============" % (self.prebuilt, self.name)) else: msg = "Unknow tag '%s' under " % child.tag LOG.exception(msg) - print msg + print(msg) raise PatchRecipeXMLFail(msg) sys.exit(2) @@ -871,7 +871,7 @@ class RecipeData: self.packages[package].gen_xml(e_package) def clean(self): - print "recipe clean" + print("recipe clean") if not self.prebuilt: for package in self.packages: self.packages[package].clean(prebuilt=self.prebuilt) @@ -908,7 +908,7 @@ class RecipeData: self.packages[package].check_release(self.name, release_map, prev_release_map) def is_prebuilt(self): - print "=========== is_prebuilt prebuilt=%s for %s =============" % (self.prebuilt, self.name) + print("=========== is_prebuilt prebuilt=%s for %s =============" % (self.prebuilt, self.name)) return self.prebuilt @@ -970,11 +970,11 @@ class PatchRecipeData: rc = True for patch in self.requires: if not patch_list.is_known(patch): - print "patch '%s' is missing required patch '%s'" % (self.patch_id, patch) + print("patch '%s' is missing required patch '%s'" % (self.patch_id, patch)) rc = False for patch in self.auto_requires: if not patch_list.is_known(patch): - print "patch '%s' is missing implicitly required patch '%s'" % (self.patch_id, patch) + print("patch '%s' is missing implicitly required patch '%s'" % (self.patch_id, patch)) rc = False return rc @@ -984,13 +984,13 @@ class PatchRecipeData: if not patch_list.is_built(patch): ctx = patch_list.patch_data[patch].get_build_context() if ctx is None: - print "patch '%s' requires patch '%s' to be built first, but lack a context to do so" % (self.patch_id, patch) + print("patch '%s' requires patch '%s' to be built first, but lack a context to do so" % (self.patch_id, patch)) rc = False for patch in self.auto_requires: if not patch_list.is_built(patch): ctx = patch_list.patch_data[patch].get_build_context() if ctx is None: - print "patch '%s' requires patch '%s' to be built first, but lack a context to do so" % (self.patch_id, patch) + print("patch '%s' requires patch '%s' to be built first, but lack a context to do so" % (self.patch_id, patch)) rc = False return rc @@ -998,11 +998,11 @@ class PatchRecipeData: rc = True for patch in self.requires: if not patch_list.is_built(patch): - print "patch '%s' requires patch '%s' to be built first" % (self.patch_id, patch) + print("patch '%s' requires patch '%s' to be built first" % (self.patch_id, patch)) rc = False for patch in self.auto_requires: if not patch_list.is_built(patch): - print "patch '%s' requires patch '%s' to be built first" % (self.patch_id, patch) + print("patch '%s' requires patch '%s' to be built first" % (self.patch_id, patch)) rc = False return rc @@ -1025,14 +1025,14 @@ class PatchRecipeData: if req is None: msg = "Patch id missing under " LOG.exception(msg) - print msg + print(msg) raise PatchRecipeXMLFail(msg) sys.exit(2) self.requires.append(req) else: msg = "Unknow tag '%s' under " % child.tag LOG.exception(msg) - print msg + print(msg) raise PatchRecipeXMLFail(msg) sys.exit(2) @@ -1046,7 +1046,7 @@ class PatchRecipeData: else: msg = "Unknow tag '%s' under " % child.tag LOG.exception(msg) - print msg + print(msg) raise PatchRecipeXMLFail(msg) sys.exit(2) @@ -1058,11 +1058,11 @@ class PatchRecipeData: self.recipies[r.name] = r elif child.tag == "CONTEXT": self.build_context = child.text and child.text.strip() or None - print "====== CONTEXT = %s ========" % self.build_context + print("====== CONTEXT = %s ========" % self.build_context) else: msg = "Unknow tag '%s' under " % child.tag LOG.exception(msg) - print msg + print(msg) raise PatchRecipeXMLFail(msg) sys.exit(2) @@ -1076,7 +1076,7 @@ class PatchRecipeData: else: msg = "Unknow tag '%s' under " % child.tag LOG.exception(msg) - print msg + print(msg) raise PatchRecipeXMLFail(msg) sys.exit(2) if 'ID' in self.metadata: @@ -1084,7 +1084,7 @@ class PatchRecipeData: else: msg = "patch is missing required field " LOG.exception(msg) - print msg + print(msg) raise PatchRecipeXMLFail(msg) sys.exit(2) @@ -1093,22 +1093,22 @@ class PatchRecipeData: if self.sw_version != build_info['SW_VERSION']: msg = "patch '%s' SW_VERSION is inconsistent with that of workdir '%s'" % (self.patch_id, workdir) LOG.exception(msg) - print msg + print(msg) raise PatchRecipeXMLFail(msg) sys.exit(2) else: msg = "patch '%s' is missing required field " % self.patch_id LOG.exception(msg) - print msg + print(msg) raise PatchRecipeXMLFail(msg) sys.exit(2) - print "_parse_root patch_id = '%s'" % self.patch_id + print("_parse_root patch_id = '%s'" % self.patch_id) def recursive_print(self, e, depth=0): for child in e: - print "%sTag: %s, attr: %s, text: %s" % (" " * depth, child.tag, child.attrib, child.text and child.text.strip() or "") + print("%sTag: %s, attr: %s, text: %s" % (" " * depth, child.tag, child.attrib, child.text and child.text.strip() or "")) self.recursive_print(child.getchildren(), depth + 1) # for child in e.iter('BUILD'): # print "Tag: %s, attr: %s" % (child.tag, child.attrib) @@ -1173,10 +1173,10 @@ class PatchRecipeData: 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) - print "context: %s" % str(self.build_context) - print "metadata: %s" % str(self.metadata) - print "requires: %s" % str(self.requires) + print("patch_id: %s" % str(self.patch_id)) + print("context: %s" % str(self.build_context)) + print("metadata: %s" % str(self.metadata)) + print("requires: %s" % str(self.requires)) for key in self.recipies: self.recipies[key].myprint("%s " % indent) @@ -1184,7 +1184,7 @@ class PatchRecipeData: if workdir is None: msg = "workdir not provided" LOG.exception(msg) - print msg + print(msg) raise PatchBuildFail(msg) sys.exit(2) return False @@ -1204,7 +1204,7 @@ class PatchRecipeData: if srcdir is None: msg = "srcdir not provided" LOG.exception(msg) - print msg + print(msg) raise PatchBuildFail(msg) sys.exit(2) return False @@ -1222,7 +1222,7 @@ class PatchRecipeData: else: msg = "Don't know what build context to use for patch %s" % self.patch_id LOG.exception(msg) - print msg + print(msg) raise PatchBuildFail(msg) sys.exit(2) return False @@ -1230,7 +1230,7 @@ class PatchRecipeData: if workdir is None: msg = "workdir not provided" LOG.exception(msg) - print msg + print(msg) raise PatchBuildFail(msg) sys.exit(2) return False @@ -1297,7 +1297,7 @@ class PatchRecipeData: os.environ['DEST'] = "%s/export/patch_source/%s" % (os.environ['MY_PATCH_WORKSPACE'], self.patch_id) issue_cmd("mkdir -p %s" % os.environ['DEST']) for recipe in self.recipies.keys(): - print "capture source of recipe %s" % recipe + print("capture source of recipe %s" % recipe) self.recipies[recipe].capture_source() def build_patch(self, local_path="."): @@ -1312,38 +1312,38 @@ class PatchRecipeData: recipe_str += recipe + " " if not self.recipies[recipe].is_prebuilt(): build_recipe_str += recipe + " " - print "recipe_str = %s" % recipe_str - print "build_recipe_str = %s" % build_recipe_str + print("recipe_str = %s" % recipe_str) + print("build_recipe_str = %s" % build_recipe_str) if recipe_str == "": msg = "No recipies for patch %s" % self.patch_id LOG.exception(msg) - print msg + print(msg) raise PatchBuildFail(msg) sys.exit(2) return False if pre_compiled_flag and pre_clean_flag: - print "pre clean" + print("pre clean") for recipe in self.recipies.keys(): - print "pre clean recipe %s" % recipe + print("pre clean recipe %s" % recipe) self.recipies[recipe].clean() - print "done" + print("done") sys.exit(0) if not pre_compiled_flag: # compile patch os.chdir(workdir) - print "pre clean" + print("pre clean") if build_recipe_str == "": - print " ... nothing to clean" + print(" ... nothing to clean") else: issue_cmd("build-pkgs --no-build-info --clean %s" % build_recipe_str) for recipe in self.recipies.keys(): - print "pre clean recipe %s" % recipe + print("pre clean recipe %s" % recipe) self.recipies[recipe].clean() - print "Build" + print("Build") if build_recipe_str == "": - print " ... nothing to build" + print(" ... nothing to build") else: issue_cmd("build-pkgs --no-build-info --careful %s" % build_recipe_str) @@ -1387,13 +1387,13 @@ class PatchRecipeData: try: self.recipies[recipe].build_patch(pf, fatal=False) except PatchPackagingMiss: - print "Warning: attempting rebuild of recipe %s" % self.recipies[recipe].name + print("Warning: attempting rebuild of recipe %s" % self.recipies[recipe].name) if not self.recipies[recipe].is_prebuilt(): issue_cmd("build-pkgs --no-build-info --careful %s" % self.recipies[recipe].name) self.recipies[recipe].build_patch(pf, fatal=True) local_path = self.pl._std_local_path("") - print "=== local_path = %s ===" % local_path + print("=== local_path = %s ===" % local_path) pf.gen_patch(outdir=local_path) return True @@ -1443,7 +1443,7 @@ def validate_tag(tag): except PatchRecipeCmdFail: msg = "TAG '%s' is invalid" % tag LOG.exception(msg) - print msg + print(msg) return False return True @@ -1455,32 +1455,32 @@ def issue_cmd_w_stdout(cmd): if rc != 0: msg = "CMD failed: %s" % str(cmd) LOG.exception(msg) - print msg + print(msg) raise PatchRecipeCmdFail(msg) return out def issue_cmd(cmd): - print "CMD: %s" % cmd + print("CMD: %s" % cmd) rc = subprocess.call(cmd, shell=True) if rc != 0: msg = "CMD failed: %s" % cmd LOG.exception(msg) - print msg + print(msg) raise PatchRecipeCmdFail(msg) def issue_cmd_no_raise(cmd): - print "CMD: %s" % cmd + print("CMD: %s" % cmd) rc = subprocess.call(cmd, shell=True) if rc != 0: msg = "CMD failed: %s" % cmd LOG.exception(msg) - print msg + print(msg) def issue_cmd_rc(cmd): - print "CMD: %s" % cmd + print("CMD: %s" % cmd) rc = subprocess.call(cmd, shell=True) return rc @@ -1518,7 +1518,7 @@ def capture_rpms(): def modify_patch_usage(): msg = "modify_patch [ --obsolete | --released | --development ] [ --sw_version --id | --file ]" LOG.exception(msg) - print msg + print(msg) sys.exit(1) @@ -1542,7 +1542,7 @@ def modify_patch(): 'file=', ]) except getopt.GetoptError as e: - print str(e) + print(str(e)) modify_patch_usage() patch_path = None @@ -1575,11 +1575,11 @@ def modify_patch(): elif opt in ("-h", "--help"): modify_patch_usage() else: - print "unknown option '%s'" % opt + print("unknown option '%s'" % opt) modify_patch_usage() if not status_set: - print "new status not specified" + print("new status not specified") modify_patch_usage() workdir = tempfile.mkdtemp(prefix="patch_modify_") @@ -1589,10 +1589,10 @@ def modify_patch(): if patch_path is not None: rc = PatchFile.modify_patch(patch_path, "status", new_status) assert(rc) - print "Patch '%s' has been modified to status '%s'" % (patch_path, new_status) + print("Patch '%s' has been modified to status '%s'" % (patch_path, new_status)) else: if sw_version is None or patch_id is None: - print "--sw_version and --id are required" + print("--sw_version and --id are required") shutil.rmtree(workdir) modify_patch_usage() @@ -1600,9 +1600,9 @@ def modify_patch(): pl = PatchList([]) patch_file_name = "%s.patch" % patch_id patch_path = pl._std_patch_git_path(patch_file_name) - print "patch_id = %s" % patch_id - print "patch_file_name = %s" % patch_file_name - print "patch_path = %s" % patch_path + print("patch_id = %s" % patch_id) + print("patch_file_name = %s" % patch_file_name) + print("patch_path = %s" % patch_path) rc = PatchFile.modify_patch(patch_path, "status", new_status) assert(rc) os.chdir(pl._std_patch_git_path("..")) @@ -1610,7 +1610,7 @@ def modify_patch(): issue_cmd("git commit -m \"Modify status of patch '%s' to '%s'\"" % (patch_id, new_status)) issue_cmd("git push --dry-run --set-upstream origin %s:%s" % (sw_version, sw_version)) issue_cmd("git push --set-upstream origin %s:%s" % (sw_version, sw_version)) - print "Patch '%s' has been modified to status '%s'" % (patch_id, new_status) + print("Patch '%s' has been modified to status '%s'" % (patch_id, new_status)) if new_status == STATUS_RELEASED: tm = time.localtime(time.time()) @@ -1694,26 +1694,26 @@ def modify_patch(): issue_cmd_no_raise("chmod 664 %s/%s" % (deliver_dest, patch_file_name)) issue_cmd_no_raise("chmod 664 %s/%s.md5" % (deliver_dest, patch_file_name)) - print "" - print "Go here to deliver the patch" - print " http://deliveryplus.windriver.com/update/release" - print "Login if required" - print "" - print "Release to be updated:" - print " select '%s'" % human_release - print "press 'select' and wait for next page to load." - print "" - print "Windshare folder to be uploaded:" - print " select '%s'" % windshare_folder - print "Subdirectory of WindShare folder in which to place updates:" - print " select 'patches'" - print "Pathname from which to copy update content:" - print " %s" % deliver_dest - print "press 'Release to Production'" - print "" + print("") + print("Go here to deliver the patch") + print(" http://deliveryplus.windriver.com/update/release") + print("Login if required") + print("") + print("Release to be updated:") + print(" select '%s'" % human_release) + print("press 'select' and wait for next page to load.") + print("") + print("Windshare folder to be uploaded:") + print(" select '%s'" % windshare_folder) + print("Subdirectory of WindShare folder in which to place updates:") + print(" select 'patches'") + print("Pathname from which to copy update content:") + print(" %s" % deliver_dest) + print("press 'Release to Production'") + print("") except: - print "Failed to modify patch!" + print("Failed to modify patch!") finally: shutil.rmtree(workdir) @@ -1721,10 +1721,10 @@ def modify_patch(): def query_patch_usage(): msg = "query_patch [ --sw_version --id | --file ] [ --field ]" LOG.exception(msg) - print msg + print(msg) msg = " field_name = [ status | summary | description | install_instructions | warnings | contents | requires ]" LOG.exception(msg) - print msg + print(msg) sys.exit(1) @@ -1746,7 +1746,7 @@ def query_patch(): 'field=', ]) except getopt.GetoptError as e: - print str(e) + print(str(e)) query_patch_usage() patch_path = None @@ -1765,7 +1765,7 @@ def query_patch(): elif opt in ("-h", "--help"): query_patch_usage() else: - print "unknown option '%s'" % opt + print("unknown option '%s'" % opt) query_patch_usage() workdir = tempfile.mkdtemp(prefix="patch_modify_") @@ -1777,14 +1777,14 @@ def query_patch(): field_order = ['id', 'sw_version', 'status', 'cert', 'reboot_required', 'unremovable', 'summary', 'description', 'install_instructions', 'warnings'] for k in field_order: if k in answer.keys(): - print "%s: '%s'" % (k, answer[k]) + print("%s: '%s'" % (k, answer[k])) # Print any remaining fields, any order for k in answer.keys(): if k not in field_order: - print "%s: '%s'" % (k, answer[k]) + print("%s: '%s'" % (k, answer[k])) else: if sw_version is None or patch_id is None: - print "--sw_version and --id are required" + print("--sw_version and --id are required") shutil.rmtree(workdir) query_patch_usage() @@ -1792,14 +1792,14 @@ def query_patch(): pl = PatchList([]) patch_file_name = "%s.patch" % patch_id patch_path = pl._std_patch_git_path(patch_file_name) - print "patch_id = %s" % patch_id - print "patch_file_name = %s" % patch_file_name - print "patch_path = %s" % patch_path + print("patch_id = %s" % patch_id) + print("patch_file_name = %s" % patch_file_name) + print("patch_path = %s" % patch_path) answer = PatchFile.query_patch(patch_path, field=field) - print str(answer) + print(str(answer)) except: - print "Failed to query patch!" + print("Failed to query patch!") finally: shutil.rmtree(workdir) @@ -1807,7 +1807,7 @@ def query_patch(): def make_patch_usage(): msg = "make_patch [--formal | --pre-compiled [--pre-clean]] [--workdir ] [--srcdir ] [--branch ] [--capture_source] [--capture_rpms] [ --all --sw_version | ]" LOG.exception(msg) - print msg + print(msg) sys.exit(1) @@ -1844,7 +1844,7 @@ def make_patch(): 'sw_version=', ]) except getopt.GetoptError as e: - print str(e) + print(str(e)) make_patch_usage() cwd = os.getcwd() @@ -1874,124 +1874,124 @@ def make_patch(): elif opt in ("-h", "--help"): make_patch_usage() else: - print "unknown option '%s'" % opt + print("unknown option '%s'" % opt) make_patch_usage() for x in remainder: patch_list.append(os.path.normpath(os.path.join(cwd, os.path.expanduser(x)))) if len(patch_list) <= 0 and not all_flag: - print "Either '--all' or a patch.xml must be specified" + print("Either '--all' or a patch.xml must be specified") make_patch_usage() if all_flag and len(patch_list) > 0: - print "only specify one of '--all' or a patch.xml" + print("only specify one of '--all' or a patch.xml") make_patch_usage() if len(patch_list) > 1: - print "only one patch.xml can be specified" + print("only one patch.xml can be specified") make_patch_usage() if all_flag: if sw_version is None: - print "'--sw_version' must be specified when using '--all'" + print("'--sw_version' must be specified when using '--all'") make_patch_usage() if branch is not None: if workdir is None or srcdir is None: - print "If --branch is specified, then a srcdir and workdir must also be specified" + print("If --branch is specified, then a srcdir and workdir must also be specified") make_patch_usage() if pre_compiled_flag: - print "pre_compiled_flag = %s" % str(pre_compiled_flag) + print("pre_compiled_flag = %s" % str(pre_compiled_flag)) if formal_flag: os.environ["FORMAL_BUILD"] = "1" - print "formal_flag = %s" % str(formal_flag) + print("formal_flag = %s" % str(formal_flag)) # TODO if branch is not None or workdir is not None or srcdir is not None: # TODO print "If --formal is specified, then srcdir, workdir and branch are automatci and must not be specified" # TODO make_patch_usage() if pre_compiled_flag and formal_flag: - print "invalid options: --formal and --pre-compiled can't be used together." + print("invalid options: --formal and --pre-compiled can't be used together.") make_patch_usage() if workdir is not None: if not os.path.isdir(workdir): - print "invalid directory: workdir = '%s'" % workdir + print("invalid directory: workdir = '%s'" % workdir) make_patch_usage() temp_rpm_db_dir = "%s/%s" % (workdir, ".rpmdb") if srcdir is not None: if not os.path.isdir(srcdir): - print "invalid directory: srcdir = '%s'" % srcdir + print("invalid directory: srcdir = '%s'" % srcdir) make_patch_usage() for patch in patch_list: if not os.path.isfile(patch): - print "invalid patch file path: '%s'" % patch + print("invalid patch file path: '%s'" % patch) make_patch_usage() if 'MY_REPO' in os.environ: MY_REPO = os.path.normpath(os.path.join(cwd, os.path.expanduser(os.environ['MY_REPO']))) else: - print "ERROR: environment variable 'MY_REPO' is not defined" + print("ERROR: environment variable 'MY_REPO' is not defined") sys.exit(1) if 'MY_WORKSPACE' in os.environ: MY_WORKSPACE = os.path.normpath(os.path.join(cwd, os.path.expanduser(os.environ['MY_WORKSPACE']))) else: - print "ERROR: environment variable 'MY_REPO' is not defined" + print("ERROR: environment variable 'MY_REPO' is not defined") sys.exit(1) if 'PROJECT' in os.environ: PROJECT = os.path.normpath(os.path.join(cwd, os.path.expanduser(os.environ['PROJECT']))) else: - print "ERROR: environment variable 'PROJECT' is not defined" + print("ERROR: environment variable 'PROJECT' is not defined") sys.exit(1) if 'SRC_BUILD_ENVIRONMENT' in os.environ: SRC_BUILD_ENVIRONMENT = os.path.normpath(os.path.join(cwd, os.path.expanduser(os.environ['SRC_BUILD_ENVIRONMENT']))) else: - print "ERROR: environment variable 'SRC_BUILD_ENVIRONMENT' is not defined" + print("ERROR: environment variable 'SRC_BUILD_ENVIRONMENT' is not defined") sys.exit(1) if 'MY_SRC_RPM_BUILD_DIR' in os.environ: MY_SRC_RPM_BUILD_DIR = os.path.normpath(os.path.join(cwd, os.path.expanduser(os.environ['MY_SRC_RPM_BUILD_DIR']))) else: - print "ERROR: environment variable 'MY_SRC_RPM_BUILD_DIR' is not defined" + print("ERROR: environment variable 'MY_SRC_RPM_BUILD_DIR' is not defined") sys.exit(1) if 'MY_BUILD_CFG' in os.environ: MY_BUILD_CFG = os.path.normpath(os.path.join(cwd, os.path.expanduser(os.environ['MY_BUILD_CFG']))) else: - print "ERROR: environment variable 'MY_BUILD_CFG' is not defined" + print("ERROR: environment variable 'MY_BUILD_CFG' is not defined") sys.exit(1) if 'MY_BUILD_DIR' in os.environ: MY_BUILD_DIR = os.path.normpath(os.path.join(cwd, os.path.expanduser(os.environ['MY_BUILD_DIR']))) else: - print "ERROR: environment variable 'MY_BUILD_DIR' is not defined" + print("ERROR: environment variable 'MY_BUILD_DIR' is not defined") sys.exit(1) - print "formal: %s" % formal_flag - print "pre_compiled_flag: %s" % pre_compiled_flag - print "pre_clean_flag: %s" % pre_clean_flag - print "capture_source_flag: %s" % capture_source_flag - print "capture_rpms_flag: %s" % capture_rpms_flag - print "workdir: %s" % workdir - print "srcdir: %s" % srcdir - print "branch: %s" % branch - print "sw_version: %s" % sw_version - print "patch_list: %s" % patch_list - print "" + print("formal: %s" % formal_flag) + print("pre_compiled_flag: %s" % pre_compiled_flag) + print("pre_clean_flag: %s" % pre_clean_flag) + print("capture_source_flag: %s" % capture_source_flag) + print("capture_rpms_flag: %s" % capture_rpms_flag) + print("workdir: %s" % workdir) + print("srcdir: %s" % srcdir) + print("branch: %s" % branch) + print("sw_version: %s" % sw_version) + print("patch_list: %s" % patch_list) + print("") if workdir is not None: os.chdir(workdir) if not read_build_info(): - print "build.info is missing. workdir is invalid, or has never completed initial loadbuild: workdir = '%s'" % workdir + print("build.info is missing. workdir is invalid, or has never completed initial loadbuild: workdir = '%s'" % workdir) make_patch_usage() # Capture initial state before any patches are built diff --git a/cgcs-patch/cgcs-patch/cgcs_patch/patch_agent.py b/cgcs-patch/cgcs-patch/cgcs_patch/patch_agent.py index ffa01a94..0f4c4f57 100644 --- a/cgcs-patch/cgcs-patch/cgcs_patch/patch_agent.py +++ b/cgcs-patch/cgcs-patch/cgcs_patch/patch_agent.py @@ -765,7 +765,7 @@ class PatchAgent(PatchService): # Build up the install set if verbose_to_stdout: - print "Checking for software updates..." + print("Checking for software updates...") self.query() install_set = [] for pkg, version in self.to_install.iteritems(): @@ -779,23 +779,23 @@ class PatchAgent(PatchService): if len(install_set) > 0: try: if verbose_to_stdout: - print "Installing software updates..." + print("Installing software updates...") LOG.info("Installing: %s" % ", ".join(install_set)) output = subprocess.check_output(smart_install_cmd + install_set, stderr=subprocess.STDOUT) changed = True for line in output.split('\n'): LOG.info("INSTALL: %s" % line) if verbose_to_stdout: - print "Software updated." + print("Software updated.") except subprocess.CalledProcessError as e: LOG.exception("Failed to install RPMs") LOG.error("Command output: %s" % e.output) rc = False if verbose_to_stdout: - print "WARNING: Software update failed." + print("WARNING: Software update failed.") else: if verbose_to_stdout: - print "Nothing to install." + print("Nothing to install.") LOG.info("Nothing to install") if rc: @@ -805,23 +805,23 @@ class PatchAgent(PatchService): if len(remove_set) > 0: try: if verbose_to_stdout: - print "Handling patch removal..." + print("Handling patch removal...") LOG.info("Removing: %s" % ", ".join(remove_set)) output = subprocess.check_output(smart_remove_cmd + remove_set, stderr=subprocess.STDOUT) changed = True for line in output.split('\n'): LOG.info("REMOVE: %s" % line) if verbose_to_stdout: - print "Patch removal complete." + print("Patch removal complete.") except subprocess.CalledProcessError as e: LOG.exception("Failed to remove RPMs") LOG.error("Command output: %s" % e.output) rc = False if verbose_to_stdout: - print "WARNING: Patch removal failed." + print("WARNING: Patch removal failed.") else: if verbose_to_stdout: - print "Nothing to remove." + print("Nothing to remove.") LOG.info("Nothing to remove") if changed: @@ -830,7 +830,7 @@ class PatchAgent(PatchService): self.node_is_patched = True if verbose_to_stdout: - print "This node has been patched." + print("This node has been patched.") if os.path.exists(node_is_patched_rr_file): LOG.info("Reboot is required. Skipping patch-scripts") diff --git a/cgcs-patch/cgcs-patch/cgcs_patch/patch_client.py b/cgcs-patch/cgcs-patch/cgcs_patch/patch_client.py index d4cdba44..c90b9cde 100644 --- a/cgcs-patch/cgcs-patch/cgcs_patch/patch_client.py +++ b/cgcs-patch/cgcs-patch/cgcs_patch/patch_client.py @@ -4,7 +4,7 @@ Copyright (c) 2014-2017 Wind River Systems, Inc. SPDX-License-Identifier: Apache-2.0 """ - +from __future__ import print_function import requests import json import os @@ -78,65 +78,65 @@ def set_term_width(): def print_help(): - print "usage: sw-patch [--debug]" - print " ..." - print "" - print "Subcomands:" - print "" - print textwrap.fill(" {0:<15} ".format("upload:") + help_upload, - width=TERM_WIDTH, subsequent_indent=' ' * 20) - print "" - print textwrap.fill(" {0:<15} ".format("upload-dir:") + help_upload_dir, - width=TERM_WIDTH, subsequent_indent=' ' * 20) - print "" - print textwrap.fill(" {0:<15} ".format("apply:") + help_apply, - width=TERM_WIDTH, subsequent_indent=' ' * 20) - print textwrap.fill(help_patch_args, - width=TERM_WIDTH, initial_indent=' ' * 20, subsequent_indent=' ' * 20) - print "" - print textwrap.fill(" {0:<15} ".format("remove:") + help_remove, - width=TERM_WIDTH, subsequent_indent=' ' * 20) - print textwrap.fill(help_patch_args, - width=TERM_WIDTH, initial_indent=' ' * 20, subsequent_indent=' ' * 20) - print "" - print textwrap.fill(" {0:<15} ".format("delete:") + help_delete, - width=TERM_WIDTH, subsequent_indent=' ' * 20) - print textwrap.fill(help_patch_args, - width=TERM_WIDTH, initial_indent=' ' * 20, subsequent_indent=' ' * 20) - print "" - print textwrap.fill(" {0:<15} ".format("query:") + help_query, - width=TERM_WIDTH, subsequent_indent=' ' * 20) - print "" - print textwrap.fill(" {0:<15} ".format("show:") + help_show, - width=TERM_WIDTH, subsequent_indent=' ' * 20) - print "" - print textwrap.fill(" {0:<15} ".format("what-requires:") + help_what_requires, - width=TERM_WIDTH, subsequent_indent=' ' * 20) - print "" - print textwrap.fill(" {0:<15} ".format("query-hosts:") + help_query_hosts, - width=TERM_WIDTH, subsequent_indent=' ' * 20) - print "" - print textwrap.fill(" {0:<15} ".format("host-install:") + help_host_install, - width=TERM_WIDTH, subsequent_indent=' ' * 20) - print "" - print textwrap.fill(" {0:<15} ".format("host-install-async:") + help_host_install_async, - width=TERM_WIDTH, subsequent_indent=' ' * 20) - print "" - print textwrap.fill(" {0:<15} ".format("install-local:") + help_install_local, - width=TERM_WIDTH, subsequent_indent=' ' * 20) - print "" - print textwrap.fill(" {0:<15} ".format("drop-host:") + help_drop_host, - width=TERM_WIDTH, subsequent_indent=' ' * 20) - print "" - print textwrap.fill(" {0:<15} ".format("query-dependencies:") + help_query_dependencies, - width=TERM_WIDTH, subsequent_indent=' ' * 20) - print "" - print textwrap.fill(" {0:<15} ".format("commit:") + help_commit, - width=TERM_WIDTH, subsequent_indent=' ' * 20) - print "" - print textwrap.fill(" {0:<15} ".format("--os-region-name:") + help_region_name, - width=TERM_WIDTH, subsequent_indent=' ' * 20) - print "" + print("usage: sw-patch [--debug]") + print(" ...") + print("") + print("Subcomands:") + print("") + print(textwrap.fill(" {0:<15} ".format("upload:") + help_upload, + width=TERM_WIDTH, subsequent_indent=' ' * 20)) + print("") + print(textwrap.fill(" {0:<15} ".format("upload-dir:") + help_upload_dir, + width=TERM_WIDTH, subsequent_indent=' ' * 20)) + print("") + print(textwrap.fill(" {0:<15} ".format("apply:") + help_apply, + width=TERM_WIDTH, subsequent_indent=' ' * 20)) + print(textwrap.fill(help_patch_args, + width=TERM_WIDTH, initial_indent=' ' * 20, subsequent_indent=' ' * 20)) + print("") + print(textwrap.fill(" {0:<15} ".format("remove:") + help_remove, + width=TERM_WIDTH, subsequent_indent=' ' * 20)) + print(textwrap.fill(help_patch_args, + width=TERM_WIDTH, initial_indent=' ' * 20, subsequent_indent=' ' * 20)) + print("") + print(textwrap.fill(" {0:<15} ".format("delete:") + help_delete, + width=TERM_WIDTH, subsequent_indent=' ' * 20)) + print(textwrap.fill(help_patch_args, + width=TERM_WIDTH, initial_indent=' ' * 20, subsequent_indent=' ' * 20)) + print("") + print(textwrap.fill(" {0:<15} ".format("query:") + help_query, + width=TERM_WIDTH, subsequent_indent=' ' * 20)) + print("") + print(textwrap.fill(" {0:<15} ".format("show:") + help_show, + width=TERM_WIDTH, subsequent_indent=' ' * 20)) + print("") + print(textwrap.fill(" {0:<15} ".format("what-requires:") + help_what_requires, + width=TERM_WIDTH, subsequent_indent=' ' * 20)) + print("") + print(textwrap.fill(" {0:<15} ".format("query-hosts:") + help_query_hosts, + width=TERM_WIDTH, subsequent_indent=' ' * 20)) + print("") + print(textwrap.fill(" {0:<15} ".format("host-install:") + help_host_install, + width=TERM_WIDTH, subsequent_indent=' ' * 20)) + print("") + print(textwrap.fill(" {0:<15} ".format("host-install-async:") + help_host_install_async, + width=TERM_WIDTH, subsequent_indent=' ' * 20)) + print("") + print(textwrap.fill(" {0:<15} ".format("install-local:") + help_install_local, + width=TERM_WIDTH, subsequent_indent=' ' * 20)) + print("") + print(textwrap.fill(" {0:<15} ".format("drop-host:") + help_drop_host, + width=TERM_WIDTH, subsequent_indent=' ' * 20)) + print("") + print(textwrap.fill(" {0:<15} ".format("query-dependencies:") + help_query_dependencies, + width=TERM_WIDTH, subsequent_indent=' ' * 20)) + print("") + print(textwrap.fill(" {0:<15} ".format("commit:") + help_commit, + width=TERM_WIDTH, subsequent_indent=' ' * 20)) + print("") + print(textwrap.fill(" {0:<15} ".format("--os-region-name:") + help_region_name, + width=TERM_WIDTH, subsequent_indent=' ' * 20)) + print("") exit(1) @@ -157,25 +157,25 @@ def print_result_debug(req): if req.status_code == 200: data = json.loads(req.text) if 'pd' in data: - print json.dumps(data['pd'], + print(json.dumps(data['pd'], sort_keys=True, indent=4, - separators=(',', ': ')) + separators=(',', ': '))) elif 'data' in data: - print json.dumps(data['data'], + print(json.dumps(data['data'], sort_keys=True, indent=4, - separators=(',', ': ')) + separators=(',', ': '))) else: - print json.dumps(data, + print(json.dumps(data, sort_keys=True, indent=4, - separators=(',', ': ')) + separators=(',', ': '))) elif req.status_code == 500: - print "An internal error has occurred. Please check /var/log/patching.log for details" + print("An internal error has occurred. Please check /var/log/patching.log for details") else: m = re.search("(Error message:.*)", req.text, re.MULTILINE) - print m.group(0) + print(m.group(0)) def print_patch_op_result(req): @@ -213,13 +213,13 @@ def print_patch_op_result(req): show_repo = True if show_repo: - print "{0:^{width_id}} {1:^{width_rr}} {2:^{width_rel}} {3:^{width_repo}} {4:^{width_state}}".format( + print("{0:^{width_id}} {1:^{width_rr}} {2:^{width_rel}} {3:^{width_repo}} {4:^{width_state}}".format( hdr_id, hdr_rr, hdr_rel, hdr_repo, hdr_state, width_id=width_id, width_rr=width_rr, - width_rel=width_rel, width_repo=width_repo, width_state=width_state) + width_rel=width_rel, width_repo=width_repo, width_state=width_state)) - print "{0} {1} {2} {3} {4}".format( - '=' * width_id, '=' * width_rr, '=' * width_rel, '=' * width_repo, '=' * width_state) + print("{0} {1} {2} {3} {4}".format( + '=' * width_id, '=' * width_rr, '=' * width_rel, '=' * width_repo, '=' * width_state)) for patch_id in sorted(pd.keys()): if "reboot_required" in pd[patch_id]: @@ -227,21 +227,21 @@ def print_patch_op_result(req): else: rr = "Y" - print "{0:<{width_id}} {1:^{width_rr}} {2:^{width_rel}} {3:^{width_repo}} {4:^{width_state}}".format( + print("{0:<{width_id}} {1:^{width_rr}} {2:^{width_rel}} {3:^{width_repo}} {4:^{width_state}}".format( patch_id, rr, pd[patch_id]["sw_version"], pd[patch_id]["repostate"], pd[patch_id]["patchstate"], width_id=width_id, width_rr=width_rr, - width_rel=width_rel, width_repo=width_repo, width_state=width_state) + width_rel=width_rel, width_repo=width_repo, width_state=width_state)) else: - print "{0:^{width_id}} {1:^{width_rr}} {2:^{width_rel}} {3:^{width_state}}".format( + print("{0:^{width_id}} {1:^{width_rr}} {2:^{width_rel}} {3:^{width_state}}".format( hdr_id, hdr_rr, hdr_rel, hdr_state, - width_id=width_id, width_rr=width_rr, width_rel=width_rel, width_state=width_state) + width_id=width_id, width_rr=width_rr, width_rel=width_rel, width_state=width_state)) - print "{0} {1} {2} {3}".format( - '=' * width_id, '=' * width_rr, '=' * width_rel, '=' * width_state) + print("{0} {1} {2} {3}".format( + '=' * width_id, '=' * width_rr, '=' * width_rel, '=' * width_state)) for patch_id in sorted(pd.keys()): if "reboot_required" in pd[patch_id]: @@ -249,28 +249,28 @@ def print_patch_op_result(req): else: rr = "Y" - print "{0:<{width_id}} {1:^{width_rr}} {2:^{width_rel}} {3:^{width_state}}".format( + print("{0:<{width_id}} {1:^{width_rr}} {2:^{width_rel}} {3:^{width_state}}".format( patch_id, rr, pd[patch_id]["sw_version"], pd[patch_id]["patchstate"], - width_id=width_id, width_rr=width_rr, width_rel=width_rel, width_state=width_state) + width_id=width_id, width_rr=width_rr, width_rel=width_rel, width_state=width_state)) - print "" + print("") if 'info' in data and data["info"] != "": - print data["info"] + print(data["info"]) if 'warning' in data and data["warning"] != "": - print "Warning:" - print data["warning"] + print("Warning:") + print(data["warning"]) if 'error' in data and data["error"] != "": - print "Error:" - print data["error"] + print("Error:") + print(data["error"]) elif req.status_code == 500: - print "An internal error has occurred. Please check /var/log/patching.log for details" + print("An internal error has occurred. Please check /var/log/patching.log for details") def print_patch_show_result(req): @@ -280,93 +280,93 @@ def print_patch_show_result(req): if 'metadata' in data: pd = data['metadata'] for patch_id in sorted(pd.keys()): - print "%s:" % patch_id + print("%s:" % patch_id) if "sw_version" in pd[patch_id] and pd[patch_id]["sw_version"] != "": - print textwrap.fill(" {0:<15} ".format("Release:") + pd[patch_id]["sw_version"], - width=TERM_WIDTH, subsequent_indent=' ' * 20) + print(textwrap.fill(" {0:<15} ".format("Release:") + pd[patch_id]["sw_version"], + width=TERM_WIDTH, subsequent_indent=' ' * 20)) if "patchstate" in pd[patch_id] and pd[patch_id]["patchstate"] != "": - print textwrap.fill(" {0:<15} ".format("Patch State:") + pd[patch_id]["patchstate"], - width=TERM_WIDTH, subsequent_indent=' ' * 20) + print(textwrap.fill(" {0:<15} ".format("Patch State:") + pd[patch_id]["patchstate"], + width=TERM_WIDTH, subsequent_indent=' ' * 20)) if pd[patch_id]["patchstate"] == "n/a": if "repostate" in pd[patch_id] and pd[patch_id]["repostate"] != "": - print textwrap.fill(" {0:<15} ".format("Repo State:") + pd[patch_id]["repostate"], - width=TERM_WIDTH, subsequent_indent=' ' * 20) + print(textwrap.fill(" {0:<15} ".format("Repo State:") + pd[patch_id]["repostate"], + width=TERM_WIDTH, subsequent_indent=' ' * 20)) if "status" in pd[patch_id] and pd[patch_id]["status"] != "": - print textwrap.fill(" {0:<15} ".format("Status:") + pd[patch_id]["status"], - width=TERM_WIDTH, subsequent_indent=' ' * 20) + print(textwrap.fill(" {0:<15} ".format("Status:") + pd[patch_id]["status"], + width=TERM_WIDTH, subsequent_indent=' ' * 20)) if "unremovable" in pd[patch_id] and pd[patch_id]["unremovable"] != "": - print textwrap.fill(" {0:<15} ".format("Unremovable:") + pd[patch_id]["unremovable"], - width=TERM_WIDTH, subsequent_indent=' ' * 20) + print(textwrap.fill(" {0:<15} ".format("Unremovable:") + pd[patch_id]["unremovable"], + width=TERM_WIDTH, subsequent_indent=' ' * 20)) if "reboot_required" in pd[patch_id] and pd[patch_id]["reboot_required"] != "": - print textwrap.fill(" {0:<15} ".format("RR:") + pd[patch_id]["reboot_required"], - width=TERM_WIDTH, subsequent_indent=' ' * 20) + print(textwrap.fill(" {0:<15} ".format("RR:") + pd[patch_id]["reboot_required"], + width=TERM_WIDTH, subsequent_indent=' ' * 20)) if "summary" in pd[patch_id] and pd[patch_id]["summary"] != "": - print textwrap.fill(" {0:<15} ".format("Summary:") + pd[patch_id]["summary"], - width=TERM_WIDTH, subsequent_indent=' ' * 20) + print(textwrap.fill(" {0:<15} ".format("Summary:") + pd[patch_id]["summary"], + width=TERM_WIDTH, subsequent_indent=' ' * 20)) if "description" in pd[patch_id] and pd[patch_id]["description"] != "": first_line = True for line in pd[patch_id]["description"].split('\n'): if first_line: - print textwrap.fill(" {0:<15} ".format("Description:") + line, - width=TERM_WIDTH, subsequent_indent=' ' * 20) + print(textwrap.fill(" {0:<15} ".format("Description:") + line, + width=TERM_WIDTH, subsequent_indent=' ' * 20)) first_line = False else: - print textwrap.fill(line, + print(textwrap.fill(line, width=TERM_WIDTH, subsequent_indent=' ' * 20, - initial_indent=' ' * 20) + initial_indent=' ' * 20)) if "install_instructions" in pd[patch_id] and pd[patch_id]["install_instructions"] != "": - print " Install Instructions:" + print(" Install Instructions:") for line in pd[patch_id]["install_instructions"].split('\n'): - print textwrap.fill(line, + print(textwrap.fill(line, width=TERM_WIDTH, subsequent_indent=' ' * 20, - initial_indent=' ' * 20) + initial_indent=' ' * 20)) if "warnings" in pd[patch_id] and pd[patch_id]["warnings"] != "": first_line = True for line in pd[patch_id]["warnings"].split('\n'): if first_line: - print textwrap.fill(" {0:<15} ".format("Warnings:") + line, - width=TERM_WIDTH, subsequent_indent=' ' * 20) + print(textwrap.fill(" {0:<15} ".format("Warnings:") + line, + width=TERM_WIDTH, subsequent_indent=' ' * 20)) first_line = False else: - print textwrap.fill(line, + print(textwrap.fill(line, width=TERM_WIDTH, subsequent_indent=' ' * 20, - initial_indent=' ' * 20) + initial_indent=' ' * 20)) if "requires" in pd[patch_id] and len(pd[patch_id]["requires"]) > 0: - print " Requires:" + print(" Requires:") for req_patch in sorted(pd[patch_id]["requires"]): - print ' ' * 20 + req_patch + print(' ' * 20 + req_patch) if "contents" in data and patch_id in data["contents"]: - print " Contents:" + print(" Contents:") for pkg in sorted(data["contents"][patch_id]): - print ' ' * 20 + pkg + print(' ' * 20 + pkg) - print "\n" + print("\n") if 'info' in data and data["info"] != "": - print data["info"] + print(data["info"]) if 'warning' in data and data["warning"] != "": - print "Warning:" - print data["warning"] + print("Warning:") + print(data["warning"]) if 'error' in data and data["error"] != "": - print "Error:" - print data["error"] + print("Error:") + print(data["error"]) elif req.status_code == 500: - print "An internal error has occurred. Please check /var/log/patching.log for details" + print("An internal error has occurred. Please check /var/log/patching.log for details") def patch_upload_req(debug, args): @@ -380,11 +380,11 @@ def patch_upload_req(debug, args): for patchfile in sorted(list(set(args))): if os.path.isdir(patchfile): - print "Error: %s is a directory. Please use upload-dir" % patchfile + print("Error: %s is a directory. Please use upload-dir" % patchfile) continue if not os.path.isfile(patchfile): - print "Error: File does not exist: %s" % patchfile + print("Error: File does not exist: %s" % patchfile) continue enc = MultipartEncoder(fields={'file': (patchfile, @@ -528,7 +528,7 @@ def patch_commit_req(debug, args): append_auth_token_if_required(headers) if release and not all_patches: # Disallow - print "Use of --release option requires --all" + print("Use of --release option requires --all") return 1 elif all_patches: # Get a list of all patches @@ -544,17 +544,17 @@ def patch_commit_req(debug, args): if 'pd' in data: patch_list = sorted(data['pd'].keys()) elif req.status_code == 500: - print "Failed to get patch list. Aborting..." + print("Failed to get patch list. Aborting...") return 1 if len(patch_list) == 0: - print "There are no %s patches to commit." % relopt + print("There are no %s patches to commit." % relopt) return 0 - print "The following patches will be committed:" + print("The following patches will be committed:") for patch_id in patch_list: - print " %s" % patch_id - print + print(" %s" % patch_id) + print() patches = "/".join(patch_list) else: @@ -569,16 +569,16 @@ def patch_commit_req(debug, args): data = json.loads(req.text) if 'patches' in data: - print "The following patches will be committed:" + print("The following patches will be committed:") for patch_id in sorted(data['patches']): - print " %s" % patch_id - print + print(" %s" % patch_id) + print() else: - print "No patches found to commit" + print("No patches found to commit") return 1 elif req.status_code == 500: - print "An internal error has occurred. Please check /var/log/patching.log for details" + print("An internal error has occurred. Please check /var/log/patching.log for details") return 1 # Run dry-run @@ -588,21 +588,21 @@ def patch_commit_req(debug, args): print_patch_op_result(req) if check_rc(req) != 0: - print "Aborting..." + print("Aborting...") return 1 if dry_run: return 0 - print + print() commit_warning = "WARNING: Committing a patch is an irreversible operation. " + \ "Committed patches cannot be removed." - print textwrap.fill(commit_warning, width=TERM_WIDTH, subsequent_indent=' ' * 9) - print + print(textwrap.fill(commit_warning, width=TERM_WIDTH, subsequent_indent=' ' * 9)) + print() user_input = raw_input("Would you like to continue? [y/N]: ") if user_input.lower() != 'y': - print "Aborting..." + print("Aborting...") return 1 url = "http://%s/patch/commit/%s" % (api_addr, patches) @@ -659,7 +659,7 @@ def print_query_hosts_result(req): if req.status_code == 200: data = json.loads(req.text) if 'data' not in data: - print "Invalid data returned:" + print("Invalid data returned:") print_result_debug(req) return @@ -690,12 +690,12 @@ def print_query_hosts_result(req): if len(agent["state"]) > width_state: width_state = len(agent["state"]) - print "{0:^{width_hn}} {1:^{width_ip}} {2:^{width_pc}} {3:^{width_rr}} {4:^{width_rel}} {5:^{width_state}}".format( + print("{0:^{width_hn}} {1:^{width_ip}} {2:^{width_pc}} {3:^{width_rr}} {4:^{width_rel}} {5:^{width_state}}".format( hdr_hn, hdr_ip, hdr_pc, hdr_rr, hdr_rel, hdr_state, - width_hn=width_hn, width_ip=width_ip, width_pc=width_pc, width_rr=width_rr, width_rel=width_rel, width_state=width_state) + width_hn=width_hn, width_ip=width_ip, width_pc=width_pc, width_rr=width_rr, width_rel=width_rel, width_state=width_state)) - print "{0} {1} {2} {3} {4} {5}".format( - '=' * width_hn, '=' * width_ip, '=' * width_pc, '=' * width_rr, '=' * width_rel, '=' * width_state) + print("{0} {1} {2} {3} {4} {5}".format( + '=' * width_hn, '=' * width_ip, '=' * width_pc, '=' * width_rr, '=' * width_rel, '=' * width_state)) for agent in sorted(agents, key=lambda a: a["hostname"]): patch_current_field = "Yes" if agent["patch_current"] else "No" @@ -705,17 +705,17 @@ def print_query_hosts_result(req): if agent["patch_failed"]: patch_current_field = "Failed" - print "{0:<{width_hn}} {1:<{width_ip}} {2:^{width_pc}} {3:^{width_rr}} {4:^{width_rel}} {5:^{width_state}}".format( + print("{0:<{width_hn}} {1:<{width_ip}} {2:^{width_pc}} {3:^{width_rr}} {4:^{width_rel}} {5:^{width_state}}".format( agent["hostname"], agent["ip"], patch_current_field, "Yes" if agent["requires_reboot"] else "No", agent["sw_version"], agent["state"], - width_hn=width_hn, width_ip=width_ip, width_pc=width_pc, width_rr=width_rr, width_rel=width_rel, width_state=width_state) + width_hn=width_hn, width_ip=width_ip, width_pc=width_pc, width_rr=width_rr, width_rel=width_rel, width_state=width_state)) elif req.status_code == 500: - print "An internal error has occurred. Please check /var/log/patching.log for details" + print("An internal error has occurred. Please check /var/log/patching.log for details") def patch_query_hosts_req(debug, args): @@ -800,10 +800,10 @@ def query_dependencies(debug, args): if 'patches' in data: for patch_id in sorted(data['patches']): - print patch_id + print(patch_id) elif req.status_code == 500: - print "An internal error has occurred. Please check /var/log/patching.log for details" + print("An internal error has occurred. Please check /var/log/patching.log for details") return check_rc(req) @@ -828,14 +828,14 @@ def wait_for_install_complete(agent_ip): if retriable_count <= max_retries: continue else: - print "Lost communications with the patch controller" + print("Lost communications with the patch controller") rc = 1 break if req.status_code == 200: data = json.loads(req.text) if 'data' not in data: - print "Invalid query-hosts data returned:" + print("Invalid query-hosts data returned:") print_result_debug(req) rc = 1 break @@ -857,7 +857,7 @@ def wait_for_install_complete(agent_ip): if retriable_count <= max_retries: continue else: - print "%s agent has timed out." % agent_ip + print("%s agent has timed out." % agent_ip) rc = 1 break @@ -867,29 +867,29 @@ def wait_for_install_complete(agent_ip): sys.stdout.write(".") sys.stdout.flush() elif state == constants.PATCH_AGENT_STATE_INSTALL_REJECTED: - print "\nInstallation rejected. Node must be locked" + print("\nInstallation rejected. Node must be locked") rc = 1 break elif state == constants.PATCH_AGENT_STATE_INSTALL_FAILED: - print "\nInstallation failed. Please check logs for details." + print("\nInstallation failed. Please check logs for details.") rc = 1 break elif state == constants.PATCH_AGENT_STATE_IDLE: - print "\nInstallation was successful." + print("\nInstallation was successful.") rc = 0 break else: - print "\nPatch agent is reporting unknown state: %s" % state + print("\nPatch agent is reporting unknown state: %s" % state) rc = 1 break elif req.status_code == 500: - print "An internal error has occurred. Please check /var/log/patching.log for details" + print("An internal error has occurred. Please check /var/log/patching.log for details") rc = 1 break else: m = re.search("(Error message:.*)", req.text, re.MULTILINE) - print m.group(0) + print(m.group(0)) rc = 1 break @@ -920,17 +920,17 @@ def host_install(debug, args): if req.status_code == 200: data = json.loads(req.text) if 'error' in data and data["error"] != "": - print "Error:" - print data["error"] + print("Error:") + print(data["error"]) rc = 1 else: rc = wait_for_install_complete(agent_ip) elif req.status_code == 500: - print "An internal error has occurred. Please check /var/log/patching.log for details" + print("An internal error has occurred. Please check /var/log/patching.log for details") rc = 1 else: m = re.search("(Error message:.*)", req.text, re.MULTILINE) - print m.group(0) + print(m.group(0)) rc = 1 return rc @@ -1015,7 +1015,7 @@ def patch_install_local(debug, args): # First, check to see if the controller hostname is already known. if utils.gethostbyname(constants.CONTROLLER_FLOATING_HOSTNAME): # If this is successful, disallow the install - print >>sys.stderr, "Error: This function can only be used before initial system configuration." + print("Error: This function can only be used before initial system configuration.", file=sys.stderr) return 1 # Ignore interrupts during this function @@ -1041,15 +1041,15 @@ def patch_install_local(debug, args): # install patches but won't automatically reboot if the RR flag is set subprocess.check_output(['/etc/init.d/sw-patch', 'restart']) except subprocess.CalledProcessError: - print >>sys.stderr, "Error: Failed to install patches. Please check /var/log/patching.log for details" + print("Error: Failed to install patches. Please check /var/log/patching.log for details", file=sys.stderr) rc = 1 # Restore /etc/hosts os.rename('/etc/hosts.patchbak', '/etc/hosts') if rc == 0: - print "Patch installation is complete." - print "Please reboot before continuing with configuration." + print("Patch installation is complete.") + print("Please reboot before continuing with configuration.") return rc @@ -1108,7 +1108,7 @@ def completion_opts(args): data = json.loads(req.text) if 'pd' in data: - print " ".join(data['pd'].keys()) + print(" ".join(data['pd'].keys())) return 0 elif args[0] == "hosts": @@ -1121,7 +1121,7 @@ def completion_opts(args): if 'data' in data: for agent in data['data']: - print agent["hostname"] + print(agent["hostname"]) return 0 return 1 @@ -1129,7 +1129,7 @@ def completion_opts(args): def check_env(env, var): if env not in os.environ: - print "You must provide a %s via env[%s]" % (var, env) + print("You must provide a %s via env[%s]" % (var, env)) exit(-1) @@ -1160,7 +1160,7 @@ def get_auth_token_and_endpoint(region_name): interface='internal', region_name=region_name) except (exceptions.http.Unauthorized, exceptions.EndpointNotFound) as e: - print e.message + print(e.message) exit(-1) return token, endpoint @@ -1192,13 +1192,13 @@ def check_for_os_region_name(): for c, value in enumerate(sys.argv, 1): if value == region_option: if c == len(sys.argv): - print "Please specify a region name" + print("Please specify a region name") print_help() region = sys.argv[c] global VIRTUAL_REGION if region != VIRTUAL_REGION: - print "Unsupported region name: %s" % region + print("Unsupported region name: %s" % region) exit(1) # check it is running on the active controller @@ -1246,8 +1246,8 @@ def main(): "host-install-async", "install-local", "drop-host"]): global VIRTUAL_REGION - print "\n%s command is not allowed in %s region" % (action, - VIRTUAL_REGION) + print("\n%s command is not allowed in %s region" % (action, + VIRTUAL_REGION)) exit(1) if auth_token is None and os.geteuid() != 0: @@ -1263,7 +1263,7 @@ def main(): elif action == "--help" or action == "-h": print_help() else: - print >>sys.stderr, "Error: Command must be run as sudo or root" + print("Error: Command must be run as sudo or root", file=sys.stderr) rc = 1 else: if action == "upload": diff --git a/cgcs-patch/cgcs-patch/cgcs_patch/patch_functions.py b/cgcs-patch/cgcs-patch/cgcs_patch/patch_functions.py index 1e709fb6..73e64f13 100644 --- a/cgcs-patch/cgcs-patch/cgcs_patch/patch_functions.py +++ b/cgcs-patch/cgcs-patch/cgcs_patch/patch_functions.py @@ -778,7 +778,7 @@ class PatchFile: try: subprocess.check_call(["sign-rpms", "-d", tmpdir]) except subprocess.CalledProcessError as e: - print "Failed to to add file signatures to RPMs. Call to sign-rpms process returned non-zero exit status %i" % e.returncode + print("Failed to to add file signatures to RPMs. Call to sign-rpms process returned non-zero exit status %i" % e.returncode) os.chdir(orig_wd) shutil.rmtree(tmpdir) raise SystemExit(e.returncode) @@ -800,7 +800,7 @@ class PatchFile: shutil.rmtree(tmpdir) - print "Patch is %s" % patchfile + print("Patch is %s" % patchfile) @staticmethod def write_patch(patchfile, cert_type=None): @@ -849,7 +849,7 @@ class PatchFile: # Note: This can fail if the user is not authorized to sign with the formal key. subprocess.check_call(["sign_patch_formal.sh", patchfile]) except subprocess.CalledProcessError as e: - print "Failed to sign official patch. Call to sign_patch_formal.sh process returned non-zero exit status %i" % e.returncode + print("Failed to sign official patch. Call to sign_patch_formal.sh process returned non-zero exit status %i" % e.returncode) raise SystemExit(e.returncode) @staticmethod @@ -1036,7 +1036,7 @@ class PatchFile: except Exception as e: template = "An exception of type {0} occurred. Arguments:\n{1!r}" message = template.format(type(e).__name__, e.args) - print message + print(message) finally: # Change back to original working dir os.chdir(orig_wd) @@ -1079,7 +1079,7 @@ class PatchFile: patch_id = thispatch.parse_metadata("metadata.xml") if patch_id is None: - print "Failed to import patch" + print("Failed to import patch") # Change back to original working dir os.chdir(orig_wd) shutil.rmtree(tmpdir) @@ -1188,26 +1188,26 @@ def patch_build(): 'storage=', 'all-nodes=']) except getopt.GetoptError: - print "Usage: %s [ ] ... " \ - % os.path.basename(sys.argv[0]) - print "Options:" - print "\t--id Patch ID" - print "\t--release Platform release version" - print "\t--status Patch Status Code (ie. O, R, V)" - print "\t--unremovable Marks patch as unremovable" - print "\t--reboot-required Marks patch as reboot-required (default=Y)" - print "\t--summary Patch Summary" - print "\t--desc Patch Description" - print "\t--warn Patch Warnings" - print "\t--inst Patch Install Instructions" - print "\t--req Required Patch" - print "\t--controller New package for controller" - print "\t--compute New package for compute node" - print "\t--compute-lowlatency New package for compute-lowlatency node" - print "\t--storage New package for storage node" - print "\t--controller-compute New package for combined node" - print "\t--controller-compute-lowlatency New package for lowlatency combined node" - print "\t--all-nodes New package for all node types" + print("Usage: %s [ ] ... " \ + % os.path.basename(sys.argv[0])) + print("Options:") + print("\t--id Patch ID") + print("\t--release Platform release version") + print("\t--status Patch Status Code (ie. O, R, V)") + print("\t--unremovable Marks patch as unremovable") + print("\t--reboot-required Marks patch as reboot-required (default=Y)") + print("\t--summary Patch Summary") + print("\t--desc Patch Description") + print("\t--warn Patch Warnings") + print("\t--inst Patch Install Instructions") + print("\t--req Required Patch") + print("\t--controller New package for controller") + print("\t--compute New package for compute node") + print("\t--compute-lowlatency New package for compute-lowlatency node") + print("\t--storage New package for storage node") + print("\t--controller-compute New package for combined node") + print("\t--controller-compute-lowlatency New package for lowlatency combined node") + print("\t--all-nodes New package for all node types") exit(1) pf = PatchFile() @@ -1228,7 +1228,7 @@ def patch_build(): pf.meta.unremovable = "Y" elif opt == "--reboot-required": if arg != "Y" and arg != "N": - print "The --reboot-required option requires either Y or N as argument." + print("The --reboot-required option requires either Y or N as argument.") exit(1) pf.meta.reboot_required = arg elif opt == "--desc": @@ -1256,7 +1256,7 @@ def patch_build(): pf.add_rpm(arg, personality=opt[2:]) if pf.meta.id is None: - print "The --id argument is mandatory." + print("The --id argument is mandatory.") exit(1) for rpmfile in remainder: 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 49673e0f..b4e56dd1 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 @@ -27,7 +27,7 @@ def get_unique_id(filename, digits=4): file = posixfile.open(path, "w") file.lock("w|", digits) except IOError: - print "creation of file '%s' failed" % path + print("creation of file '%s' failed" % path) return -1 file.seek(0) # rewind diff --git a/cgcs-patch/cgcs-patch/cgcs_patch_id/patch_id_allocator_client.py b/cgcs-patch/cgcs-patch/cgcs_patch_id/patch_id_allocator_client.py index 1af05c41..1da10caf 100755 --- a/cgcs-patch/cgcs-patch/cgcs_patch_id/patch_id_allocator_client.py +++ b/cgcs-patch/cgcs-patch/cgcs_patch_id/patch_id_allocator_client.py @@ -21,7 +21,7 @@ def request_patch_id(sw_version="1.01", prefix="CGCS"): raw_parms = {} raw_parms['sw_version'] = sw_version raw_parms['prefix'] = prefix - print "raw_parms = %s" % str(raw_parms) + print("raw_parms = %s" % str(raw_parms)) url = "http://%s:%d/get_patch_id" % (server, port) params = urllib.urlencode(raw_parms) @@ -36,23 +36,23 @@ def main(): prefix = None raw_parms = {} - print "optlist = %s" % str(optlist) - print "remainder = %s" % str(remainder) + print("optlist = %s" % str(optlist)) + print("remainder = %s" % str(remainder)) for key, val in optlist: - print "key = %s, val = %s" % (key, val) + print("key = %s, val = %s" % (key, val)) if key == '--sw_version': sw_version = val - print "sw_version = %s" % sw_version + print("sw_version = %s" % sw_version) raw_parms['sw_version'] = sw_version if key == '--prefix': prefix = val - print "prefix = %s" % prefix + print("prefix = %s" % prefix) raw_parms['prefix'] = prefix # response = request_patch_id(sw_version=sw_version, prefix=prefix) response = request_patch_id(**raw_parms) - print "response = %s" % str(response) + print("response = %s" % str(response)) if __name__ == "__main__": diff --git a/tox.ini b/tox.ini index 0188d675..b2de07f7 100644 --- a/tox.ini +++ b/tox.ini @@ -52,16 +52,34 @@ commands = [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 +# 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 +exclude = .venv,.git,.tox,dist,doc,*lib/python*,*egg,build,release-tag-* + +# Use flake8 to replace pep8. [testenv:pep8] usedevelop = False skip_install = True deps = - pep8 + flake8 commands = - pep8 + flake8 [testenv:venv] commands = {posargs}