-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtempcmds_migrate.py
executable file
·43 lines (34 loc) · 1 KB
/
tempcmds_migrate.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
#!/usr/bin/python3
#
# Migrate the old repr-based file to the new msgpack or JSON-based one.
#
import ast
try:
from msgpack import dumps
_t = 'msgpack'
except ImportError:
import json
_t = 'JSON'
dumps = lambda data : json.dumps(data).encode('utf-8')
def migrate(file):
print('Loading commands from the file...')
try:
with open(file, 'r') as f:
data = ast.literal_eval(f.read())
except:
print('ERROR: Could not load the commands list, are you sure it has not'
' already been converted?')
return False
print('Converting commands list to {}...'.format(_t))
data = dumps(data)
print('Writing commands back to the file...')
with open(file, 'wb') as f:
f.write(data)
print('Done!')
return True
if __name__ == '__main__':
import argparse
_parser = argparse.ArgumentParser()
_parser.add_argument('file', help='The tempcmds file to "upgrade".')
args = _parser.parse_args()
migrate(args.file)