add commands and subcommands
This commit is contained in:
@@ -18,7 +18,7 @@ class CliBase(Controller):
|
|||||||
description = 'Kontor CLI Tool'
|
description = 'Kontor CLI Tool'
|
||||||
|
|
||||||
# text displayed at the bottom of --help output
|
# text displayed at the bottom of --help output
|
||||||
epilog = 'Usage: kontor gui|database'
|
epilog = 'Usage: kontor (gui | database | media) [subcommands]'
|
||||||
|
|
||||||
# controller level arguments. ex: 'kontor --version'
|
# controller level arguments. ex: 'kontor --version'
|
||||||
arguments = [
|
arguments = [
|
||||||
@@ -26,11 +26,14 @@ class CliBase(Controller):
|
|||||||
(['-v', '--version'],
|
(['-v', '--version'],
|
||||||
{'action': 'version',
|
{'action': 'version',
|
||||||
'version': VERSION_BANNER}),
|
'version': VERSION_BANNER}),
|
||||||
|
(['-m', '--dry-run'],
|
||||||
|
{'action': 'store_true',
|
||||||
|
'dest': 'dry_run'})
|
||||||
]
|
]
|
||||||
|
|
||||||
def _default(self):
|
def _default(self):
|
||||||
"""Default action if no sub-command is passed."""
|
"""Default action if no sub-command is passed."""
|
||||||
self.gui()
|
self.app.args.print_help()
|
||||||
|
|
||||||
@ex(
|
@ex(
|
||||||
help='start GUI'
|
help='start GUI'
|
||||||
|
|||||||
@@ -30,3 +30,26 @@ class Database(Controller):
|
|||||||
table_list = kontor_db.get_table_names()
|
table_list = kontor_db.get_table_names()
|
||||||
kontor_db.export_db(data['export_type'], data['db_file'], table_list)
|
kontor_db.export_db(data['export_type'], data['db_file'], table_list)
|
||||||
self.app.render(data, 'command1.jinja2')
|
self.app.render(data, 'command1.jinja2')
|
||||||
|
|
||||||
|
@ex(
|
||||||
|
label='import',
|
||||||
|
help='import data from file into database',
|
||||||
|
arguments=[
|
||||||
|
(['-f', '--file'],
|
||||||
|
{'help': 'file to read data',
|
||||||
|
'action': 'store',
|
||||||
|
'dest': 'db_file'})
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def import_cmd(self):
|
||||||
|
data = {
|
||||||
|
'db_file': 'data.json',
|
||||||
|
'data_type': 'JSON',
|
||||||
|
}
|
||||||
|
if self.app.pargs.db_file is not None:
|
||||||
|
data['db_file'] = self.app.pargs.db_file
|
||||||
|
kontor_db = KontorDB(self.app.session, self.app.log)
|
||||||
|
if self.app.pargs.dry_run:
|
||||||
|
self.app.render(data, 'import.jinja2')
|
||||||
|
else:
|
||||||
|
kontor_db.import_db(data['db_file'])
|
||||||
|
|||||||
@@ -0,0 +1,40 @@
|
|||||||
|
from cement import Controller, ex
|
||||||
|
|
||||||
|
|
||||||
|
class Media(Controller):
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
label = 'media'
|
||||||
|
stacked_type = 'nested'
|
||||||
|
stacked_on = 'base'
|
||||||
|
|
||||||
|
@ex(
|
||||||
|
label='update',
|
||||||
|
help='update title for mediafiles',
|
||||||
|
)
|
||||||
|
def update_title(self):
|
||||||
|
if self.app.pargs.dry_run:
|
||||||
|
print('print command to shell')
|
||||||
|
self.app.render({}, 'update.jinja2')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ex(
|
||||||
|
label='download',
|
||||||
|
help='download all marked videos',
|
||||||
|
arguments=[
|
||||||
|
(['-d', '--dir'],
|
||||||
|
{'help': 'directory to store videos',
|
||||||
|
'action': 'store',
|
||||||
|
'dest': 'media_dir'})
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def download(self):
|
||||||
|
data = {
|
||||||
|
'media_dir': '/data/media',
|
||||||
|
}
|
||||||
|
if self.app.pargs.media_dir is not None:
|
||||||
|
data['media_dir'] = self.app.pargs.media_dir
|
||||||
|
if self.app.pargs.dry_run:
|
||||||
|
print('print command to shell')
|
||||||
|
self.app.render(data, 'download.jinja2')
|
||||||
@@ -153,3 +153,6 @@ class KontorDB:
|
|||||||
self.log.debug("unknown export type")
|
self.log.debug("unknown export type")
|
||||||
if export_file.exists():
|
if export_file.exists():
|
||||||
self.log.debug(f"{export_file} exists")
|
self.log.debug(f"{export_file} exists")
|
||||||
|
|
||||||
|
def import_db(self, import_file_name: str):
|
||||||
|
pass
|
||||||
|
|||||||
@@ -3,20 +3,23 @@ from cement.core.exc import CaughtSignal
|
|||||||
from sqlalchemy import create_engine
|
from sqlalchemy import create_engine
|
||||||
from sqlalchemy.orm import sessionmaker
|
from sqlalchemy.orm import sessionmaker
|
||||||
|
|
||||||
|
from kontor.controllers.media import Media
|
||||||
from .core.exc import KontorError
|
from .core.exc import KontorError
|
||||||
from .database.base import Base
|
from .database.base import Base
|
||||||
from .controllers.clibase import CliBase
|
from .controllers.clibase import CliBase
|
||||||
from .controllers.database import Database
|
from .controllers.database import Database
|
||||||
|
|
||||||
# configuration defaults
|
# configuration defaults
|
||||||
CONFIG = init_defaults('kontor', 'mariadb')
|
CONFIG = init_defaults('kontor', 'mariadb','output.json', 'output.yaml')
|
||||||
CONFIG['kontor']['foo'] = 'bar'
|
CONFIG['kontor']['foo'] = 'bar'
|
||||||
CONFIG['mariadb']['user'] = 'kontor'
|
CONFIG['mariadb']['user'] = 'kontor'
|
||||||
CONFIG['mariadb']['password'] = 'kontor'
|
CONFIG['mariadb']['password'] = 'kontor'
|
||||||
CONFIG['mariadb']['host'] = '127.0.0.1'
|
CONFIG['mariadb']['host'] = '127.0.0.1'
|
||||||
CONFIG['mariadb']['port'] = '3306'
|
CONFIG['mariadb']['port'] = '3306'
|
||||||
CONFIG['mariadb']['database'] = 'kontor'
|
CONFIG['mariadb']['database'] = 'kontor'
|
||||||
|
META = init_defaults('output.json', 'output.yaml')
|
||||||
|
META['output.json']['overridable'] = True
|
||||||
|
META['output.yaml']['overridable'] = True
|
||||||
|
|
||||||
def extend_sqlalchemy(app):
|
def extend_sqlalchemy(app):
|
||||||
app.log.info('extending kontor application with sqlalchemy')
|
app.log.info('extending kontor application with sqlalchemy')
|
||||||
@@ -48,12 +51,15 @@ class Kontor(App):
|
|||||||
# configuration defaults
|
# configuration defaults
|
||||||
config_defaults = CONFIG
|
config_defaults = CONFIG
|
||||||
|
|
||||||
|
meta_defaults = META
|
||||||
|
|
||||||
# call sys.exit() on close
|
# call sys.exit() on close
|
||||||
exit_on_close = True
|
exit_on_close = True
|
||||||
|
|
||||||
# load additional framework extensions
|
# load additional framework extensions
|
||||||
extensions = [
|
extensions = [
|
||||||
'yaml',
|
'yaml',
|
||||||
|
'json',
|
||||||
'colorlog',
|
'colorlog',
|
||||||
'jinja2',
|
'jinja2',
|
||||||
]
|
]
|
||||||
@@ -78,6 +84,7 @@ class Kontor(App):
|
|||||||
handlers = [
|
handlers = [
|
||||||
CliBase,
|
CliBase,
|
||||||
Database,
|
Database,
|
||||||
|
Media,
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
|
||||||
|
Download videos to directory {{ media_dir }}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
|
||||||
|
Import data from {{ db_file }}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
|
||||||
|
Update entries of mediafile
|
||||||
Reference in New Issue
Block a user