This repository has been archived by the owner on Apr 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mcmanage.py
executable file
·66 lines (50 loc) · 1.54 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
58
59
60
61
62
63
64
65
66
#!/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>
mcmanage.py shard init
mcmanage.py shard migrate
"""
from docopt import docopt
from mediacrush.email import send_report
from mediacrush.mcmanage.database import database_clear, database_sync
from mediacrush.mcmanage.files import files_delete
from mediacrush.mcmanage.report import report
from mediacrush.mcmanage.shard import init, migrate
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}
shard_commands = {"init": init, "migrate": migrate}
mapping = {
"database": database_commands,
"report": report_commands,
"files": files_commands,
"shard": shard_commands,
"admin": None,
}
def find_true(arguments, mapping_dict):
return list(
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)