-
Notifications
You must be signed in to change notification settings - Fork 0
/
package.py
115 lines (107 loc) · 3.52 KB
/
package.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import os
import io
import sys
import requests
# import angledat
home = os.path.expanduser('~')
module = os.path.join(home, '.strawberry', 'lib')
sys.path.append(module)
import angledat as ang
args = sys.argv
def argerror(expected, real):
if not expected == real:
print("Wrong number of args")
sys.exit()
def help():
print("install : install a package")
print("remove : remove a package")
print("uppak : update package list")
print("lsinstalled : list installed packages")
print("lsinstallable : list installable packages")
print("search : search for packages")
sys.exit()
# from https://raspberrypi.stackexchange.com/questions/5100/detect-that-a-python-program-is-running-on-the-pi
def ispi():
try:
with io.open('/sys/firmware/devicetree/base/model', 'r') as m:
if 'raspberry pi' in m.read().lower(): return True
except Exception: pass
return False
if not ispi():
print("Please run on a supported machine")
sys.exit()
if len(args) == 1:
help()
if args[1] == "install":
argerror(3, len(args))
try:
filler = args[2]
except:
print("Second argument not given.")
sys.exit()
list = ang.read_dict(os.path.join(home, '.strawberry', 'pmlist', 'list.txt'))
if args[2] in list:
os.chdir(os.path.join(home, '.strawberry', 'pakbin'))
package = list[args[2]]
if not package.endswith(args[2]):
print("Invalid link found for package.")
sys.exit()
if not os.path.exists(args[2]):
exit = os.system("wget " + package + " >~/.strawberry/wget.log 2>&1")
if exit == 0:
os.system("chmod +x " + args[2])
print("Package installed")
else:
print("Failed to download package")
sys.exit()
else:
print("Package is already installed")
sys.exit()
else:
print("No package found")
elif args[1] == "uppak":
argerror(2, len(args))
os.chdir(os.path.join(home, '.strawberry', 'pmlist'))
exit = os.system("git pull >~/.strawberry/uppack.log 2>&1")
if not exit == 0:
print("Error while pulling")
elif args[1] == "remove":
argerror(3, len(args))
os.chdir(os.path.join(home, '.strawberry', 'pakbin'))
try:
filler = args[2]
except:
print("Second argument not given.")
sys.exit()
if os.path.exists(args[2]):
if not args[2] == "strawberry":
exit = os.system("rm -rf " + args[2] + " >~/.strawberry/remove.log 2>&1")
if not exit == 0:
print("Could not remove package " + args[2])
else:
print("Package is protected cannot uninstall it.")
else:
print("No package called that exists")
elif args[1] == "lsinstalled":
argerror(2, len(args))
installed = os.listdir(os.path.join(home, '.strawberry', 'pakbin'))
for i in installed:
print(i)
elif args[1] == "ver":
argerror(2, len(args))
print("Strawberry version 0.1")
elif args[1] == "lsinstallable":
argerror(2, len(args))
list = ang.read_dict(os.path.join(home, '.strawberry', 'pmlist', 'list.txt'))
for name in list:
print(name)
elif args[1] == "search":
argerror(3, len(args))
list = ang.read_dict(os.path.join(home, '.strawberry', 'pmlist', 'list.txt'))
for name in list:
val = list[name]
if args[2] in name or args[2] in val:
print(name)
else:
print("Not a recognized command.")
help()