forked from Squalr/Squally
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dep.py
executable file
·155 lines (125 loc) · 4.92 KB
/
dep.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/usr/bin/env python3
###################################################################################
# This script will bootstrap vspkg and grab any neccessary dependencies #
# Run this script every time you pull #
###################################################################################
import argparse
import sys
import subprocess
import json
import os
import time
from sys import platform as _platform
from subprocess import call
from subprocess import check_output as shell_exec, Popen
def main():
# Setup environment
os.environ['MACOSX_DEPLOYMENT_TARGET'] = '10.10'
# Parse args
parser = argparse.ArgumentParser()
parser.add_argument('command', nargs='+', help="accepted commands: init, update, search, install")
parser.add_argument("-c", "--common", help="operation operates on the common set", action="store_true")
parser.add_argument("-t", "--triplet", help="vcpkg triplet (use vcpkg default is not specified", default="")
try:
args = parser.parse_args()
except:
parser.print_help()
return 0
if len(args.command) <= 0:
parser.print_help()
return 0
# Command
if args.command[0] == "init":
init(args.triplet)
elif args.command[0] == "install":
if len(args.command) <= 1:
print("please specify a package to install")
parser.print_help()
return 0
install(args.command[1], args.common, args.triplet)
elif args.command[0] == "search":
search(args.command[1])
elif args.command[0] == "update":
update(args.triplet)
else:
parser.print_help()
return 0
def integrate():
if _platform == "linux" or _platform == "linux2":
returncode = call(["./vcpkg/vcpkg", "integrate", "install"])
elif _platform == "darwin":
returncode = call(["./vcpkg/vcpkg", "integrate", "install"])
elif _platform == "win32":
returncode = call([".\\vcpkg\\vcpkg", "integrate", "install"])
if returncode != 0:
print()
print("dep.py: Error integrating vcpkg.")
return
def bootstrap():
returncode = -1
if _platform == "linux" or _platform == "linux2":
returncode = call(["./vcpkg/bootstrap-vcpkg.sh"], bufsize=1)
elif _platform == "darwin":
returncode = call(["./vcpkg/bootstrap-vcpkg.sh"], bufsize=1)
elif _platform == "win32":
returncode = call(".\\vcpkg\\bootstrap-vcpkg.bat", shell=True, bufsize=1)
if returncode != 0:
print()
print("dep.py: Error bootstrapping vcpkg.")
return
def init(triplet=""):
bootstrap()
update(triplet)
def update(triplet=""):
with open('requirements.json', 'r+') as fp:
manifest = json.load(fp)
# install common deps
for line in manifest["common"]:
print ("installing: " + line)
install(line.strip(), True, triplet)
# install platform deps
if _platform == "linux" or _platform == "linux2":
requirements = manifest["linux"]
elif _platform == "darwin":
requirements = manifest["darwin"]
elif _platform == "win32":
requirements = manifest["windows"]
for line in requirements:
print ("installing: " + line)
install(line.strip(), False, triplet)
integrate()
def search(searchString):
print(shell_exec(["./vcpkg/vcpkg", "search" , searchString]).decode('utf-8'))
def install(packageString, common=True, triplet=""):
s = packageString
if len(triplet) > 0:
s += ":" + triplet
# We ignore the error stream as vcpkg reports error on stdout and all we get is a spam of
# complaints about some vcpkg lock file not being present (this happens when vcpkg is run
# quickly).
if _platform == "linux" or _platform == "linux2":
returncode = call(["./vcpkg/vcpkg", "install" , s])
else:
returncode = call(["./vcpkg/vcpkg", "install" , s])
if returncode != 0:
print()
print("dep.py: A problem appears to have occurred, writing package to requirements.json skipped.")
return
# Select a set to write the dependency to
if common:
selectedSet = "common"
elif _platform == "win32" or _platform == "win64":
selectedSet = "windows"
elif _platform == "linux" or _platform == "linux2":
selectedSet = "linux"
elif _platform == "darwin":
selectedSet = "darwin"
# Write the dependency into our requirements file
with open("requirements.json", "r+") as fp:
manifest = json.load(fp)
if (packageString not in manifest[selectedSet]) and (packageString not in manifest["common"]):
manifest[selectedSet].append(packageString)
with open("requirements.json", "w") as wp:
json.dump(manifest, wp, indent=4, sort_keys=True)
if __name__ == '__main__':
main()