Ran update_copyright.py, updating all the copyright blurbs and adding AUTHORS.
[hooke.git] / hooke / ui / commandline.py
index 8d85a957052a51737ab63c74ffe138873313da1f..8a497181b8e0808d70775dfb6a3979b3f70aa044 100644 (file)
@@ -1,3 +1,21 @@
+# Copyright (C) 2010 W. Trevor King <wking@drexel.edu>
+#
+# This file is part of Hooke.
+#
+# Hooke is free software: you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation, either
+# version 3 of the License, or (at your option) any later version.
+#
+# Hooke is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with Hooke.  If not, see
+# <http://www.gnu.org/licenses/>.
+
 """Defines :class:`CommandLine` for driving Hooke from the command
 line.
 """
@@ -8,7 +26,7 @@ import readline # including readline makes cmd.Cmd.cmdloop() smarter
 import shlex
 
 from ..command import CommandExit, Exit, Command, Argument, StoreValue
-from ..interaction import Request, BooleanRequest
+from ..interaction import Request, BooleanRequest, ReloadUserInterfaceConfig
 from ..ui import UserInterface, CommandMessage
 
 
@@ -91,6 +109,9 @@ class DoCommand (CommandMethod):
                 self.cmd.stdout.write(msg.__class__.__name__+'\n')
                 self.cmd.stdout.write(str(msg).rstrip()+'\n')
                 break
+            elif isinstance(msg, ReloadUserInterfaceConfig):
+                self.cmd.ui.reload_config(msg.config)
+                continue
             elif isinstance(msg, Request):
                 self._handle_request(msg)
                 continue
@@ -124,7 +145,7 @@ class DoCommand (CommandMethod):
         If not, raise optparse.OptParseError().
         """
         min_args = 0
-        max_args = -1
+        max_args = 0
         for argument in self.parser.command_args:
             if argument.optional == False and argument.count > 0:
                 min_args += argument.count
@@ -298,7 +319,7 @@ typing mistakes ;).
             default = True
             if len(not_saved) > 0:
                 msg = 'Unsaved playlists (%s).  %s' \
-                    % (', '.join(not_saved), msg)
+                    % (', '.join([str(p) for p in not_saved]), msg)
                 default = False
             outqueue.put(BooleanRequest(msg, default))
             result = inqueue.get()
@@ -311,8 +332,9 @@ typing mistakes ;).
 # Now onto the main attraction.
 
 class HookeCmd (cmd.Cmd):
-    def __init__(self, commands, inqueue, outqueue):
+    def __init__(self, ui, commands, inqueue, outqueue):
         cmd.Cmd.__init__(self)
+        self.ui = ui
         self.commands = commands
         self.local_commands = [LocalExitCommand(), LocalHelpCommand()]
         self.prompt = 'hooke> '
@@ -343,7 +365,15 @@ class CommandLine (UserInterface):
         super(CommandLine, self).__init__(name='command line')
 
     def run(self, commands, ui_to_command_queue, command_to_ui_queue):
-        cmd = HookeCmd(commands,
+        cmd = HookeCmd(self, commands,
                        inqueue=ui_to_command_queue,
                        outqueue=command_to_ui_queue)
         cmd.cmdloop(self._splash_text())
+
+    def run_lines(self, commands, ui_to_command_queue, command_to_ui_queue,
+                  lines):
+        cmd = HookeCmd(self, commands,
+                       inqueue=ui_to_command_queue,
+                       outqueue=command_to_ui_queue)
+        for line in lines:
+            cmd.onecmd(line)