-
Notifications
You must be signed in to change notification settings - Fork 0
/
pack.py
71 lines (53 loc) · 1.42 KB
/
pack.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
import json
class Pack:
def __init__(self, name):
self.name = name
self.mods = []
def add_mod(self, mod):
self.mods.append(mod.__dict__)
def delete_mod(self, project_id):
for mod in self.mods:
if mod['project_id'] == project_id:
self.mods.remove(mod)
return True
return False
class PackMod:
def __init__(self, project_id, name):
self.project_id = project_id
self.name = name
packs = []
def load_packs():
global packs
packs.clear()
with open('packs.json', 'r') as f:
packs_ = json.load(f)
for pack in packs_:
p = Pack(pack['name'])
for mod in pack['mods']:
p.add_mod(PackMod(mod['project_id'], mod['name']))
packs.append(p)
def save_packs():
with open('packs.json', 'w') as f:
p = []
for pack in packs:
p.append(pack.__dict__)
json.dump(p, f)
def create_pack(name):
p = Pack(name)
packs.append(p)
save_packs()
return p
def delete_pack(name):
for pack in packs:
if pack.name == name:
packs.remove(pack)
save_packs()
return
raise Exception('Pack not found')
def rename_pack(name, new_name):
for pack in packs:
if pack.name == name:
pack.name = new_name
save_packs()
return
raise Exception('Pack not found')