diff options
author | Patrick Totzke <patricktotzke@gmail.com> | 2011-10-13 19:53:49 +0100 |
---|---|---|
committer | Patrick Totzke <patricktotzke@gmail.com> | 2011-10-13 19:53:49 +0100 |
commit | df06f6019df34fabfc0748744e67d27d62a2a75d (patch) | |
tree | e44cefb4ccaedacba336cec1728caa2043cf2bfa /alot/commands | |
parent | 897820c419d68fe38e160f03f0374c703a752183 (diff) |
imports and pep8
Diffstat (limited to 'alot/commands')
-rw-r--r-- | alot/commands/__init__.py | 55 | ||||
-rw-r--r-- | alot/commands/envelope.py | 28 | ||||
-rw-r--r-- | alot/commands/globals.py | 28 | ||||
-rw-r--r-- | alot/commands/search.py | 14 | ||||
-rw-r--r-- | alot/commands/taglist.py | 9 | ||||
-rw-r--r-- | alot/commands/thread.py | 30 |
6 files changed, 67 insertions, 97 deletions
diff --git a/alot/commands/__init__.py b/alot/commands/__init__.py index 3a6bbe31..c67ad2a2 100644 --- a/alot/commands/__init__.py +++ b/alot/commands/__init__.py @@ -1,31 +1,8 @@ import os -#import re -#import code import glob import logging -#import threading -#import subprocess -#import shlex -#import email -#import tempfile -#from email import Charset -#from email.header import Header -#from email.mime.text import MIMEText -#from email.mime.multipart import MIMEMultipart -#import urwid -# -#import buffer -import settings -#import widgets -#import completion -#import helper -#from db import DatabaseROError -#from db import DatabaseLockedError -#from completion import ContactsCompleter -#from completion import AccountCompleter -#from message import decode_to_unicode -#from message import decode_header -#from message import encode_header + +import alot.settings class Command(object): @@ -41,18 +18,12 @@ class Command(object): COMMANDS = { - 'search': { - }, - 'envelope': { - }, - 'bufferlist': { - }, - 'taglist': { - }, - 'thread': { - }, - 'global': { - } + 'search': {}, + 'envelope': {}, + 'bufferlist': {}, + 'taglist': {}, + 'thread': {}, + 'global': {}, } @@ -66,6 +37,7 @@ class registerCommand(object): COMMANDS[self.mode][self.name] = (klass, self.defaultparms) return klass + def register(klass): COMMANDS['classes'] = klass return klass @@ -86,8 +58,8 @@ def commandfactory(cmdname, mode='global', **kwargs): else: parms[key] = value - parms['prehook'] = settings.hooks.get('pre_' + cmdname) - parms['posthook'] = settings.hooks.get('post_' + cmdname) + parms['prehook'] = alot.settings.hooks.get('pre_' + cmdname) + parms['posthook'] = alot.settings.hooks.get('post_' + cmdname) logging.debug('cmd parms %s' % parms) return cmdclass(**parms) @@ -106,8 +78,8 @@ def interpret_commandline(cmdline, mode): params = '' # unfold aliases - if settings.config.has_option('command-aliases', cmd): - cmd = settings.config.get('command-aliases', cmd) + if alot.settings.config.has_option('command-aliases', cmd): + cmd = alot.settings.config.get('command-aliases', cmd) # allow to shellescape without a space after '!' if cmd.startswith('!'): @@ -190,5 +162,4 @@ def interpret_commandline(cmdline, mode): return None - __all__ = list(filename[:-3] for filename in glob.glob1(os.path.dirname(__file__), '*.py')) diff --git a/alot/commands/envelope.py b/alot/commands/envelope.py index 601372a7..f37195db 100644 --- a/alot/commands/envelope.py +++ b/alot/commands/envelope.py @@ -1,6 +1,3 @@ -from commands import Command, registerCommand -from twisted.internet import defer - import os import re import glob @@ -8,17 +5,22 @@ import logging import email import tempfile from email import Charset +from twisted.internet import defer -import settings -import helper -from message import decode_to_unicode -from message import decode_header -from message import encode_header -import commands +from alot.commands import Command, registerCommand +from alot import settings +from alot import helper +from alot.message import decode_to_unicode +from alot.message import decode_header +from alot.message import encode_header +from alot.commands.globals import EditCommand +from alot.commands.globals import BufferCloseCommand +from alot.commands.globals import EnvelopeOpenCommand MODE = 'envelope' + @registerCommand(MODE, 'attach', {}) class EnvelopeAttachCommand(Command): def __init__(self, path=None, mail=None, **kwargs): @@ -47,6 +49,7 @@ class EnvelopeAttachCommand(Command): if not self.mail: # set the envelope msg iff we got it from there ui.current_buffer.set_email(msg) + @registerCommand(MODE, 'refine', {}) class EnvelopeRefineCommand(Command): """prompt to change current value of header field""" @@ -91,7 +94,7 @@ class EnvelopeSendCommand(Command): reason = account.send_mail(mail) ui.clear_notify([clearme]) if not reason: # sucessfully send mail - cmd = commands.globals.BufferCloseCommand(buffer=envelope) + cmd = BufferCloseCommand(buffer=envelope) ui.apply_command(cmd) ui.notify('mail send successful') else: @@ -158,7 +161,7 @@ class EnvelopeEditCommand(Command): f.close() os.unlink(tf.name) if self.openNew: - ui.apply_command(commands.globals.EnvelopeOpenCommand(mail=self.mail)) + ui.apply_command(EnvelopeOpenCommand(mail=self.mail)) else: ui.current_buffer.set_email(self.mail) @@ -193,7 +196,7 @@ class EnvelopeEditCommand(Command): tf.write(content.encode('utf-8')) tf.flush() tf.close() - cmd = commands.globals.EditCommand(tf.name, on_success=openEnvelopeFromTmpfile, + cmd = EditCommand(tf.name, on_success=openEnvelopeFromTmpfile, refocus=False) ui.apply_command(cmd) @@ -215,4 +218,3 @@ class EnvelopeSetCommand(Command): del(mail[self.key]) mail[self.key] = self.value envelope.rebuild() - diff --git a/alot/commands/globals.py b/alot/commands/globals.py index 881a1d2b..877071e3 100644 --- a/alot/commands/globals.py +++ b/alot/commands/globals.py @@ -1,6 +1,3 @@ -from commands import Command, registerCommand -from twisted.internet import defer - import os import code import threading @@ -10,19 +7,22 @@ import email from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart import urwid +from twisted.internet import defer -import buffers -import settings -import widgets -import helper -from db import DatabaseLockedError -from completion import ContactsCompleter -from completion import AccountCompleter -from message import encode_header -import commands +from alot.commands import Command, registerCommand +from alot import buffers +from alot import settings +from alot import widgets +from alot import helper +from alot.db import DatabaseLockedError +from alot.completion import ContactsCompleter +from alot.completion import AccountCompleter +from alot.message import encode_header +from alot import commands MODE = 'global' + @registerCommand(MODE, 'exit', {}) class ExitCommand(Command): """shuts the MUA down cleanly""" @@ -202,7 +202,7 @@ class BufferCloseCommand(Command): @registerCommand(MODE, 'bprevious', {'offset': -1}) @registerCommand(MODE, 'bnext', {'offset': +1}) -@registerCommand('bufferlist', 'openfocussed', {}) # todo separate +@registerCommand('bufferlist', 'openfocussed', {}) # todo separate class BufferFocusCommand(Command): """focus a buffer""" def __init__(self, buffer=None, offset=0, **kwargs): @@ -417,5 +417,3 @@ class EnvelopeOpenCommand(Command): def apply(self, ui): ui.buffer_open(buffers.EnvelopeBuffer(ui, mail=self.mail)) - - diff --git a/alot/commands/search.py b/alot/commands/search.py index 45c05763..1b68e491 100644 --- a/alot/commands/search.py +++ b/alot/commands/search.py @@ -1,14 +1,15 @@ -from commands import Command, registerCommand +from alot.commands import Command, registerCommand from twisted.internet import defer -from db import DatabaseROError -import commands -import buffers +from alot.db import DatabaseROError +from alot import commands +from alot import buffers MODE = 'search' -@registerCommand(MODE, 'openthread', {}) #todo: make this select + +@registerCommand(MODE, 'openthread', {}) # todo: make this select class OpenThreadCommand(Command): """open a new thread-view buffer""" def __init__(self, thread=None, **kwargs): @@ -68,6 +69,7 @@ class ToggleThreadTagCommand(Command): elif isinstance(cb, buffers.ThreadBuffer): pass + @registerCommand(MODE, 'refine', {}) class RefineCommand(Command): """refine the query of the currently open searchbuffer""" @@ -143,5 +145,3 @@ class RetagCommand(Command): sbuffer = ui.current_buffer threadwidget = sbuffer.get_selected_threadline() threadwidget.rebuild() # rebuild and redraw the line - - diff --git a/alot/commands/taglist.py b/alot/commands/taglist.py index 48c92b91..c551b72f 100644 --- a/alot/commands/taglist.py +++ b/alot/commands/taglist.py @@ -1,6 +1,5 @@ -from commands import Command, registerCommand - -import commands +from alot.commands import Command, registerCommand +from alot.commands.globals import SearchCommand MODE = 'taglist' @@ -9,7 +8,5 @@ MODE = 'taglist' class TaglistSelectCommand(Command): def apply(self, ui): tagstring = ui.current_buffer.get_selected_tag() - cmd = commands.globals.SearchCommand(query='tag:%s' % tagstring) + cmd = SearchCommand(query='tag:%s' % tagstring) ui.apply_command(cmd) - - diff --git a/alot/commands/thread.py b/alot/commands/thread.py index 143ff8e9..b70f9720 100644 --- a/alot/commands/thread.py +++ b/alot/commands/thread.py @@ -1,6 +1,3 @@ -from commands import Command, registerCommand -from twisted.internet import defer - import os import logging import tempfile @@ -8,15 +5,21 @@ from email import Charset from email.header import Header from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart +from twisted.internet import defer + +from alot.commands import Command, registerCommand +from alot.commands.globals import ExternalCommand +from alot.commands.globals import FlushCommand +from alot.commands.globals import ComposeCommand +from alot import settings +from alot import widgets +from alot import completion +from alot import helper +from alot.message import encode_header -import commands -import settings -import widgets -import completion -import helper -from message import encode_header MODE = 'thread' + @registerCommand(MODE, 'reply', {}) @registerCommand(MODE, 'groupreply', {'groupreply': True}) class ReplyCommand(Command): @@ -114,7 +117,7 @@ class ReplyCommand(Command): else: reply['References'] = '<%s>' % self.message.get_message_id() - ui.apply_command(commands.globals.ComposeCommand(mail=reply)) + ui.apply_command(ComposeCommand(mail=reply)) def clear_my_address(self, my_addresses, value): new_value = [] @@ -191,7 +194,7 @@ class ForwardCommand(Command): account = ui.accountman.get_account_by_address(matched_address) fromstring = '%s <%s>' % (account.realname, account.address) reply['From'] = encode_header('From', fromstring) - ui.apply_command(commands.globals.ComposeCommand(mail=reply)) + ui.apply_command(ComposeCommand(mail=reply)) @registerCommand(MODE, 'fold', {'visible': False}) @@ -215,7 +218,7 @@ class FoldMessagesCommand(Command): if self.visible or (self.visible == None and widget.folded): if 'unread' in msg.get_tags(): msg.remove_tags(['unread']) - ui.apply_command(commands.globalsFlushCommand()) + ui.apply_command(FlushCommand()) widget.rebuild() widget.fold(visible=True) else: @@ -371,7 +374,7 @@ class OpenAttachmentCommand(Command): def afterwards(): os.remove(path) - ui.apply_command(commands.globals.ExternalCommand(handler, path=path, + ui.apply_command(ExternalCommand(handler, path=path, on_success=afterwards, in_thread=True)) else: @@ -389,4 +392,3 @@ class ThreadSelectCommand(Command): ui.apply_command(OpenAttachmentCommand(focus.get_attachment())) else: logging.info('unknown widget %s' % focus) - |