forked from MediaCrush/MediaCrush
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mcmanage.py
executable file
·58 lines (45 loc) · 1.32 KB
/
mcmanage.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
#!/usr/bin/env python
"""MediaCrush manage.
Usage:
mcmanage.py database clear
mcmanage.py database sync
mcmanage.py admin list
mcmanage.py admin add <pwhash>
mcmanage.py admin delete <pwhash>
mcmanage.py report show
mcmanage.py report email
mcmanage.py files delete <hash>
"""
from docopt import docopt
from mediacrush.mcmanage.database import database_clear, database_sync
from mediacrush.mcmanage.report import report
from mediacrush.mcmanage.files import files_delete
from mediacrush.email import send_report
def show_report(args):
print(report())
database_commands = {
'clear': database_clear,
'sync': database_sync,
}
report_commands = {
'show': show_report,
'email': lambda args: send_report(report())
}
files_commands = {
'delete': files_delete,
}
mapping = {
'database': database_commands,
'report': report_commands,
'files': files_commands,
'admin': None,
}
def find_true(arguments, mapping_dict):
return filter(lambda x: x is not None, [item if arguments[item] else None for item in mapping_dict])[0]
if __name__ == '__main__':
arguments = docopt(__doc__, version='1.0')
module = find_true(arguments, mapping)
commands = mapping[module]
command = find_true(arguments, commands)
command = commands[command]
command(arguments)