1 # Copyright (C) 2010-2012 W. Trevor King <wking@drexel.edu>
3 # This file is part of Hooke.
5 # Hooke is free software: you can redistribute it and/or modify it under the
6 # terms of the GNU Lesser General Public License as published by the Free
7 # Software Foundation, either version 3 of the License, or (at your option) any
10 # Hooke is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
15 # You should have received a copy of the GNU Lesser General Public License
16 # along with Hooke. If not, see <http://www.gnu.org/licenses/>.
18 """The `engine` module provides :class:`EnginePlugin` and several
19 associated :class:`hooke.command.Command`\s for basic
20 :class:`~hooke.hooke.Hooke` and :class:`~hooke.engine.CommandEngine`
24 from ..command import Exit, Command, Argument
25 from ..interaction import BooleanRequest
29 class EnginePlugin (Builtin):
31 super(EnginePlugin, self).__init__(name='engine')
33 ExitCommand(self), HelpCommand(self)]
36 class ExitCommand (Command):
37 """Exit Hooke cleanly.
39 def __init__(self, plugin):
40 super(ExitCommand, self).__init__(
43 Argument(name='force', type='bool', default=False,
45 Exit without prompting the user. Use if you save often or don't make
49 help=self.__doc__, plugin=plugin)
51 def _run(self, hooke, inqueue, outqueue, params):
52 """Exit Hooke, prompting if there are unsaved changes.
55 if params['force'] == False:
56 not_saved = [p.name for p in hooke.playlists
57 if p.is_saved() == False]
60 if len(not_saved) > 0:
61 msg = 'Unsaved playlists (%s). %s' \
62 % (', '.join([str(p) for p in not_saved]), msg)
64 outqueue.put(BooleanRequest(msg, default))
65 result = inqueue.get()
66 assert result.type == 'boolean'
70 # TODO: check for unsaved config file
75 class HelpCommand (Command):
76 """Called with an argument, prints that command's documentation.
78 With no argument, lists all available help topics as well as any
79 undocumented commands.
81 def __init__(self, plugin):
82 super(HelpCommand, self).__init__(
83 name='help', help=self.__doc__, plugin=plugin)
84 # We set .arguments now (vs. using th arguments option to __init__),
85 # to overwrite the default help argument. We don't override
86 # :meth:`cmd.Cmd.do_help`, so `help --help` is not a valid command.
88 Argument(name='command', type='string', optional=True,
89 help='The name of the command you want help with.')
92 def _run(self, hooke, inqueue, outqueue, params):
93 if params['command'] == None:
94 outqueue.put(sorted([c.name for c in hooke.commands]))
96 outqueue.put(hooke.command_by_name[params['command']].help())