This repository has been archived by the owner on Aug 16, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmanage.py
63 lines (47 loc) · 1.64 KB
/
manage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# -*- coding: utf-8 -*-
import os
import sys
import errno
import inspect
from mhundwa.models import Base, engine
from mhundwa.commands.index import parse as parse_index
from mhundwa.commands.post import parse as parse_post
from mhundwa.commands.download import download
from mhundwa.commands.inventory_post import inventory_post
from mhundwa.youtube import _get_youtube_service
import settings
sys.path.insert(0, os.path.abspath('.'))
def database_create(*args):
"""Создание базы данных и всех таблиц"""
try:
os.makedirs(settings.DATA_ROOT)
except OSError as err:
if err.errno == errno.EEXIST and os.path.isdir(settings.DATA_ROOT):
pass
else:
raise
Base.metadata.drop_all(engine)
Base.metadata.create_all(engine)
def google_oauth(*args, **kwargs):
"""OAuth авторизация Google для YouTube"""
_get_youtube_service()
commands = {
'parse_index': parse_index,
'parse_post': parse_post,
'database_create': database_create,
'download': download,
'inventory_post': inventory_post,
'google_oauth': google_oauth,
}
if __name__ == '__main__':
try:
command = commands[sys.argv[1]]
except (KeyError, IndexError) as e:
if isinstance(e, KeyError):
sys.stdout.write('Unknown command!\n\n')
commands_list = u'\n'.join([
u'{}: {}'.format(key, inspect.getdoc(value).decode('utf-8').split('\n')[0]) for key, value in commands.items()
])
sys.stdout.write(u'Run one of those commands:\n\n{}\n'.format(commands_list))
sys.exit(errno.EINVAL)
command(*sys.argv[2:])