-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathcontrol.py
executable file
·112 lines (79 loc) · 2.36 KB
/
control.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/usr/bin/env python
import click
from cli import admin as _admin
from prettytable import PrettyTable
import metrics
@click.group()
def cli():
"""Unshred.it management CLI"""
@cli.group('admin')
def admin():
"""Manages admin users"""
pass
@admin.command('list')
def admin_list():
"""List admin users"""
_admin.list_admin()
@admin.command('add')
@click.argument('email')
def admin_add(email):
"""Mark user as admin"""
_admin.toggle_admin(email, True)
@admin.command('remove')
@click.argument('email')
def admin_remove(email):
"""Unmark user as admin"""
_admin.toggle_admin(email, False)
@cli.group('batch')
def batch():
"""Manage batches"""
pass
@cli.group('tags')
def tags():
"""Manage tags"""
pass
@batch.command("process")
@click.argument('wildcard_filter')
@click.argument('batch')
def batch_process(wildcard_filter, batch):
"""Process input files and upload processed batch to mongo"""
from cli import load_to_mongo
load_to_mongo.load_new_batch(wildcard_filter, batch)
@batch.command("list")
def batch_list():
"""Show all batches and stats"""
from cli import load_to_mongo
batches = load_to_mongo.list_batches()
x = PrettyTable(["Batch name", "Shreds"])
for b in batches:
x.add_row([b["name"], b["shreds_created"]])
click.echo(x)
@tags.command("import")
@click.option('--clear/--no-clear', default=False,
help='delete existing base tags before import')
def tags_import(clear):
"""Import base tags from fixtures"""
from cli import load_to_mongo
added, updated = load_to_mongo.import_tags(clear)
click.echo(u"%s tags created, %s tags updated" % (added, updated))
@tags.command("list")
def tags_list():
"""List tags in db"""
from cli import load_to_mongo
tags = load_to_mongo.list_tags()
x = PrettyTable(["Tag name", "Is base", "Used"])
for tag in tags:
x.add_row([tag["title"], tag["is_base"], tag["usages"]])
click.echo(x)
@cli.group('metric')
def metric():
"""Manage Shreds metrics"""
pass
@metric.command('jaccard')
@click.option('--clear/--no-clear', default=False,
help='delete existing shreds distances before inserting new')
@click.option('--repeats', default=metrics.TAGS_REPEATS)
def churn_jaccard(clear, repeats):
metrics.churn_jaccard(clear, repeats)
if __name__ == '__main__':
cli()