diff options
author | Patrick Totzke <patricktotzke@gmail.com> | 2011-10-12 22:43:30 +0100 |
---|---|---|
committer | Patrick Totzke <patricktotzke@gmail.com> | 2011-10-12 22:43:30 +0100 |
commit | c99da513998ffdd28a5fd7c600a42e858e7c876b (patch) | |
tree | 56ac5aa423ef74bed4060031b0825589fd4370a9 /alot | |
parent | 60dd4b1f2e684d43ac5fd08e93fe23f29f96d870 (diff) |
globals and search commands done
Diffstat (limited to 'alot')
-rw-r--r-- | alot/Commands/__init__.py | 3 | ||||
-rw-r--r-- | alot/Commands/globals.py | 45 | ||||
-rw-r--r-- | alot/__init__.py | 2 | ||||
-rw-r--r-- | alot/command.py | 188 | ||||
-rwxr-xr-x | alot/init.py | 10 |
5 files changed, 5 insertions, 243 deletions
diff --git a/alot/Commands/__init__.py b/alot/Commands/__init__.py deleted file mode 100644 index f047554a..00000000 --- a/alot/Commands/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -import os -import glob -__all__ = list(filename[:-3] for filename in glob.glob1(os.path.dirname(__file__), '*.py')) diff --git a/alot/Commands/globals.py b/alot/Commands/globals.py deleted file mode 100644 index e439ad88..00000000 --- a/alot/Commands/globals.py +++ /dev/null @@ -1,45 +0,0 @@ -from command import Command, registerCommand -#from alot.command import Command, registerCommand -from twisted.internet import defer - -registerCommand('global', 'exit', {}) -class ExitCommand(Command): - """shuts the MUA down cleanly""" - @defer.inlineCallbacks - def apply(self, ui): - if settings.config.getboolean('general', 'bug_on_exit'): - if (yield ui.choice('realy quit?', select='yes', cancel='no', - msg_position='left')) == 'no': - return - ui.exit() - - -registerCommand('global', 'search', {}) -class SearchCommand(Command): - """open a new search buffer""" - def __init__(self, query, **kwargs): - """ - :param query: initial querystring - """ - self.query = query - Command.__init__(self, **kwargs) - - @defer.inlineCallbacks - def apply(self, ui): - if self.query: - if self.query == '*' and ui.current_buffer: - s = 'really search for all threads? This takes a while..' - if (yield ui.choice(s, select='yes', cancel='no')) == 'no': - return - open_searches = ui.get_buffers_of_type(buffer.SearchBuffer) - to_be_focused = None - for sb in open_searches: - if sb.querystring == self.query: - to_be_focused = sb - if to_be_focused: - ui.buffer_focus(to_be_focused) - else: - ui.buffer_open(buffer.SearchBuffer(ui, self.query)) - else: - ui.notify('empty query string') - diff --git a/alot/__init__.py b/alot/__init__.py index 6a364552..8d2b1835 100644 --- a/alot/__init__.py +++ b/alot/__init__.py @@ -25,5 +25,3 @@ __description__ = "Command-line MUA using notmuch mail" __url__ = "https://github.com/pazz/alot" __license__ = "Licensed under the GNU GPL v3+." -import command -from commands import * diff --git a/alot/command.py b/alot/command.py deleted file mode 100644 index 5b064091..00000000 --- a/alot/command.py +++ /dev/null @@ -1,188 +0,0 @@ -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 - - -class Command(object): - """base class for commands""" - def __init__(self, prehook=None, posthook=None): - self.prehook = prehook - self.posthook = posthook - self.undoable = False - self.help = self.__doc__ - - def apply(self, caller): - pass - - -COMMANDS = { - 'search': { - }, - 'envelope': { - }, - 'bufferlist': { - }, - 'taglist': { - }, - 'thread': { - }, - 'global': { - } -} - - -class registerCommand(object): - def __init__(self, mode, name, defaultparms): - self.mode = mode - self.name = name - self.defaultparms = defaultparms - - def __call__(self, klass): - COMMANDS[self.mode][self.name] = (klass, self.defaultparms) - return klass - - -def commandfactory(cmdname, mode='global', **kwargs): - if cmdname in COMMANDS[mode]: - (cmdclass, parms) = COMMANDS[mode][cmdname] - elif cmdname in COMMANDS['global']: - (cmdclass, parms) = COMMANDS['global'][cmdname] - else: - logging.error('there is no command %s' % cmdname) - parms = parms.copy() - parms.update(kwargs) - for (key, value) in kwargs.items(): - if callable(value): - parms[key] = value() - else: - parms[key] = value - - parms['prehook'] = settings.hooks.get('pre_' + cmdname) - parms['posthook'] = settings.hooks.get('post_' + cmdname) - - logging.debug('cmd parms %s' % parms) - return cmdclass(**parms) - - -def interpret_commandline(cmdline, mode): - # TODO: use argparser here! - if not cmdline: - return None - logging.debug('mode:%s got commandline "%s"' % (mode, cmdline)) - args = cmdline.split(' ', 1) - cmd = args[0] - if args[1:]: - params = args[1] - else: - params = '' - - # unfold aliases - if settings.config.has_option('command-aliases', cmd): - cmd = settings.config.get('command-aliases', cmd) - - # allow to shellescape without a space after '!' - if cmd.startswith('!'): - params = cmd[1:] + ' ' + params - cmd = 'shellescape' - - # check if this command makes sense in current mode - if cmd not in COMMANDS[mode] and cmd not in COMMANDS['global']: - logging.debug('unknown command: %s' % (cmd)) - return None - - if cmd == 'search': - return commandfactory(cmd, mode=mode, query=params) - if cmd in ['move', 'sendkey']: - return commandfactory(cmd, mode=mode, key=params) - elif cmd == 'compose': - h = {} - if params: - h = {'To': params} - return commandfactory(cmd, mode=mode, headers=h) - elif cmd == 'attach': - return commandfactory(cmd, mode=mode, path=params) - elif cmd == 'help': - return commandfactory(cmd, mode=mode, commandline=params) - elif cmd == 'forward': - return commandfactory(cmd, mode=mode, inline=(params == '--inline')) - elif cmd == 'prompt': - return commandfactory(cmd, mode=mode, startstring=params) - elif cmd == 'refine': - if mode == 'search': - return commandfactory(cmd, mode=mode, query=params) - elif mode == 'envelope': - return commandfactory(cmd, mode=mode, key=params) - - elif cmd == 'retag': - return commandfactory(cmd, mode=mode, tagsstring=params) - elif cmd == 'shellescape': - return commandfactory(cmd, mode=mode, commandstring=params) - elif cmd == 'set': - key, value = params.split(' ', 1) - return commandfactory(cmd, mode=mode, key=key, value=value) - elif cmd == 'toggletag': - return commandfactory(cmd, mode=mode, tags=params.split()) - elif cmd == 'fold': - return commandfactory(cmd, mode=mode, all=(params == '--all')) - elif cmd == 'unfold': - return commandfactory(cmd, mode=mode, all=(params == '--all')) - elif cmd == 'save': - args = params.split(' ') - allset = False - pathset = None - if args: - if args[0] == '--all': - allset = True - pathset = ' '.join(args[1:]) - else: - pathset = params - return commandfactory(cmd, mode=mode, all=allset, path=pathset) - elif cmd == 'edit': - filepath = os.path.expanduser(params) - if os.path.isfile(filepath): - return commandfactory(cmd, mode=mode, path=filepath) - elif cmd == 'print': - args = [a.strip() for a in params.split()] - return commandfactory(cmd, mode=mode, - whole_thread=('--thread' in args), - separately=('--separately' in args)) - elif cmd == 'pipeto': - return commandfactory(cmd, mode=mode, command=params) - - elif not params and cmd in ['exit', 'flush', 'pyshell', 'taglist', - 'bclose', 'compose', 'openfocussed', - 'closefocussed', 'bnext', 'bprevious', 'retag', - 'refresh', 'bufferlist', 'refineprompt', - 'reply', 'open', 'groupreply', 'bounce', - 'openthread', 'toggleheaders', 'send', - 'cancel', 'reedit', 'select', 'retagprompt']: - return commandfactory(cmd, mode=mode) - else: - return None - - diff --git a/alot/init.py b/alot/init.py index 9ef9c3f3..86f3dc42 100755 --- a/alot/init.py +++ b/alot/init.py @@ -25,8 +25,8 @@ import settings from account import AccountManager from db import DBManager from ui import UI -import command -from Commands import * +import commands +from commands import * def parse_args(): @@ -92,7 +92,7 @@ def main(): logging.basicConfig(level=numeric_loglevel, filename=logfilename) logger = logging.getLogger() - logger.debug(command.COMMANDS) + logger.debug(commands.COMMANDS) #accountman aman = AccountManager(settings.config) @@ -101,12 +101,12 @@ def main(): # get initial searchstring if args.command != '': - cmd = command.interpret_commandline(args.command, 'global') + cmd = commands.interpret_commandline(args.command, 'global') if cmd is None: sys.exit('Invalid command: ' + args.command) else: default_commandline = settings.config.get('general', 'initial_command') - cmd = command.interpret_commandline(default_commandline, 'global') + cmd = commands.interpret_commandline(default_commandline, 'global') # set up and start interface UI(dbman, |