mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
[mod] pep8
This commit is contained in:
parent
5bf2f46f47
commit
09f49e4a8a
4 changed files with 92 additions and 93 deletions
|
@ -213,5 +213,5 @@ class Authenticator(BaseAuthenticator):
|
||||||
attr, value)
|
attr, value)
|
||||||
raise MoulinetteError(errno.EEXIST,
|
raise MoulinetteError(errno.EEXIST,
|
||||||
m18n.g('ldap_attribute_already_exists',
|
m18n.g('ldap_attribute_already_exists',
|
||||||
attribute=attr, value=value))
|
attribute=attr, value=value))
|
||||||
return True
|
return True
|
||||||
|
|
|
@ -604,14 +604,14 @@ class ExtendedArgumentParser(argparse.ArgumentParser):
|
||||||
subcategories_subparser = copy.copy(action_group._group_actions[0])
|
subcategories_subparser = copy.copy(action_group._group_actions[0])
|
||||||
|
|
||||||
# Filter "action"-type and "subcategory"-type commands
|
# Filter "action"-type and "subcategory"-type commands
|
||||||
actions_subparser.choices = OrderedDict([(k,v) for k,v in actions_subparser.choices.items() if v.type == "action"])
|
actions_subparser.choices = OrderedDict([(k, v) for k, v in actions_subparser.choices.items() if v.type == "action"])
|
||||||
subcategories_subparser.choices = OrderedDict([(k,v) for k,v in subcategories_subparser.choices.items() if v.type == "subcategory"])
|
subcategories_subparser.choices = OrderedDict([(k, v) for k, v in subcategories_subparser.choices.items() if v.type == "subcategory"])
|
||||||
|
|
||||||
actions_choices = actions_subparser.choices.keys()
|
actions_choices = actions_subparser.choices.keys()
|
||||||
subcategories_choices = subcategories_subparser.choices.keys()
|
subcategories_choices = subcategories_subparser.choices.keys()
|
||||||
|
|
||||||
actions_subparser._choices_actions = [ c for c in choice_actions if c.dest in actions_choices ]
|
actions_subparser._choices_actions = [c for c in choice_actions if c.dest in actions_choices]
|
||||||
subcategories_subparser._choices_actions = [ c for c in choice_actions if c.dest in subcategories_choices ]
|
subcategories_subparser._choices_actions = [c for c in choice_actions if c.dest in subcategories_choices]
|
||||||
|
|
||||||
# Display each section (actions and subcategories)
|
# Display each section (actions and subcategories)
|
||||||
if actions_choices != []:
|
if actions_choices != []:
|
||||||
|
@ -648,98 +648,98 @@ class ExtendedArgumentParser(argparse.ArgumentParser):
|
||||||
class PositionalsFirstHelpFormatter(argparse.HelpFormatter):
|
class PositionalsFirstHelpFormatter(argparse.HelpFormatter):
|
||||||
|
|
||||||
def _format_usage(self, usage, actions, groups, prefix):
|
def _format_usage(self, usage, actions, groups, prefix):
|
||||||
if prefix is None:
|
if prefix is None:
|
||||||
# TWEAK : not using gettext here...
|
# TWEAK : not using gettext here...
|
||||||
prefix = 'usage: '
|
prefix = 'usage: '
|
||||||
|
|
||||||
# if usage is specified, use that
|
# if usage is specified, use that
|
||||||
if usage is not None:
|
if usage is not None:
|
||||||
usage = usage % dict(prog=self._prog)
|
usage = usage % dict(prog=self._prog)
|
||||||
|
|
||||||
# if no optionals or positionals are available, usage is just prog
|
# if no optionals or positionals are available, usage is just prog
|
||||||
elif usage is None and not actions:
|
elif usage is None and not actions:
|
||||||
usage = '%(prog)s' % dict(prog=self._prog)
|
usage = '%(prog)s' % dict(prog=self._prog)
|
||||||
|
|
||||||
# if optionals and positionals are available, calculate usage
|
# if optionals and positionals are available, calculate usage
|
||||||
elif usage is None:
|
elif usage is None:
|
||||||
prog = '%(prog)s' % dict(prog=self._prog)
|
prog = '%(prog)s' % dict(prog=self._prog)
|
||||||
|
|
||||||
# split optionals from positionals
|
# split optionals from positionals
|
||||||
optionals = []
|
optionals = []
|
||||||
positionals = []
|
positionals = []
|
||||||
for action in actions:
|
for action in actions:
|
||||||
if action.option_strings:
|
if action.option_strings:
|
||||||
optionals.append(action)
|
optionals.append(action)
|
||||||
|
else:
|
||||||
|
positionals.append(action)
|
||||||
|
|
||||||
|
# build full usage string
|
||||||
|
format = self._format_actions_usage
|
||||||
|
# TWEAK here : positionals first
|
||||||
|
action_usage = format(positionals + optionals, groups)
|
||||||
|
usage = ' '.join([s for s in [prog, action_usage] if s])
|
||||||
|
|
||||||
|
# wrap the usage parts if it's too long
|
||||||
|
text_width = self._width - self._current_indent
|
||||||
|
if len(prefix) + len(usage) > text_width:
|
||||||
|
|
||||||
|
# break usage into wrappable parts
|
||||||
|
part_regexp = r'\(.*?\)+|\[.*?\]+|\S+'
|
||||||
|
opt_usage = format(optionals, groups)
|
||||||
|
pos_usage = format(positionals, groups)
|
||||||
|
opt_parts = re.findall(part_regexp, opt_usage)
|
||||||
|
pos_parts = re.findall(part_regexp, pos_usage)
|
||||||
|
assert ' '.join(opt_parts) == opt_usage
|
||||||
|
assert ' '.join(pos_parts) == pos_usage
|
||||||
|
|
||||||
|
# helper for wrapping lines
|
||||||
|
def get_lines(parts, indent, prefix=None):
|
||||||
|
lines = []
|
||||||
|
line = []
|
||||||
|
if prefix is not None:
|
||||||
|
line_len = len(prefix) - 1
|
||||||
else:
|
else:
|
||||||
positionals.append(action)
|
line_len = len(indent) - 1
|
||||||
|
for part in parts:
|
||||||
# build full usage string
|
if line_len + 1 + len(part) > text_width:
|
||||||
format = self._format_actions_usage
|
|
||||||
# TWEAK here : positionals first
|
|
||||||
action_usage = format(positionals + optionals, groups)
|
|
||||||
usage = ' '.join([s for s in [prog, action_usage] if s])
|
|
||||||
|
|
||||||
# wrap the usage parts if it's too long
|
|
||||||
text_width = self._width - self._current_indent
|
|
||||||
if len(prefix) + len(usage) > text_width:
|
|
||||||
|
|
||||||
# break usage into wrappable parts
|
|
||||||
part_regexp = r'\(.*?\)+|\[.*?\]+|\S+'
|
|
||||||
opt_usage = format(optionals, groups)
|
|
||||||
pos_usage = format(positionals, groups)
|
|
||||||
opt_parts = re.findall(part_regexp, opt_usage)
|
|
||||||
pos_parts = re.findall(part_regexp, pos_usage)
|
|
||||||
assert ' '.join(opt_parts) == opt_usage
|
|
||||||
assert ' '.join(pos_parts) == pos_usage
|
|
||||||
|
|
||||||
# helper for wrapping lines
|
|
||||||
def get_lines(parts, indent, prefix=None):
|
|
||||||
lines = []
|
|
||||||
line = []
|
|
||||||
if prefix is not None:
|
|
||||||
line_len = len(prefix) - 1
|
|
||||||
else:
|
|
||||||
line_len = len(indent) - 1
|
|
||||||
for part in parts:
|
|
||||||
if line_len + 1 + len(part) > text_width:
|
|
||||||
lines.append(indent + ' '.join(line))
|
|
||||||
line = []
|
|
||||||
line_len = len(indent) - 1
|
|
||||||
line.append(part)
|
|
||||||
line_len += len(part) + 1
|
|
||||||
if line:
|
|
||||||
lines.append(indent + ' '.join(line))
|
lines.append(indent + ' '.join(line))
|
||||||
if prefix is not None:
|
line = []
|
||||||
lines[0] = lines[0][len(indent):]
|
line_len = len(indent) - 1
|
||||||
return lines
|
line.append(part)
|
||||||
|
line_len += len(part) + 1
|
||||||
|
if line:
|
||||||
|
lines.append(indent + ' '.join(line))
|
||||||
|
if prefix is not None:
|
||||||
|
lines[0] = lines[0][len(indent):]
|
||||||
|
return lines
|
||||||
|
|
||||||
# if prog is short, follow it with optionals or positionals
|
# if prog is short, follow it with optionals or positionals
|
||||||
if len(prefix) + len(prog) <= 0.75 * text_width:
|
if len(prefix) + len(prog) <= 0.75 * text_width:
|
||||||
indent = ' ' * (len(prefix) + len(prog) + 1)
|
indent = ' ' * (len(prefix) + len(prog) + 1)
|
||||||
# START TWEAK : pos_parts first, then opt_parts
|
# START TWEAK : pos_parts first, then opt_parts
|
||||||
if pos_parts:
|
if pos_parts:
|
||||||
lines = get_lines([prog] + pos_parts, indent, prefix)
|
lines = get_lines([prog] + pos_parts, indent, prefix)
|
||||||
lines.extend(get_lines(opt_parts, indent))
|
lines.extend(get_lines(opt_parts, indent))
|
||||||
elif opt_parts:
|
elif opt_parts:
|
||||||
lines = get_lines([prog] + opt_parts, indent, prefix)
|
lines = get_lines([prog] + opt_parts, indent, prefix)
|
||||||
# END TWEAK
|
# END TWEAK
|
||||||
else:
|
|
||||||
lines = [prog]
|
|
||||||
|
|
||||||
# if prog is long, put it on its own line
|
|
||||||
else:
|
else:
|
||||||
indent = ' ' * len(prefix)
|
lines = [prog]
|
||||||
parts = pos_parts + opt_parts
|
|
||||||
lines = get_lines(parts, indent)
|
|
||||||
if len(lines) > 1:
|
|
||||||
lines = []
|
|
||||||
# TWEAK here : pos_parts first, then opt_part
|
|
||||||
lines.extend(get_lines(pos_parts, indent))
|
|
||||||
lines.extend(get_lines(opt_parts, indent))
|
|
||||||
lines = [prog] + lines
|
|
||||||
|
|
||||||
# join lines into usage
|
# if prog is long, put it on its own line
|
||||||
usage = '\n'.join(lines)
|
else:
|
||||||
|
indent = ' ' * len(prefix)
|
||||||
|
parts = pos_parts + opt_parts
|
||||||
|
lines = get_lines(parts, indent)
|
||||||
|
if len(lines) > 1:
|
||||||
|
lines = []
|
||||||
|
# TWEAK here : pos_parts first, then opt_part
|
||||||
|
lines.extend(get_lines(pos_parts, indent))
|
||||||
|
lines.extend(get_lines(opt_parts, indent))
|
||||||
|
lines = [prog] + lines
|
||||||
|
|
||||||
# prefix with 'usage:'
|
# join lines into usage
|
||||||
return '%s%s\n\n' % (prefix, usage)
|
usage = '\n'.join(lines)
|
||||||
|
|
||||||
|
# prefix with 'usage:'
|
||||||
|
return '%s%s\n\n' % (prefix, usage)
|
||||||
|
|
|
@ -411,9 +411,9 @@ class _ActionsMapPlugin(object):
|
||||||
raise e
|
raise e
|
||||||
import traceback
|
import traceback
|
||||||
tb = traceback.format_exc()
|
tb = traceback.format_exc()
|
||||||
logs = { "route": _route,
|
logs = {"route": _route,
|
||||||
"arguments": arguments,
|
"arguments": arguments,
|
||||||
"traceback": tb }
|
"traceback": tb}
|
||||||
return HTTPErrorResponse(json_encode(logs))
|
return HTTPErrorResponse(json_encode(logs))
|
||||||
else:
|
else:
|
||||||
return format_for_response(ret)
|
return format_for_response(ret)
|
||||||
|
|
|
@ -317,7 +317,6 @@ class ActionsMapParser(BaseActionsMapParser):
|
||||||
|
|
||||||
self.global_parser.add_argument(*names, **argument_options)
|
self.global_parser.add_argument(*names, **argument_options)
|
||||||
|
|
||||||
|
|
||||||
def parse_args(self, args, **kwargs):
|
def parse_args(self, args, **kwargs):
|
||||||
try:
|
try:
|
||||||
ret = self._parser.parse_args(args)
|
ret = self._parser.parse_args(args)
|
||||||
|
|
Loading…
Add table
Reference in a new issue