-
Notifications
You must be signed in to change notification settings - Fork 0
/
command.py
executable file
·59 lines (48 loc) · 1.8 KB
/
command.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
#!/usr/bin/env python
import sys
import argparse
sys.path.append('/gravel/pkg/gravel-common')
sys.path.append('/gravel/pkg/gravel-master')
import gravel_master
import json
import users
import cmd_util
def action_add():
parser = argparse.ArgumentParser(description='Create user and print it\'s uid to stdout.')
parser.add_argument('uid', type=int, default=-1,
help='ID of user to be added. (pass -1 to get first free one)')
args = parser.parse_args()
print users.add(args.uid)
def action_sethost():
parser = argparse.ArgumentParser()
parser.add_argument('uid', type=int)
parser.add_argument('node')
args = parser.parse_args()
users.User(args.uid).set_host(gravel_master.get_one_node(args.node))
def action_custom():
parser = argparse.ArgumentParser()
parser.add_argument('--set', action='store_const',
dest='action', const='set')
parser.add_argument('--get', action='store_const',
dest='action', const='get')
parser.add_argument('uid', type=int)
parser.add_argument('customname', default='list')
args = parser.parse_args()
user = users.User(args.uid)
if args.action == 'get':
json.dump(user.data.custom[args.customname], sys.stdout)
elif args.action == 'set':
data = json.load(sys.stdin)
user.data.custom[args.customname] = data
user.save_custom()
user.save()
else:
assert sys.stdin.isatty()
comment = 'Editing %s custom config for %d.' % (args.customname, args.uid)
user.data.custom[args.customname] = cmd_util.run_yaml_editor(
comment,
user.data.custom.get(args.customname, {}))
user.save_custom()
user.save()
if __name__ == '__main__':
cmd_util.main_multiple_action(globals())