2022-11-30 00:09:23 -08:00
|
|
|
from slugify import slugify
|
|
|
|
|
|
|
|
from groove.db.manager import database_manager
|
|
|
|
from groove.shell.base import BasePrompt
|
|
|
|
from groove import db
|
|
|
|
from groove.playlist import Playlist
|
|
|
|
|
|
|
|
|
|
|
|
class CommandPrompt(BasePrompt):
|
|
|
|
|
|
|
|
def __init__(self, manager):
|
|
|
|
super().__init__(manager=manager)
|
|
|
|
self._playlist = None
|
|
|
|
self._prompt = "Groove on Demand interactive shell. Try 'help' for help.\ngroove>"
|
|
|
|
self._completer = None
|
|
|
|
self._commands = None
|
|
|
|
|
|
|
|
@property
|
|
|
|
def playlist(self):
|
|
|
|
return self._playlist
|
|
|
|
|
|
|
|
@property
|
|
|
|
def commands(self):
|
|
|
|
if not self._commands:
|
|
|
|
self._commands = {}
|
|
|
|
for cmd in BasePrompt.__subclasses__():
|
|
|
|
if cmd.__name__ == self.__class__.__name__:
|
|
|
|
continue
|
|
|
|
self._commands[cmd.__name__] = cmd(manager=self.manager, parent=self)
|
|
|
|
return self._commands
|
|
|
|
|
|
|
|
@property
|
|
|
|
def values(self):
|
|
|
|
return [k for k in self.commands.keys() if not k.startswith('_')]
|
|
|
|
|
2022-12-07 23:41:49 -08:00
|
|
|
def default_completer(self, document, complete_event): # pragma: no cover
|
2022-11-30 00:09:23 -08:00
|
|
|
def _formatter(row):
|
2022-12-02 00:21:19 -08:00
|
|
|
self._playlist = Playlist.from_row(row, self.manager.session)
|
2022-11-30 00:09:23 -08:00
|
|
|
return self.playlist.record.name
|
|
|
|
return self.manager.fuzzy_table_completer(
|
|
|
|
db.playlist,
|
|
|
|
db.playlist.c.name,
|
|
|
|
_formatter
|
|
|
|
).get_completions(document, complete_event)
|
|
|
|
|
|
|
|
def process(self, cmd, *parts):
|
|
|
|
name = cmd + ' ' + ' '.join(parts)
|
|
|
|
if cmd in self.commands:
|
|
|
|
self.commands[cmd].start(name)
|
2022-12-07 23:41:49 -08:00
|
|
|
return True
|
|
|
|
self._playlist = Playlist(
|
|
|
|
slug=slugify(name),
|
|
|
|
name=name,
|
|
|
|
session=self.manager.session,
|
|
|
|
create_ok=True
|
|
|
|
)
|
2022-12-10 10:38:11 -08:00
|
|
|
self.commands['_playlist'].start()
|
|
|
|
return True
|
2022-12-07 23:41:49 -08:00
|
|
|
|
|
|
|
|
|
|
|
def start(): # pragma: no cover
|
2022-11-30 00:09:23 -08:00
|
|
|
with database_manager() as manager:
|
|
|
|
CommandPrompt(manager).start()
|