1 # Copyright (C) 2010 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
6 # under the terms of the GNU Lesser General Public License as
7 # published by the Free Software Foundation, either version 3 of the
8 # License, or (at your option) any later version.
10 # Hooke is distributed in the hope that it will be useful, but WITHOUT
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
13 # Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with Hooke. If not, see
17 # <http://www.gnu.org/licenses/>.
19 """The `engine` module provides :class:`EnginePlugin` and several
20 associated :class:`hooke.command.Command`\s for basic
21 :class:`~hooke.hooke.Hooke` and :class:`~hooke.engine.CommandEngine`
25 from ..command import Exit, Command, Argument
26 from ..interaction import BooleanRequest
30 class EnginePlugin (Builtin):
32 super(EnginePlugin, self).__init__(name='engine')
34 ExitCommand(self), HelpCommand(self)]
37 class ExitCommand (Command):
38 """Exit Hooke cleanly.
40 def __init__(self, plugin):
41 super(ExitCommand, self).__init__(
44 Argument(name='force', type='bool', default=False,
46 Exit without prompting the user. Use if you save often or don't make
50 help=self.__doc__, plugin=plugin)
52 def _run(self, hooke, inqueue, outqueue, params):
53 """Exit Hooke, prompting if there are unsaved changes.
56 if params['force'] == False:
57 not_saved = [p.name for p in hooke.playlists
58 if p.is_saved() == False]
61 if len(not_saved) > 0:
62 msg = 'Unsaved playlists (%s). %s' \
63 % (', '.join([str(p) for p in not_saved]), msg)
65 outqueue.put(BooleanRequest(msg, default))
66 result = inqueue.get()
67 assert result.type == 'boolean'
71 # TODO: check for unsaved config file
76 class HelpCommand (Command):
77 """Called with an argument, prints that command's documentation.
79 With no argument, lists all available help topics as well as any
80 undocumented commands.
82 def __init__(self, plugin):
83 super(HelpCommand, self).__init__(
84 name='help', help=self.__doc__, plugin=plugin)
85 # We set .arguments now (vs. using th arguments option to __init__),
86 # to overwrite the default help argument. We don't override
87 # :meth:`cmd.Cmd.do_help`, so `help --help` is not a valid command.
89 Argument(name='command', type='string', optional=True,
90 help='The name of the command you want help with.')
93 def _run(self, hooke, inqueue, outqueue, params):
94 if params['command'] == None:
95 outqueue.put(sorted([c.name for c in hooke.commands]))
97 outqueue.put(hooke.command_by_name[params['command']].help())