remove kontor-cli.backup
This commit is contained in:
@@ -32,29 +32,3 @@ class CliBase(Controller):
|
||||
"""Default action if no sub-command is passed."""
|
||||
|
||||
self.app.args.print_help()
|
||||
|
||||
|
||||
@ex(
|
||||
help='example sub command1',
|
||||
|
||||
# sub-command level arguments. ex: 'kontor command1 --foo bar'
|
||||
arguments=[
|
||||
### add a sample foo option under subcommand namespace
|
||||
( [ '-f', '--foo' ],
|
||||
{ 'help' : 'notorious foo option',
|
||||
'action' : 'store',
|
||||
'dest' : 'foo' } ),
|
||||
],
|
||||
)
|
||||
def command1(self):
|
||||
"""Example sub-command."""
|
||||
|
||||
data = {
|
||||
'foo' : 'bar',
|
||||
}
|
||||
|
||||
### do something with arguments
|
||||
if self.app.pargs.foo is not None:
|
||||
data['foo'] = self.app.pargs.foo
|
||||
|
||||
self.app.render(data, 'command1.jinja2')
|
||||
|
||||
@@ -8,6 +8,11 @@ class Database(Controller):
|
||||
label = 'database'
|
||||
stacked_type = 'nested'
|
||||
stacked_on = 'clibase'
|
||||
arguments = [
|
||||
(['-m', '--dry-run'],
|
||||
{'action': 'store_true',
|
||||
'dest': 'dry_run'}),
|
||||
]
|
||||
|
||||
@ex(
|
||||
help='export database to given file',
|
||||
@@ -25,9 +30,11 @@ class Database(Controller):
|
||||
}
|
||||
if self.app.pargs.db_file is not None:
|
||||
data['db_file'] = self.app.pargs.db_file
|
||||
kontor_db = KontorDB(self.app.engine, self.app.config, self.app.log)
|
||||
kontor_db.export_db(data['export_type'], data['db_file'])
|
||||
self.app.render(data, 'command1.jinja2')
|
||||
kontor_db = KontorDB(self.app.engine)
|
||||
self.app.log.info(f"export DB to {data['db_file']} as {data['export_type']}")
|
||||
results = kontor_db.export_db(data['export_type'], data['db_file'])
|
||||
data['results'] = results
|
||||
self.app.render(data, 'export_db.jinja2')
|
||||
|
||||
@ex(
|
||||
label='import',
|
||||
@@ -46,8 +53,7 @@ class Database(Controller):
|
||||
}
|
||||
if self.app.pargs.db_file is not None:
|
||||
data['db_file'] = self.app.pargs.db_file
|
||||
kontor_db = KontorDB(self.app.engine, self.app.config, self.app.log)
|
||||
self.app.render(data, 'import.jinja2')
|
||||
kontor_db = KontorDB(self.app.engine)
|
||||
kontor_db.import_db(data['db_file'], self.app.pargs.dry_run)
|
||||
|
||||
@ex(
|
||||
@@ -66,7 +72,7 @@ class Database(Controller):
|
||||
cursor.execute("SHOW TABLES")
|
||||
for (tablename,) in cursor.fetchall():
|
||||
table_list.append(tablename)
|
||||
kontor_db = KontorDB(self.app.engine, self.app.log)
|
||||
kontor_db = KontorDB(self.app.engine)
|
||||
table_names = kontor_db.get_table_names()
|
||||
for table in table_list:
|
||||
if table not in table_names:
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
from pathlib import Path
|
||||
|
||||
from cement import Controller, ex
|
||||
from kontor_schema import KontorDB
|
||||
from kontor_video import VideoLink
|
||||
|
||||
class Media(Controller):
|
||||
|
||||
class Media(Controller):
|
||||
class Meta:
|
||||
label = 'media'
|
||||
stacked_type = 'nested'
|
||||
@@ -14,8 +16,14 @@ class Media(Controller):
|
||||
help='update title for mediafiles',
|
||||
)
|
||||
def update_title(self):
|
||||
kontor_db = KontorDB(self.app.engine, self.app.log)
|
||||
kontor_db.update_title(self.app.pargs.dry_run)
|
||||
kontor_db = KontorDB(self.app.engine)
|
||||
updates = kontor_db.get_update_list()
|
||||
self.app.log.info(f"found {len(updates)} links for update")
|
||||
for file_id, url in updates.items():
|
||||
link = VideoLink(url)
|
||||
title = link.get_title()
|
||||
if title is not None:
|
||||
kontor_db.update_entry('media_file', file_id, {'title': title, 'review': 0,})
|
||||
|
||||
@ex(
|
||||
label='download',
|
||||
@@ -33,11 +41,26 @@ class Media(Controller):
|
||||
}
|
||||
if self.app.pargs.media_dir is not None:
|
||||
data['media_dir'] = self.app.pargs.media_dir
|
||||
kontor_db = KontorDB(self.app.engine, self.app.log)
|
||||
kontor_db = KontorDB(self.app.engine)
|
||||
downloads = kontor_db.get_download_list()
|
||||
for download in downloads:
|
||||
link = VideoLink(download, download_dir=data['media_dir'])
|
||||
link.download()
|
||||
self.app.log.info(f"found {len(downloads)} links for download")
|
||||
for file_id, url in downloads.items():
|
||||
link = VideoLink(url)
|
||||
file_name = link.download(download_dir=data['media_dir'])
|
||||
if file_name is None:
|
||||
kontor_db.update_entry('media_file', file_id, {'file_name': None, 'should_download': 1})
|
||||
else:
|
||||
download_file = Path(file_name)
|
||||
download_file.with_name(f"{file_id}{download_file.suffix}")
|
||||
link.file_name = download_file.name
|
||||
link.should_download = 0
|
||||
link.cloud_link = download_file.absolute()
|
||||
kontor_db.update_entry('media_file', file_id,
|
||||
{
|
||||
'file_name': download_file.name,
|
||||
'should_download': 0,
|
||||
'cloud_link': download_file.absolute()}
|
||||
)
|
||||
|
||||
@ex(
|
||||
help='add url to database',
|
||||
@@ -56,9 +79,10 @@ class Media(Controller):
|
||||
data['link_url'] = self.app.pargs.link
|
||||
if self.app.pargs.dry_run:
|
||||
print(f"add url {data['link_url']} to database")
|
||||
kontor_db = KontorDB(self.app.engine, self.app.log)
|
||||
kontor_db.add_link(self.app.pargs.link, self.app.pargs.dry_run)
|
||||
|
||||
else:
|
||||
kontor_db = KontorDB(self.app.engine)
|
||||
result = kontor_db.add_link(self.app.pargs.link)
|
||||
self.log.info(result)
|
||||
else:
|
||||
print("no url was given.")
|
||||
|
||||
@@ -77,5 +101,5 @@ class Media(Controller):
|
||||
}
|
||||
if self.app.pargs.media_dir is not None:
|
||||
data['media_dir'] = self.app.pargs.media_dir
|
||||
kontor_db = KontorDB(self.app.engine, self.app.log)
|
||||
kontor_db = KontorDB(self.app.engine)
|
||||
kontor_db.check_files()
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
|
||||
Example Template (templates/command1.jinja2)
|
||||
|
||||
Foo => {{ foo }}
|
||||
@@ -0,0 +1,5 @@
|
||||
Following tables were exported:
|
||||
|
||||
{% for key, value in results.items() %}
|
||||
Table {{key}}: {{value}} entries
|
||||
{% endfor %}
|
||||
@@ -0,0 +1,29 @@
|
||||
[build-system]
|
||||
requires = ["setuptools"]
|
||||
build-backend = "setuptools.build_meta"
|
||||
|
||||
[project]
|
||||
name = "kontor-cli"
|
||||
version = "0.1.0"
|
||||
description = "Kontor CLI Application"
|
||||
authors = [
|
||||
{name = "Thomas Peetz", email = "thomas.peetz@thpeetz.de"},
|
||||
]
|
||||
maintainers = [
|
||||
{name = "Thomas Peetz", email = "thomas.peetz@thpeetz.de"},
|
||||
]
|
||||
readme = "README.md"
|
||||
classifiers = [
|
||||
"Development Status :: 3 - Alpha",
|
||||
"Environment :: Console",
|
||||
"Programming Language :: Python",
|
||||
"Programming Language :: Python :: 3.10",
|
||||
"Topic :: Utilities",
|
||||
]
|
||||
|
||||
dependencies = [
|
||||
]
|
||||
requires-python = ">= 3.10"
|
||||
|
||||
[projects.scripts]
|
||||
kontor = "kontor.main:main"
|
||||
@@ -7,3 +7,4 @@ cement[yaml]
|
||||
cement[colorlog]
|
||||
mariadb
|
||||
sqlalchemy
|
||||
pathlib
|
||||
|
||||
Reference in New Issue
Block a user