import ConfigParser as configparser
+from .. import version
from ..compat.odict import odict
from ..config import Setting
from ..plugin import IsSubclass
def run(self, hooke, ui_to_command_queue, command_to_ui_queue):
return
- def playlist_status(self, playlist):
+ # Assorted useful tidbits for subclasses
+
+ def _splash_text(self):
+ return ("""
+This is Hooke, version %s
+
+COPYRIGHT
+----
+""" % version()).strip()
+
+ def _playlist_status(self, playlist):
if playlist.has_curves():
return '%s (%s/%s)' % (playlist.name, playlist._index + 1,
len(playlist))
+"""Defines :class:`CommandLine` for driving Hooke from the command
+line.
+"""
+
+import cmd
+import readline
+
from ..ui import UserInterface
+
+class HookeCmd (cmd.Cmd):
+ def __init__(self, hooke):
+ cmd.Cmd.__init__(self)
+ self.hooke = hooke
+ self.prompt = 'hooke> '
+ self._add_do_methods()
+
+ def _safe_name(self, name):
+ return name.lower().replace(' ', '_')
+
+ def _add_do_methods(self):
+ for command in self.hooke.commands:
+ for name in [command.name] + command.aliases:
+ name = self._safe_name(name)
+ def do_fn(self, args):
+ pass
+ setattr(self.__class__, 'do_%s' % name, do_fn)
+ def help_fn(self):
+ pass
+ setattr(self.__class__, 'help_%s' % name, help_fn)
+ def complete_fn(self, text, line, begidx, endidx):
+ pass
+ setattr(self.__class__, 'complete_%s' % name, complete_fn)
+
+ def _help(self, name, aliases, message, usage_args=None):
+ if len(aliases) == 0:
+ alias_string = ''
+ else:
+ alias_string = ' (%s)' % ', '.join(aliases)
+ if usage_args == None:
+ usage_string = name
+ else:
+ usage_string = '%s %s' % (name, usage_args)
+ self.stdout.write(("""
+%s%s
+
+%s
+------
+Usage: %s
+""" % (name, alias_string, message.strip(), usage_string)).lstrip())
+
+ def help_help(self):
+ return self._help('help', [], """
+Called with an argument, prints that command's documentation.
+
+With no argument, lists all available help topics as well as any
+undocumented commands.
+""",
+ '[command]')
+
+ def do_exit(self, args):
+ return True # the True return stops .cmdloop execution
+
+ def help_exit(self):
+ return self._help('exit', ['quit', 'EOF'], "Exit Hooke cleanly.")
+
+ def do_quit(self, args):
+ return self.do_exit(args)
+
+ def help_quit(self):
+ return self.help_exit()
+
+ def do_EOF(self, args):
+ return self.do_exit(args)
+
+ def help_EOF(self):
+ return self.help_exit()
+
class CommandLine (UserInterface):
"""Command line interface. Simple and powerful.
"""
def __init__(self):
super(CommandLine, self).__init__(name='command line')
+
+ def run(self, hooke, ui_to_command_queue, command_to_ui_queue):
+ cmd = HookeCmd(hooke)
+ cmd.cmdloop(self._splash_text())