aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Harder <radhermit@gmail.com>2015-07-04 17:02:25 -0400
committerTim Harder <radhermit@gmail.com>2015-07-04 17:02:25 -0400
commit31f64ef25f42e1e19d2fbecce3bbafe0f775de45 (patch)
treed03250d83353ab96b85db597af82e4c0206188fc
parentcommandline: add --override-config option (diff)
downloadpkgcore-31f64ef25f42e1e19d2fbecce3bbafe0f775de45.tar.gz
pkgcore-31f64ef25f42e1e19d2fbecce3bbafe0f775de45.tar.bz2
pkgcore-31f64ef25f42e1e19d2fbecce3bbafe0f775de45.zip
whitespace consistency
-rw-r--r--pkgcore/util/commandline.py117
-rw-r--r--pkgcore/util/file_type.py5
-rw-r--r--pkgcore/util/parserestrict.py25
-rw-r--r--pkgcore/util/repo_utils.py1
-rw-r--r--pkgcore/util/thread_pool.py14
5 files changed, 98 insertions, 64 deletions
diff --git a/pkgcore/util/commandline.py b/pkgcore/util/commandline.py
index 407c8d7f..e93613ec 100644
--- a/pkgcore/util/commandline.py
+++ b/pkgcore/util/commandline.py
@@ -127,7 +127,8 @@ class Delayed(argparse.Action):
self.priority = int(priority)
self.target = target(option_strings=option_strings, dest=dest, **kwds.copy())
- super(Delayed, self).__init__(option_strings=option_strings[:],
+ super(Delayed, self).__init__(
+ option_strings=option_strings[:],
dest=dest, nargs=kwds.get("nargs", None), required=kwds.get("required", None),
help=kwds.get("help", None), metavar=kwds.get("metavar", None))
@@ -143,8 +144,8 @@ CONFIG_ALL_DEFAULT = object()
class EnableDebug(argparse._StoreTrueAction):
def __call__(self, parser, namespace, values, option_string=None):
- super(EnableDebug, self).__call__(parser, namespace, values,
- option_string=option_string)
+ super(EnableDebug, self).__call__(
+ parser, namespace, values, option_string=option_string)
logging.root.setLevel(logging.DEBUG)
@@ -202,8 +203,8 @@ class StoreConfigObject(argparse._StoreAction):
(metavar, name, available))
if self.writable and getattr(val, 'frozen', False):
- raise argparse.ArgumentError(self, "%s%r is readonly" %
- (metavar, name))
+ raise argparse.ArgumentError(
+ self, "%s%r is readonly" % (metavar, name))
if self.store_name:
return name, val
@@ -275,10 +276,10 @@ class StoreConfigObject(argparse._StoreAction):
try:
obj = getattr(namespace.config, config_type)[key]
except KeyError:
- raise ConfigError("Failed loading object %s of type %s"
- % (config_type, key))
- raise argparse.ArgumentError(self, "couldn't find %s %r" %
- (self.config_type, name))
+ raise ConfigError(
+ "Failed loading object %s of type %s" % (config_type, key))
+ raise argparse.ArgumentError(
+ self, "couldn't find %s %r" % (self.config_type, name))
setattr(namespace, attr, obj)
@@ -286,7 +287,8 @@ class StoreRepoObject(StoreConfigObject):
def __init__(self, *args, **kwargs):
if 'config_type' in kwargs:
- raise ValueError("StoreRepoObject: config_type keyword is redundant: got %s"
+ raise ValueError(
+ "StoreRepoObject: config_type keyword is redundant: got %s"
% (kwargs['config_type'],))
self.raw = kwargs.pop("raw", False)
self.domain_forced = 'domain' in kwargs
@@ -348,7 +350,8 @@ class DomainFromPath(StoreConfigObject):
if not targets:
raise ValueError("couldn't find domain at path %r" % (requested_path,))
elif len(targets) != 1:
- raise ValueError("multiple domains claim root %r: domains %s" %
+ raise ValueError(
+ "multiple domains claim root %r: domains %s" %
(requested_path, ', '.join(repr(x[0]) for x in targets)))
return targets[0][1]
@@ -422,11 +425,13 @@ class BooleanQuery(DelayedValue):
elif callable(klass_type):
self.klass = klass
else:
- raise ValueError("klass_type either needs to be 'or', 'and', "
+ raise ValueError(
+ "klass_type either needs to be 'or', 'and', "
"or a callable. Got %r" % (klass_type,))
if converter is not None and not callable(converter):
- raise ValueError("converter either needs to be None, or a callable;"
+ raise ValueError(
+ "converter either needs to be None, or a callable;"
" got %r" % (converter,))
self.converter = converter
@@ -470,16 +475,16 @@ def make_query(parser, *args, **kwargs):
else:
kwargs.setdefault("type", parse_restriction)
kwargs.setdefault("metavar", dest)
- final_priority = kwargs.pop("final_priority", None)
+ final_priority = kwargs.pop("final_priority", None)
final_converter = kwargs.pop("final_converter", None)
parser.add_argument(*args, **kwargs)
- bool_kwargs = {'converter':final_converter}
+ bool_kwargs = {'converter': final_converter}
if final_priority is not None:
bool_kwargs['priority'] = final_priority
obj = BooleanQuery(list(attrs) + [subattr], klass_type=klass_type, **bool_kwargs)
# note that dict expansion has to be used here; dest=obj would just set a
# default named 'dest'
- parser.set_defaults(**{dest:obj})
+ parser.set_defaults(**{dest: obj})
class Expansion(argparse.Action):
@@ -489,7 +494,8 @@ class Expansion(argparse.Action):
if subst is None:
raise TypeError("resultant_string must be set")
- super(Expansion, self).__init__(option_strings=option_strings,
+ super(Expansion, self).__init__(
+ option_strings=option_strings,
dest=dest,
help=help,
required=required,
@@ -506,7 +512,7 @@ class Expansion(argparse.Action):
dvals = {str(idx): val for idx, val in enumerate(vals)}
dvals['*'] = ' '.join(vals)
- for action in parser._actions:
+ for action in actions:
action_map.update((option, action) for option in action.option_strings)
for chunk in self.subst:
@@ -514,7 +520,9 @@ class Expansion(argparse.Action):
action = action_map.get(option)
args = [x % dvals for x in args]
if not action:
- raise ValueError("unable to find option %r for %r" (option, self.option_strings))
+ raise ValueError(
+ "unable to find option %r for %r" %
+ (option, self.option_strings))
if action.type is not None:
args = map(action.type, args)
if action.nargs in (1, None):
@@ -545,7 +553,7 @@ def python_namespace_type(value, module=False, attribute=False):
class _SubParser(argparse._SubParsersAction):
def add_parser(self, name, **kwds):
- """modified version of argparse._SubParsersAction, linking description/help if one is specified"""
+ """argparser subparser that links description/help if one is specified"""
description = kwds.get("description")
help_txt = kwds.get("help")
if description is None:
@@ -600,7 +608,8 @@ class ArgumentParser(argparse.ArgumentParser):
conflict_handler='error',
add_help=True):
- super(ArgumentParser, self).__init__(prog=prog, usage=usage,
+ super(ArgumentParser, self).__init__(
+ prog=prog, usage=usage,
description=description, epilog=epilog,
parents=parents, formatter_class=formatter_class,
prefix_chars=prefix_chars, fromfile_prefix_chars=fromfile_prefix_chars,
@@ -624,15 +633,15 @@ class ArgumentParser(argparse.ArgumentParser):
# just work.
i = ((attr, val) for attr, val in args.__dict__.iteritems()
- if isinstance(val, DelayedDefault))
- for attr, functor in sorted(i, key=lambda val:val[1].priority):
+ if isinstance(val, DelayedDefault))
+ for attr, functor in sorted(i, key=lambda val: val[1].priority):
functor(args, attr)
# now run the delays.
i = ((attr, val) for attr, val in args.__dict__.iteritems()
- if isinstance(val, DelayedValue))
+ if isinstance(val, DelayedValue))
try:
- for attr, delayed in sorted(i, key=lambda val:val[1].priority):
+ for attr, delayed in sorted(i, key=lambda val: val[1].priority):
delayed(args, attr)
except (TypeError, ValueError) as err:
self.error("failed loading/parsing %s: %s" % (attr, str(err)))
@@ -652,7 +661,8 @@ class ArgumentParser(argparse.ArgumentParser):
def bind_class(self, obj):
if not isinstance(obj, ArgparseCommand):
- raise ValueError("expected obj to be an instance of "
+ raise ValueError(
+ "expected obj to be an instance of "
"ArgparseCommand; got %r" % (obj,))
obj.bind_to_parser(self)
return self
@@ -661,7 +671,7 @@ class ArgumentParser(argparse.ArgumentParser):
def f(functor, name=name):
if name is None:
name = functor.__name__
- self.set_defaults(**{name:DelayedValue(functor, priority)})
+ self.set_defaults(**{name: DelayedValue(functor, priority)})
return functor
return f
@@ -682,6 +692,7 @@ class ArgparseCommand(object):
def __call__(self, namespace, out, err):
raise NotImplementedError(self, '__call__')
+
def register_command(commands, real_type=type):
def f(name, bases, scope, real_type=real_type, commands=commands):
o = real_type(name, bases, scope)
@@ -689,6 +700,7 @@ def register_command(commands, real_type=type):
return o
return f
+
def _convert_config_mods(iterable):
d = {}
if iterable is None:
@@ -697,9 +709,10 @@ def _convert_config_mods(iterable):
d.setdefault(section, {})[key] = value
return d
+
def store_config(namespace, attr):
- configs = map(_convert_config_mods,
- [namespace.new_config, namespace.add_config])
+ configs = map(
+ _convert_config_mods, [namespace.new_config, namespace.add_config])
# add necessary inherits for add_config
for key, vals in configs[1].iteritems():
vals.setdefault('inherit', key)
@@ -717,10 +730,12 @@ def store_config(namespace, attr):
def _mk_domain(parser):
- parser.add_argument('--domain', get_default=True, config_type='domain',
+ parser.add_argument(
+ '--domain', get_default=True, config_type='domain',
action=StoreConfigObject,
help="domain to use for this operation")
+
def existent_path(value):
if not os.path.exists(value):
raise ValueError("path %r doesn't exist on disk" % (value,))
@@ -728,9 +743,11 @@ def existent_path(value):
return osutils.abspath(value)
except EnvironmentError as e:
compatibility.raise_from(
- ValueError("while resolving path %r, encountered error: %r" %
+ ValueError(
+ "while resolving path %r, encountered error: %r" %
(value, e)))
+
def mk_argparser(suppress=False, config=True, domain=True,
color=True, debug=True, version=True, **kwds):
p = ArgumentParser(**kwds)
@@ -742,22 +759,28 @@ def mk_argparser(suppress=False, config=True, domain=True,
if version:
p.add_argument('--version', action='version', version=get_version())
if debug:
- p.add_argument('--debug', action=EnableDebug, help="Enable debugging checks")
+ p.add_argument(
+ '--debug', action=EnableDebug, help="Enable debugging checks")
if color:
- p.add_argument('--color', action=StoreBool,
+ p.add_argument(
+ '--color', action=StoreBool,
default=True,
help="Enable or disable color support.")
if config:
- p.add_argument('--add-config', nargs=3, action='append',
+ p.add_argument(
+ '--add-config', nargs=3, action='append',
metavar=("SECTION", "KEY", "VALUE"),
help="modify an existing configuration section.")
- p.add_argument('--new-config', nargs=3, action='append',
+ p.add_argument(
+ '--new-config', nargs=3, action='append',
metavar=("SECTION", "KEY", "VALUE"),
help="add a new configuration section.")
- p.add_argument('--empty-config', action='store_true', default=False,
+ p.add_argument(
+ '--empty-config', action='store_true', default=False,
help="Do not load user/system configuration.")
- p.add_argument('--override-config', metavar="PATH",
+ p.add_argument(
+ '--override-config', metavar="PATH",
help="Override location of config files")
p.set_defaults(config=DelayedValue(store_config, 0))
@@ -771,11 +794,13 @@ def argparse_parse(parser, args, namespace=None):
namespace = parser.parse_args(args, namespace=namespace)
main = getattr(namespace, 'main_func', None)
if main is None:
- raise Exception("parser %r lacks a main method- internal bug.\nGot namespace %r\n"
+ raise Exception(
+ "parser %r lacks a main method- internal bug.\nGot namespace %r\n"
% (parser, namespace))
namespace.prog = parser.prog
return main, namespace
+
def convert_to_restrict(sequence, default=packages.AlwaysTrue):
"""Convert an iterable to a list of atoms, or return the default"""
l = []
@@ -784,8 +809,8 @@ def convert_to_restrict(sequence, default=packages.AlwaysTrue):
l.append(parserestrict.parse_match(x))
except parserestrict.ParseError as e:
compatibility.raise_from(
- optparse.OptionValueError("arg %r isn't a valid atom: %s"
- % (x, e)))
+ optparse.OptionValueError(
+ "arg %r isn't a valid atom: %s" % (x, e)))
return l or [default]
@@ -842,8 +867,8 @@ def main(subcommands, args=None, outfile=None, errfile=None, script_name=None):
if out_fd is not None and err_fd is not None:
out_stat, err_stat = os.fstat(out_fd), os.fstat(err_fd)
if out_stat.st_dev == err_stat.st_dev \
- and out_stat.st_ino == err_stat.st_ino and \
- not errfile.isatty():
+ and out_stat.st_ino == err_stat.st_ino and \
+ not errfile.isatty():
# they're the same underlying fd. thus
# point the handles at the same so we don't
# get intermixed buffering issues.
@@ -853,8 +878,8 @@ def main(subcommands, args=None, outfile=None, errfile=None, script_name=None):
exitstatus = -10
try:
if isinstance(subcommands, dict):
- main_func, options = optparse_parse(subcommands, args=args, script_name=script_name,
- errfile=errfile)
+ main_func, options = optparse_parse(
+ subcommands, args=args, script_name=script_name, errfile=errfile)
else:
options = argparse.Namespace()
main_func, options = argparse_parse(subcommands, args, options)
@@ -900,6 +925,7 @@ def main(subcommands, args=None, outfile=None, errfile=None, script_name=None):
out.title('%s succeeded' % (options.prog,))
raise MySystemExit(exitstatus)
+
def dump_error(handle, raw_exc, context_msg=None, tb=None):
prefix = ''
if context_msg:
@@ -912,7 +938,8 @@ def dump_error(handle, raw_exc, context_msg=None, tb=None):
exc_strings = []
if raw_exc is not None:
for exc in walk_exception_chain(raw_exc):
- exc_strings.extend('%s%s' % (prefix, x.strip())
+ exc_strings.extend(
+ '%s%s' % (prefix, x.strip())
for x in filter(None, str(exc).split("\n")))
if exc_strings:
handle.write("\n".join(exc_strings))
diff --git a/pkgcore/util/file_type.py b/pkgcore/util/file_type.py
index f34d7260..2f099de7 100644
--- a/pkgcore/util/file_type.py
+++ b/pkgcore/util/file_type.py
@@ -46,7 +46,8 @@ class file_identifier(object):
def _fallback_file(path):
ret, out = spawn_get_output(["file", path])
if ret != 0:
- raise ValueError("file output was non zero- ret:%r out:%r" %
+ raise ValueError(
+ "file output was non zero- ret:%r out:%r" %
(ret, out))
out = ''.join(out)
if out.startswith(path):
@@ -54,5 +55,3 @@ class file_identifier(object):
if out.startswith(":"):
out = out[1:]
return out
-
-
diff --git a/pkgcore/util/parserestrict.py b/pkgcore/util/parserestrict.py
index cd92f204..77474bda 100644
--- a/pkgcore/util/parserestrict.py
+++ b/pkgcore/util/parserestrict.py
@@ -14,7 +14,8 @@ import re
from snakeoil.compatibility import raise_from, is_py3k
from pkgcore.ebuild import atom, cpv, errors, restricts
-from pkgcore.restrictions import packages, values, util
+from pkgcore.restrictions import packages, values
+from pkgcore.restrictions.util import collect_package_restrictions
valid_globbing = re.compile(r"^(?:[\w+-.]+|(?<!\*)\*)+$").match
@@ -32,8 +33,8 @@ def comma_separated_containment(attr, values_kls=frozenset, token_kls=str):
have any of those values in the attribute passed to this function.
"""
def _parse(value):
- return packages.PackageRestriction(attr,
- values.ContainmentMatch2(
+ return packages.PackageRestriction(
+ attr, values.ContainmentMatch2(
values_kls(token_kls(piece.strip()) for piece in value.split(','))
)
)
@@ -46,17 +47,20 @@ def convert_glob(token):
elif '*' not in token:
return values.StrExactMatch(token)
elif not valid_globbing(token):
- raise ParseError("globs must be composed of [\w-.+], with optional "
+ raise ParseError(
+ "globs must be composed of [\w-.+], with optional "
"'*'- '%s' is disallowed however" % token)
pattern = "^%s$" % (re.escape(token).replace("\*", ".*"),)
return values.StrRegex(pattern, match=True)
+
def collect_ops(text):
i = 0
while i < len(text) and text[i] in ("<", "=", ">", "~"):
i += 1
return text[0:i], text[i:]
+
def parse_match(text):
"""generate appropriate restriction for text
@@ -116,9 +120,9 @@ def parse_match(text):
orig_text,))
# ok... fake category. whee.
try:
- r = list(util.collect_package_restrictions(
- atom.atom("%scategory/%s" % (ops, text)).restrictions,
- attrs=("category",), invert=True))
+ r = list(collect_package_restrictions(
+ atom.atom("%scategory/%s" % (ops, text)).restrictions,
+ attrs=("category",), invert=True))
except errors.MalformedAtom as e:
raise_from(ParseError(str(e)))
if len(r) == 1:
@@ -163,8 +167,9 @@ def parse_pv(repo, text):
result = None
for match in repo.itermatch(restrict):
if result is not None:
- raise ParseError('multiple matches for %s (%s, %s)' % (
- text, result.cpvstr, match.cpvstr))
+ raise ParseError(
+ 'multiple matches for %s (%s, %s)' %
+ (text, result.cpvstr, match.cpvstr))
result = match
if result is None:
raise ParseError('no matches for %s' % (text,))
@@ -173,4 +178,4 @@ def parse_pv(repo, text):
parse_funcs = {
'match': parse_match,
- }
+}
diff --git a/pkgcore/util/repo_utils.py b/pkgcore/util/repo_utils.py
index ded1e2c5..7520fa67 100644
--- a/pkgcore/util/repo_utils.py
+++ b/pkgcore/util/repo_utils.py
@@ -27,6 +27,7 @@ def get_raw_repos(repo):
return l
return [repo]
+
def get_virtual_repos(repo, sentinel=True):
"""
select only virtual repos
diff --git a/pkgcore/util/thread_pool.py b/pkgcore/util/thread_pool.py
index 83dcbdef..facceaf9 100644
--- a/pkgcore/util/thread_pool.py
+++ b/pkgcore/util/thread_pool.py
@@ -11,6 +11,7 @@ demandload(
'snakeoil.process:get_proc_count',
)
+
def reclaim_threads(threads):
for x in threads:
try:
@@ -21,9 +22,10 @@ def reclaim_threads(threads):
# should do something better here
pass
+
def map_async(iterable, functor, *args, **kwds):
- per_thread_args = kwds.pop("per_thread_args", lambda:())
- per_thread_kwds = kwds.pop("per_thread_kwds", lambda:{})
+ per_thread_args = kwds.pop("per_thread_args", lambda: ())
+ per_thread_kwds = kwds.pop("per_thread_kwds", lambda: {})
parallelism = kwds.pop("threads", None)
if parallelism is None:
parallelism = get_proc_count()
@@ -33,13 +35,13 @@ def map_async(iterable, functor, *args, **kwds):
# spawn pointless threads.
parallelism = max(min(len(iterable), parallelism), 0)
- # note we allow an infinite queue since .put below
- # is blocking, and won't return till it succeeds (regardless of signal)
- # as such, we do it this way to ensure the put succeeds, then the keyboardinterrupt
- # can be seen.
+ # note we allow an infinite queue since .put below is blocking, and won't
+ # return till it succeeds (regardless of signal) as such, we do it this way
+ # to ensure the put succeeds, then the keyboardinterrupt can be seen.
queue = Queue.Queue()
kill = threading.Event()
kill.clear()
+
def iter_queue(kill, qlist, empty_signal):
while not kill.isSet():
item = qlist.get()