From 937cf7052a7fa0d9c8c74703866705c19554a2ed Mon Sep 17 00:00:00 2001 From: Fabio Erculiani Date: Mon, 18 Feb 2013 22:47:19 +0000 Subject: [PATCH] [matter] uniform string quoting, prefer " over ' --- matter/antimatter.py | 22 ++--- matter/matter-scheduler | 4 +- matter/matter/builder.py | 30 +++--- matter/matter/main.py | 12 +-- matter/matter/output.py | 40 ++++---- matter/matter/spec.py | 192 +++++++++++++++++++-------------------- matter/matter/utils.py | 4 +- 7 files changed, 152 insertions(+), 152 deletions(-) diff --git a/matter/antimatter.py b/matter/antimatter.py index 486942e09..920f60ce7 100755 --- a/matter/antimatter.py +++ b/matter/antimatter.py @@ -8,15 +8,15 @@ import os import re import time -os.environ['ETP_GETTEXT_DOMAIN'] = "entropy-server" +os.environ["ETP_GETTEXT_DOMAIN"] = "entropy-server" # Entropy imports -sys.path.insert(0, '/usr/lib/entropy/lib') -sys.path.insert(0, '/usr/lib/entropy/server') -sys.path.insert(0, '/usr/lib/entropy/client') -sys.path.insert(0, '../lib') -sys.path.insert(0, '../server') -sys.path.insert(0, '../client') +sys.path.insert(0, "/usr/lib/entropy/lib") +sys.path.insert(0, "/usr/lib/entropy/server") +sys.path.insert(0, "/usr/lib/entropy/client") +sys.path.insert(0, "../lib") +sys.path.insert(0, "../server") +sys.path.insert(0, "../client") # Entropy imports @@ -25,9 +25,9 @@ from entropy.output import print_info, print_error, print_warning, \ purple, brown # Portage imports -os.environ['ACCEPT_PROPERTIES'] = "* -interactive" -os.environ['FEATURES'] = "split-log" -os.environ['CMAKE_NO_COLOR'] = "yes" +os.environ["ACCEPT_PROPERTIES"] = "* -interactive" +os.environ["FEATURES"] = "split-log" +os.environ["CMAKE_NO_COLOR"] = "yes" from _emerge.actions import load_emerge_config import portage @@ -483,7 +483,7 @@ if __name__ == "__main__": nocolor() parser = argparse.ArgumentParser( - description='Automated package updates scanner', + description="Automated package updates scanner", formatter_class=argparse.RawDescriptionHelpFormatter) parser.add_argument("--verbose", "-v", action="store_true", diff --git a/matter/matter-scheduler b/matter/matter-scheduler index cb386eaf8..d033a40ad 100755 --- a/matter/matter-scheduler +++ b/matter/matter-scheduler @@ -38,7 +38,7 @@ Environment variables: DEFAULT_MATTER_ARGS,) parser = argparse.ArgumentParser( - description='Entropy Matter, execution scheduler', + description="Entropy Matter, execution scheduler", epilog=ENV_VARS_HELP, formatter_class=argparse.RawDescriptionHelpFormatter) @@ -66,4 +66,4 @@ Environment variables: sys.stderr.write(repr(err) + "\n") rc = 1 - raise SystemExit(rc) \ No newline at end of file + raise SystemExit(rc) diff --git a/matter/matter/builder.py b/matter/matter/builder.py index 5eec33e7b..66191810a 100644 --- a/matter/matter/builder.py +++ b/matter/matter/builder.py @@ -244,9 +244,9 @@ class PackageBuilder(object): filters against the package dependency to see if it's eligible for the graph. """ - allow_rebuild = self._params['rebuild'] == "yes" - allow_not_installed = self._params['not-installed'] == "yes" - allow_downgrade = self._params['downgrade'] == "yes" + allow_rebuild = self._params["rebuild"] == "yes" + allow_not_installed = self._params["not-installed"] == "yes" + allow_downgrade = self._params["downgrade"] == "yes" try: best_visible = portdb.xmatch("bestmatch-visible", package) @@ -317,7 +317,7 @@ class PackageBuilder(object): # list of _emerge.Package.Package objects package_queue = graph.altlist() - allow_soft_blocker = self._params['soft-blocker'] == "yes" + allow_soft_blocker = self._params["soft-blocker"] == "yes" if not allow_soft_blocker: blockers = [x for x in package_queue if isinstance(x, Blocker)] if blockers: @@ -354,7 +354,7 @@ class PackageBuilder(object): # calculate dependencies, if --dependencies is not enabled # because we have to validate it - if (self._params['dependencies'] == "no") \ + if (self._params["dependencies"] == "no") \ and (len(package_queue) > 1): deps = "\n ".join(dep_list) print_warning("dependencies pulled in:") @@ -363,7 +363,7 @@ class PackageBuilder(object): return None # protect against unwanted package unmerges - if self._params['unmerge'] == "no": + if self._params["unmerge"] == "no": unmerges = [x for x in real_queue if x.operation == "uninstall"] if unmerges: deps = "\n ".join([x.cpv for x in unmerges]) @@ -373,9 +373,9 @@ class PackageBuilder(object): return None # inspect use flags changes - allow_new_useflags = self._params['new-useflags'] == "yes" + allow_new_useflags = self._params["new-useflags"] == "yes" allow_removed_useflags = \ - self._params['removed-useflags'] == "yes" + self._params["removed-useflags"] == "yes" use_flags_give_up = False if (not allow_new_useflags) or (not allow_removed_useflags): @@ -411,7 +411,7 @@ class PackageBuilder(object): "USE flags constraint") return None - allow_downgrade = self._params['downgrade'] == "yes" + allow_downgrade = self._params["downgrade"] == "yes" # check the whole queue against downgrade directive if not allow_downgrade: allow_downgrade_give_ups = [] @@ -456,10 +456,10 @@ class PackageBuilder(object): c_repo, w_repo,)) print_warning("") - allow_spm_repo_change = self._params['spm-repository-change'] \ + allow_spm_repo_change = self._params["spm-repository-change"] \ == "yes" allow_spm_repo_change_if_ups = \ - self._params['spm-repository-change-if-upstreamed'] == "yes" + self._params["spm-repository-change-if-upstreamed"] == "yes" if (not allow_spm_repo_change) and allow_spm_repo_change_if_ups: print_info("SPM repository change allowed if the original " @@ -623,7 +623,7 @@ class PackageBuilder(object): # accept-properties just sets os.environ... build_args = [] build_args += PackageBuilder.PORTAGE_BUILTIN_ARGS - build_args += self._params['build-args'], + build_args += self._params["build-args"], build_args += ["=" + best_v for _x, best_v in packages] myaction, myopts, myfiles = parse_opts(build_args) @@ -720,7 +720,7 @@ class PackageBuilder(object): print_warning("failed package: %s::%s" % (failed_package.cpv, failed_package.repo,)) - if self._params['buildfail'] and (failed_package is not None): + if self._params["buildfail"] and (failed_package is not None): std_env = PackageBuilder._build_standard_environment( repository=self._params["repository"]) @@ -731,7 +731,7 @@ class PackageBuilder(object): std_env["MATTER_PORTAGE_BUILD_LOG_DIR"] = os.path.join(log_dir, "build") - buildfail = self._params['buildfail'] + buildfail = self._params["buildfail"] print_info("spawning buildfail: %s" % (buildfail,)) tmp_fd, tmp_path = mkstemp() with os.fdopen(tmp_fd, "wb") as tmp_f: @@ -759,7 +759,7 @@ class PackageBuilder(object): print_info("executing post-build operations, please wait...") builtin_args = PackageBuilder.PORTAGE_BUILTIN_ARGS _action, opts, _files = parse_opts( - builtin_args + spec['build-args']) + builtin_args + spec["build-args"]) unmerge(emerge_trees[emerge_settings["ROOT"]]["root_config"], opts, "clean", [], mtimedb["ldpath"], autoclean=1) diff --git a/matter/matter/main.py b/matter/matter/main.py index 2887115a4..bbeedc024 100644 --- a/matter/matter/main.py +++ b/matter/matter/main.py @@ -97,8 +97,8 @@ def matter_main(binary_pms, nsargs, cwd, specs): keep_going = spec["keep-going"] == "yes" local_completed = [] - tot_pkgs = len(spec['packages']) - for pkg_count, packages in enumerate(spec['packages'], 1): + tot_pkgs = len(spec["packages"]) + for pkg_count, packages in enumerate(spec["packages"], 1): builder = PackageBuilder( emerge_config, packages, @@ -131,7 +131,7 @@ def matter_main(binary_pms, nsargs, cwd, specs): local_completed.extend( [x for x in built_packages \ if x not in local_completed]) - tainted_repositories.add(spec['repository']) + tainted_repositories.add(spec["repository"]) # make some room print_info("") @@ -158,7 +158,7 @@ def matter_main(binary_pms, nsargs, cwd, specs): if local_completed and nsargs.commit: _rc = binary_pms.commit( - spec['repository'], + spec["repository"], local_completed) if exit_st == 0 and _rc != 0: exit_st = _rc @@ -272,13 +272,13 @@ Available Binary PMSs: for k in avail_binpms]),) parser = argparse.ArgumentParser( - description='Automated Packages Builder', + description="Automated Packages Builder", epilog=_env_vars_help, formatter_class=argparse.RawDescriptionHelpFormatter) # * instead of + in order to support --sync only tasks parser.add_argument( - "spec", nargs='+', metavar="", type=file, + "spec", nargs="+", metavar="", type=file, help="matter spec file") default_pms = avail_binpms[0] diff --git a/matter/matter/output.py b/matter/matter/output.py index df07205c2..8482430d7 100644 --- a/matter/matter/output.py +++ b/matter/matter/output.py @@ -21,24 +21,24 @@ from matter.utils import is_python3 stuff = {} -stuff['cols'] = 30 +stuff["cols"] = 30 try: curses.setupterm() - stuff['cols'] = curses.tigetnum('cols') + stuff["cols"] = curses.tigetnum("cols") except Exception: pass -stuff['cleanline'] = "" +stuff["cleanline"] = "" def setcols(): - stuff['cleanline'] = "" - count = stuff['cols'] + stuff["cleanline"] = "" + count = stuff["cols"] while count: - stuff['cleanline'] += ' ' + stuff["cleanline"] += " " count -= 1 setcols() -stuff['cursor'] = False -stuff['ESC'] = chr(27) +stuff["cursor"] = False +stuff["ESC"] = chr(27) havecolor=1 global dotitles @@ -110,9 +110,9 @@ for x in range(30, 38): ansi_color_codes.append("%im" % x) ansi_color_codes.append("%i;01m" % x) -rgb_ansi_colors = ['0x000000', '0x555555', '0xAA0000', '0xFF5555', '0x00AA00', - '0x55FF55', '0xAA5500', '0xFFFF55', '0x0000AA', '0x5555FF', '0xAA00AA', - '0xFF55FF', '0x00AAAA', '0x55FFFF', '0xAAAAAA', '0xFFFFFF'] +rgb_ansi_colors = ["0x000000", "0x555555", "0xAA0000", "0xFF5555", "0x00AA00", + "0x55FF55", "0xAA5500", "0xFFFF55", "0x0000AA", "0x5555FF", "0xAA00AA", + "0xFF55FF", "0x00AAAA", "0x55FFFF", "0xAAAAAA", "0xFFFFFF"] for x in range(len(rgb_ansi_colors)): codes[rgb_ansi_colors[x]] = esc_seq + ansi_color_codes[x] @@ -164,7 +164,7 @@ def nocolor(): """ Turn off colorization process-wide. """ - os.environ['MATTER_NO_COLOR'] = "1" + os.environ["MATTER_NO_COLOR"] = "1" global havecolor havecolor=0 @@ -369,7 +369,7 @@ def reset_cursor(): of the line. """ if havecolor: - sys.stdout.write(stuff['ESC'] + '[2K') + sys.stdout.write(stuff["ESC"] + "[2K") _flush_stdouterr() def _flush_stdouterr(): @@ -387,13 +387,13 @@ def _std_write(msg, stderr = False): try: obj.write(msg) except UnicodeEncodeError: - msg = msg.encode('utf-8') + msg = msg.encode("utf-8") if is_python3(): obj.buffer.write(msg) else: obj.write(msg) -def _print_prio(msg, color_func, back = False, flush = True, end = '\n', +def _print_prio(msg, color_func, back = False, flush = True, end = "\n", stderr = False): if not back: setcols() @@ -414,7 +414,7 @@ def _print_prio(msg, color_func, back = False, flush = True, end = '\n', if flush: _flush_stdouterr() -def print_error(msg, back = False, flush = True, end = '\n'): +def print_error(msg, back = False, flush = True, end = "\n"): """ Service function used by Entropy text client (will be moved from here) to write error messages to stdout (not stderr, atm). @@ -432,7 +432,7 @@ def print_error(msg, back = False, flush = True, end = '\n'): return _print_prio(msg, darkred, back = back, flush = flush, end = end, stderr = True) -def print_info(msg, back = False, flush = True, end = '\n'): +def print_info(msg, back = False, flush = True, end = "\n"): """ Service function used by Entropy text client (will be moved from here) to write info messages to stdout (not stderr, atm). @@ -449,7 +449,7 @@ def print_info(msg, back = False, flush = True, end = '\n'): """ return _print_prio(msg, darkgreen, back = back, flush = flush, end = end) -def print_warning(msg, back = False, flush = True, end = '\n'): +def print_warning(msg, back = False, flush = True, end = "\n"): """ Service function used by Entropy text client (will be moved from here) to write warning messages to stdout (not stderr, atm). @@ -473,7 +473,7 @@ def print_generic(*args, **kwargs): to write generic messages to stdout (not stderr, atm). NOTE: don't use this directly but rather subclass TextInterface class. """ - stderr = kwargs.get('stderr', False) + stderr = kwargs.get("stderr", False) msg_idx = 1 for msg in args: _std_write(msg, stderr = stderr) @@ -481,7 +481,7 @@ def print_generic(*args, **kwargs): sys.stdout.write(" ") msg_idx += 1 - end = kwargs.get('end', '\n') + end = kwargs.get("end", "\n") _std_write(end, stderr = stderr) _flush_stdouterr() diff --git a/matter/matter/spec.py b/matter/matter/spec.py index 45bbb525c..11b82b2e6 100644 --- a/matter/matter/spec.py +++ b/matter/matter/spec.py @@ -69,7 +69,7 @@ class GenericSpecFunctions(object): x = str(x) return x except (UnicodeDecodeError, UnicodeEncodeError,): - return '' + return "" def valid_yes_no(self, x): return x in ("yes", "no") @@ -130,128 +130,128 @@ class MatterSpec(GenericSpecFunctions): @rtype: dict """ return { - 'build-args': { - 'cb': self.ne_string, - 've': self.ve_string_shlex_splitter, - 'default': ["--verbose", "--nospinner"], - 'desc': "Portage build arguments (default is --verbose\n " + "build-args": { + "cb": self.ne_string, + "ve": self.ve_string_shlex_splitter, + "default": ["--verbose", "--nospinner"], + "desc": "Portage build arguments (default is --verbose\n " "--nospinner)", }, - 'dependencies': { - 'cb': self.valid_yes_no, - 've': self.ve_string_stripper, - 'default': "no", - 'desc': "Allow dependencies to be pulled in? (yes/no)", + "dependencies": { + "cb": self.valid_yes_no, + "ve": self.ve_string_stripper, + "default": "no", + "desc": "Allow dependencies to be pulled in? (yes/no)", }, - 'downgrade': { - 'cb': self.valid_yes_no, - 've': self.ve_string_stripper, - 'default': "no", - 'desc': "Allow package downgrades? (yes/no)", + "downgrade": { + "cb": self.valid_yes_no, + "ve": self.ve_string_stripper, + "default": "no", + "desc": "Allow package downgrades? (yes/no)", }, - 'keep-going': { - 'cb': self.valid_yes_no, - 've': self.ve_string_stripper, - 'default': "no", - 'desc': "Make possible to continue if one \n\t" + "keep-going": { + "cb": self.valid_yes_no, + "ve": self.ve_string_stripper, + "default": "no", + "desc": "Make possible to continue if one \n\t" "or more packages fail to build? (yes/no)", }, - 'new-useflags': { - 'cb': self.valid_yes_no, - 've': self.ve_string_stripper, - 'default': "no", - 'desc': "Allow new USE flags? (yes/no)", + "new-useflags": { + "cb": self.valid_yes_no, + "ve": self.ve_string_stripper, + "default": "no", + "desc": "Allow new USE flags? (yes/no)", }, - 'removed-useflags': { - 'cb': self.valid_yes_no, - 've': self.ve_string_stripper, - 'default': "no", - 'desc': "Allow removed USE flags? (yes/no)", + "removed-useflags": { + "cb": self.valid_yes_no, + "ve": self.ve_string_stripper, + "default": "no", + "desc": "Allow removed USE flags? (yes/no)", }, - 'rebuild': { - 'cb': self.valid_yes_no, - 've': self.ve_string_stripper, - 'default': "no", - 'desc': "Allow package rebuilds? (yes/no)", + "rebuild": { + "cb": self.valid_yes_no, + "ve": self.ve_string_stripper, + "default": "no", + "desc": "Allow package rebuilds? (yes/no)", }, - 'spm-repository-change': { - 'cb': self.valid_yes_no, - 've': self.ve_string_stripper, - 'default': "no", - 'desc': "Allow Source Package Manager (Portage) \n\t" + "spm-repository-change": { + "cb": self.valid_yes_no, + "ve": self.ve_string_stripper, + "default": "no", + "desc": "Allow Source Package Manager (Portage) \n\t" "repository change? (yes/no)", }, - 'spm-repository-change-if-upstreamed': { - 'cb': self.valid_yes_no, - 've': self.ve_string_stripper, - 'default': "no", - 'desc': "In case of Source Package Manager \n\trepository " + "spm-repository-change-if-upstreamed": { + "cb": self.valid_yes_no, + "ve": self.ve_string_stripper, + "default": "no", + "desc": "In case of Source Package Manager \n\trepository " "changes, allow execution if the original repository " "\n\tdoes not contain the package anymore? (yes/no)", }, - 'not-installed': { - 'cb': self.valid_yes_no, - 've': self.ve_string_stripper, - 'default': "no", - 'desc': "Allow compiling packages even if they " + "not-installed": { + "cb": self.valid_yes_no, + "ve": self.ve_string_stripper, + "default": "no", + "desc": "Allow compiling packages even if they " "are not \n\tactually installed on the System? (yes/no)", }, - 'soft-blocker': { - 'cb': self.valid_yes_no, - 've': self.ve_string_stripper, - 'default': "yes", - 'desc': "Allow soft-blockers in the merge queue?\n " + "soft-blocker": { + "cb": self.valid_yes_no, + "ve": self.ve_string_stripper, + "default": "yes", + "desc": "Allow soft-blockers in the merge queue?\n " "Packages will be unmerged if yes. (yes/no)", }, - 'unmerge': { - 'cb': self.valid_yes_no, - 've': self.ve_string_stripper, - 'default': "yes", - 'desc': "Allow package unmerges due to Portage\n " + "unmerge": { + "cb": self.valid_yes_no, + "ve": self.ve_string_stripper, + "default": "yes", + "desc": "Allow package unmerges due to Portage\n " "soft-blockers resolution. (yes/no)", }, - 'pkgpre': { - 'cb': self.not_none, - 've': self.ve_string_open_file_read, - 'default': None, - 'desc': "Package pre execution script hook path, " + "pkgpre": { + "cb": self.not_none, + "ve": self.ve_string_open_file_read, + "default": None, + "desc": "Package pre execution script hook path, " "executed \n\tfor each package (also see example files)", }, - 'pkgpost': { - 'cb': self.not_none, - 've': self.ve_string_open_file_read, - 'default': None, - 'desc': "Package build post execution script hook path, " + "pkgpost": { + "cb": self.not_none, + "ve": self.ve_string_open_file_read, + "default": None, + "desc": "Package build post execution script hook path, " "executed \n\tfor each package (also see example files)", }, - 'buildfail': { - 'cb': self.not_none, - 've': self.ve_string_open_file_read, - 'default': None, - 'desc': "Package build failure execution script hook " + "buildfail": { + "cb": self.not_none, + "ve": self.ve_string_open_file_read, + "default": None, + "desc": "Package build failure execution script hook " "path, \n\texecuted for each failing package (also see " "example files)", }, - 'packages': { - 'cb': self.always_valid, - 've': self.valid_comma_sep_list_list, - 'mod': lambda l_l: [x for x in l_l if x], - 'desc': "List of packages to scrape, separated by " + "packages": { + "cb": self.always_valid, + "ve": self.valid_comma_sep_list_list, + "mod": lambda l_l: [x for x in l_l if x], + "desc": "List of packages to scrape, separated by " "comma. \n\tIf you want to let Portage consider a group " "of packages, \n\tjust separate them with spaces/tabs but " "no commas", }, - 'repository': { - 'cb': self.ne_string, - 've': self.ve_string_stripper, - 'desc': "Binary Package Manager repository in where " + "repository": { + "cb": self.ne_string, + "ve": self.ve_string_stripper, + "desc": "Binary Package Manager repository in where " "newly built \n\tpackages will be put and pushed to", }, - 'stable': { - 'cb': self.valid_yes_no_inherit, - 've': self.ve_string_stripper, - 'default': "inherit", - 'desc': "Only accept Portage stable packages (no " + "stable": { + "cb": self.valid_yes_no_inherit, + "ve": self.ve_string_stripper, + "default": "inherit", + "desc": "Only accept Portage stable packages (no " "unstable keywords)", }, } @@ -308,7 +308,7 @@ class SpecPreprocessor: spec_f = self._spec_file_obj spec_f.seek(0) - lines = '' + lines = "" try: for line in spec_f.readlines(): # call recursively @@ -353,7 +353,7 @@ class SpecPreprocessor: line = expander(line) final_content.append(line) - final_content = (''.join(final_content)).split("\n") + final_content = ("".join(final_content)).split("\n") return final_content @@ -406,8 +406,8 @@ class SpecParser: check_dict = self._parser_data_path.get(key) if not isinstance(check_dict, dict): continue - value = check_dict['ve'](value) - if not check_dict['cb'](value): + value = check_dict["ve"](value) + if not check_dict["cb"](value): continue if key in mydict: @@ -445,7 +445,7 @@ class SpecParser: """ for statement, opts in self._parser_data_path.items(): if "default" in opts and (statement not in mydata): - mydata[statement] = opts['default'] + mydata[statement] = opts["default"] def _mod_parse(self, mydata): """ @@ -454,7 +454,7 @@ class SpecParser: """ for statement, opts in self._parser_data_path.items(): if statement in mydata and "mod" in opts: - mydata[statement] = opts['mod'](mydata[statement]) + mydata[statement] = opts["mod"](mydata[statement]) def _validate_parse(self, mydata): for param in self.vital_parameters: diff --git a/matter/matter/utils.py b/matter/matter/utils.py index 45cadb360..9dddcc0a2 100644 --- a/matter/matter/utils.py +++ b/matter/matter/utils.py @@ -79,7 +79,7 @@ def print_exception(silent=False, tb_data=None, all_frame_data=False): frame.f_code.co_filename, frame.f_lineno)) for key, value in list(frame.f_locals.items()): - cur_str = '' + cur_str = "" cur_str = "\t%20s = " % key try: cur_str += repr(value) + "\n" @@ -236,7 +236,7 @@ def convert_to_unicode(obj, enctype = _RAW_ENCODING): # string/unicode support if is_unicode(obj): return obj - if hasattr(obj, 'decode'): + if hasattr(obj, "decode"): return obj.decode(enctype) else: if is_python3():