-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsubmit.py
More file actions
61 lines (55 loc) · 2.42 KB
/
Copy pathsubmit.py
File metadata and controls
61 lines (55 loc) · 2.42 KB
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
import os
import json
import shutil
from os import listdir
from os.path import isfile, join
def addOne(name2, version):
name = name2.replace("\\", "/")
pv = version.replace(".", "_")
os.makedirs("published/"+name.lower(), exist_ok=True)
shutil.copyfile("src/"+name+".sl", "published/"+name.lower()+"/"+pv+".sl")
with open("published/index.json") as f:
data = json.load(f)
with open("published/index.json", "w") as f:
if name.replace("/", ".").lower() not in data["libraries"]:
data["libraries"][name.replace("/", ".").lower()] = [{"url": name.lower()+"/"+pv+".sl", "filename": name.lower()+".sl", "version": version}]
else:
# remove old version
latest = {}
for i in range(len(data["libraries"][name.replace("/", ".").lower()])):
if data["libraries"][name.replace("/", ".").lower()][i]["version"] == version:
# merge with new version if it exists
data["libraries"][name.replace("/", ".").lower()][i].update({"url": name.lower()+"/"+pv+".sl", "filename": name.lower()+".sl", "version": version})
break
else:
latest = data["libraries"][name.replace("/", ".").lower()][i]
else:
d = {}
d.update(latest)
d.update({"url": name.lower()+"/"+pv+".sl", "filename": name.lower()+".sl", "version": version})
data["libraries"][name.replace("/", ".").lower()].append(d)
json.dump(data, f, indent=4)
if (__name__ == "__main__"):
action = input("library to add: ").replace(".", "/")
if (action == "*"):
mypath = "src/"
walk = os.walk(mypath)
for parent, dirs, files in walk:
for file in files:
file = parent + "/"+file
name = file.replace(".sl","").replace(mypath, "").replace("\\", "/")
if name[0] == "/":
name = name[1:]
print(name)
addOne(name, "1.0.0")
else:
with open("published/index.json") as f:
data = json.load(f)
version = "1.0.0"
key = action.replace("/", ".").lower()
if key in data["libraries"]:
version = data["libraries"][key][-1]["version"]
v = input(f"version (Latest = {version}): ")
if v != "":
version = v
addOne(action, version)