Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Formats commands.py to use PEP8 #62

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 20 additions & 15 deletions mailpile/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ class Command:
TEMPLATE_IDS = ['command']

class CommandResult:
__str__ = lambda self: self.as_text()
__unicode__ = lambda self: self.as_text()

def __init__(self, session, command, template_ids, doc, result):
self.session = session
self.command = command
Expand All @@ -43,11 +46,9 @@ def __nonzero__(self):
return self.result.__nonzero__()

def as_text(self):
if type(self.result) == type(True):
if isinstance(self.result, bool):
return '%s: %s' % (self.result and 'Succeeded' or 'Failed', self.doc)
return unicode(self.result)
__str__ = lambda self: self.as_text()
__unicode__ = lambda self: self.as_text()

def as_dict(self):
return {
Expand All @@ -71,7 +72,7 @@ def __init__(self, session, name=None, arg=None, data=None):
self.name = name
self.data = data or {}
self.result = None
if type(arg) in (type(list()), type(tuple())):
if isinstance(arg, (list, tuple)):
self.args = list(arg)
elif arg:
if self.SPLIT_ARG:
Expand All @@ -97,6 +98,7 @@ def __do_load():
if not wait:
session.ui.reset_marks(quiet=quiet)
return idx

if wait:
return config.slow_worker.do(session, 'Load', __do_load)
else:
Expand Down Expand Up @@ -172,14 +174,15 @@ def _run(self, *args, **kwargs):
try:
def command(self, *args, **kwargs):
return self.command(*args, **kwargs)

if self.SUBCOMMANDS and self.args and self.args[0] in self.SUBCOMMANDS:
subcmd = self.args.pop(0)
for i in range(0, len(self.template_ids)):
self.template_ids[i] += '_' + subcmd
if self.name:
self.name += ' ' + subcmd
command = self.SUBCOMMANDS[subcmd][0]
elif self.SUBCOMMANDS and self.args and self.args[0] == 'help':
elif self.SUBCOMMANDS and self.args and self.args[0] is 'help':
if not self.IS_HELP:
return Help(self.session, arg=[self.name]).run()
self._starting()
Expand Down Expand Up @@ -235,7 +238,8 @@ def command(self):
subprocess.check_call(pre_command, shell=True)
count = 1
for fid, fpath in config.get_mailboxes():
if mailpile.util.QUITTING: break
if mailpile.util.QUITTING:
break
count += idx.scan_mailbox(session, fid, fpath, config.open_mailbox)
config.clear_mbox_cache()
session.ui.mark('\n')
Expand Down Expand Up @@ -356,8 +360,7 @@ def command(self):
arg = os.path.abspath(fn)
else:
return self._error('No such file/directory: %s' % raw_fn)
if config.parse_set(session,
'mailbox:%s=%s' % (config.nid('mailbox'), fn)):
if config.parse_set(session,'mailbox:%s=%s' % (config.nid('mailbox'), fn)):
self._serialize('Save config', lambda: config.save())
return True

Expand All @@ -384,10 +387,8 @@ class CommandResult(Command.CommandResult):
def splash_as_text(self):
return '\n'.join([
self.result['splash'],
'The web interface is %s' % (self.result['http_url'] or 'disabled.'),
'',
'For instructions, type `help`, press <CTRL-D> to quit.',
''
'The web interface is %s' % (self.result['http_url'] or 'disabled.\n'),
'For instructions, type `help`, press <CTRL-D> to quit.\n',
])
def variables_as_text(self):
text = []
Expand All @@ -410,8 +411,10 @@ def commands_as_text(self):
ckeys.sort(key=lambda k: cmds[k][3])
for c in ckeys:
cmd, args, explanation, rank = cmds[c]
if not rank: continue
if last_rank and int(rank/10) != last_rank: text.append('')
if not rank:
continue
if last_rank and int(rank/10) != last_rank:
text.append('')
last_rank = int(rank/10)
if c[0] == '_':
c = ' '
Expand Down Expand Up @@ -512,7 +515,9 @@ def help_splash(self):
'http_url': http_url,
}

def _starting(self): pass
def _starting(self):
pass

def _finishing(self, command, rv):
return self.CommandResult(self.session, self.name, self.template_ids,
command.__doc__ or self.__doc__, rv)
Expand Down