-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
112 lines (99 loc) · 3.33 KB
/
main.py
File metadata and controls
112 lines (99 loc) · 3.33 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
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import sys
import json
import os
import requests
#temp list of packages
url = ''
metapath = os.path.join(os.path.expanduser('~'), '.agpm', 'localmetadata.json')
settingspath = os.path.join(os.path.expanduser('~'), '.agpm', 'sources.escnf')
def fetchsource():
print("fetching source list...")
try:
with open(settingspath, 'r') as file:
source = file.readline()
print("Source url: " + source)
return source
except Exception:
return "https://eyescary-development.github.io/CDN/agpm_packages/"
def setsource(srcurl):
with open(settingspath, 'w') as file:
file.write(srcurl)
def fetchlist():
print("fetching cloud metadata...")
response = requests.get(url+"packagelist.json")
response.raise_for_status()
return response.json()
def fetchlocalmet():
print("fetch local metadata...")
try:
with open(metapath, 'r') as f:
localmetadata = json.load(f)
return localmetadata
except Exception:
print("local metadata file doesn't exist, returning empty metadata...")
return {}
def checkpackagelist(item):
pkglist = fetchlist()
print("checking package list...")
try:
temp=pkglist[item]
return True
except Exception:
return False
def lookup(item):
metadata=fetchlist()
print("package name: " + str(item))
print("description: " + str(metadata[item]["description"]))
print("latest release notes: " + str(metadata[item]["releaseNotes"]))
def metawrite(metadata, path):
with open(path, 'w') as f:
json.dump(metadata, f, indent=2)
def install(item):
os.system("curl -O "+url+item+"/protocols/install.sh && bash install.sh && rm install.sh")
localmetadata=fetchlocalmet()
cloudmetadata=fetchlist()
localmetadata[item]=cloudmetadata[item]
metawrite(localmetadata, metapath)
def uninstall(item):
os.system("curl -O "+url+item+"/protocols/uninstall.sh && bash uninstall.sh && rm uninstall.sh")
localmetadata = fetchlocalmet()
localmetadata.pop(item, None)
metawrite(localmetadata, metapath)
def update(item):
metadata=fetchlist()
cloudver = metadata[item]["version"]
localmetadata = fetchlocalmet()
localver = localmetadata[item]["version"]
if localver != cloudver:
os.system("curl -O "+url+item+"/protocols/update.sh && bash update.sh && rm update.sh")
localmetadata[item]=metadata[item]
metawrite(localmetadata, metapath)
else:
print("Package already up to date, command already satisfied")
def operate(task, app):
if checkpackagelist(app):
match task:
case "install":
install(app)
case "uninstall":
uninstall(app)
case "update":
update(app)
case "search":
lookup(app)
case 'srcset':
setsource(app)
else:
print("package doesn't exist, terminating...")
def main():
global url
url=fetchsource()
usin = input("set (s)ource, or install/lookup/update/uninstall a package (o)?: ")
match usin:
case 'o':
while True:
task,app = input("operation: "), input("app to operate: ")
operate(task,app)
case 's':
setsource(input("enter your source url (no need for packagelist.json at the end: )"))
main()