-
Notifications
You must be signed in to change notification settings - Fork 0
/
dependencies.py
executable file
·68 lines (56 loc) · 1.82 KB
/
dependencies.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
#!/usr/bin/python
import os
import platform
import urllib
import zipfile
class Requirement:
osName = platform.system()
platform = 'amd64'
installDir = '/usr/local/bin/'
def __init__(self, fileName):
self.fileName = fileName
print "\n Starting installing dependencies..."
def openF(self):
try:
with open(self.fileName,'r') as f:
content = f.readlines()
return [x.strip() for x in content]
except Exception as e:
print "File requirements.txt doesn't exist!"
exit(1)
def getZip(self, program, version):
file = program +'_'+ \
version +'_'+ \
self.osName.lower() +'_'+ \
self.platform + '.zip'
link = 'https://releases.hashicorp.com/' + \
program +'/'+ \
version +'/'+ \
program +'_'+ \
version +'_'+ \
self.osName.lower() +'_'+ \
self.platform + '.zip'
try:
urllib.urlretrieve (link, file)
return file
except Exception as e:
print "Cannot get " + program + "_" + version
exit(1)
def install(self, file, name):
try:
zipF = zipfile.ZipFile(file,'r')
zipF.extractall(self.installDir)
os.chmod(self.installDir + name, 755)
os.remove(file)
return " Successfuly installed!"
except Exception as e:
print "Cannot install " + file
exit(1)
init = Requirement('requirements.txt')
for c in init.openF():
name, ver = c.split("=")
print "\n Downloading " + name
file = init.getZip(name.lower(), ver)
print " Installing " + name
print init.install(file, name)
print '\n All dependencies was installed! \n'