-
Notifications
You must be signed in to change notification settings - Fork 0
/
bump.py
91 lines (74 loc) · 1.83 KB
/
bump.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
import argparse
import json
parser = argparse.ArgumentParser(
prog='bump',
description='Adjust the x and y properties of the specified items in the specified JSON files')
parser.add_argument(
"-x",
action="store",
dest="x",
type=int,
help="Specify an absolute X coordinate for the specified items")
parser.add_argument(
"-y",
action="store",
dest="y",
type=int,
help="Specify an absolute Y coordinate for the specified items")
parser.add_argument(
"-dx",
action="store",
dest="dx",
type=int,
help="Specify a change for the X coordinate for the specified items")
parser.add_argument(
"-dy",
action="store",
dest="dy",
type=int,
help="Specify a change for the Y coordinate for the specified items")
parser.add_argument(
"-file",
action="append",
dest="files",
help="Specifies a JSON file to modify. Can be specified multiple times.")
parser.add_argument(
"items",
action="store",
nargs="+",
help="unique_id of the items to modify")
def move_item(item, args):
if args.x != None:
item["x"] = args.x
elif args.dx != None:
item["x"] += args.dx
pass
if args.y != None:
item["y"] = args.y
elif args.dy != None:
item["y"] += args.dy
pass
pass
def process_file(f, args):
print("Processing %s" % f)
with open(f, "r") as io:
data = json.load(io)
pass
for item in data:
if item["unique_id"] in args.items:
move_item(item, args)
pass
pass
with open(f, "w") as io:
json.dump(data, io, indent=4)
pass
pass
def main():
args = parser.parse_args()
print(args)
for f in args.files:
process_file(f, args)
pass
pass
if __name__ == '__main__':
main()