-
Notifications
You must be signed in to change notification settings - Fork 0
/
conan_complete_remove.py
182 lines (148 loc) · 5.09 KB
/
conan_complete_remove.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
import subprocess
import sys
from functools import cmp_to_key
def get_conan_search(reference, remote=None, default=None):
try:
if remote is None:
params = ["conan", "search", reference]
else:
params = ["conan", "search", reference, "-r", remote]
res = subprocess.Popen(params, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output, _ = res.communicate()
if output:
if res.returncode == 0:
return output.decode("utf-8")
return default
except OSError: # as e:
return default
except:
return default
def get_package_ids(reference, remote=None, default=None):
res = []
str_res = get_conan_search(reference, remote)
# print(str_res)
for l in iter(str_res.splitlines()):
idx = l.find("Package_ID:") #, start, end)
# print(idx)
if idx != -1:
# print(l)
res.append(l[idx + len("Package_ID:") + 1:])
return res
def exec_conan_remove(reference, package, remote=None, default=None):
try:
if remote is None:
params = ["conan", "remove", reference, "--packages", package, "--force"]
else:
params = ["conan", "remove", reference, "--packages", package, "-r", remote, "--force"]
res = subprocess.Popen(params, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output, _ = res.communicate()
if output:
if res.returncode == 0:
return output.decode("utf-8")
return default
except OSError: # as e:
return default
except:
return default
def get_full_references(partial_ref, remote):
res = []
str_res = get_conan_search(partial_ref, remote)
# print(str_res)
for l in iter(str_res.splitlines()):
idx = l.find(partial_ref) #, start, end)
# print(idx)
if idx != -1:
# print(l)
res.append(l)
return res
def get_testing_full_references(partial_ref, remote):
res = []
full_references = get_full_references(partial_ref, remote)
for ref in full_references:
if "0.X" in ref:
continue
if "/testing" in ref:
res.append(ref)
return res
def get_staging_full_references(partial_ref, remote):
res = []
full_references = get_full_references(partial_ref, remote)
for ref in full_references:
if "0.X" in ref:
continue
if "/staging" in ref:
res.append(ref)
return res
# def get_removable_full_references(partial_ref, remote):
# res = []
# full_references = get_full_references(partial_ref, remote)
# for ref in full_references:
# if "0.X" in ref:
# continue
# if "/stable" in ref:
# continue
# res.append(ref)
# return res
def stable_sorter(x, y):
partX = x.split("@")[0]
partX = partX.split("/")[1]
partX = partX.split(".")
mapX = map(int, partX)
partX = list(mapX)
partY = y.split("@")[0]
partY = partY.split("/")[1]
partY = partY.split(".")
mapY = map(int, partY)
partY = list(mapY)
if partX < partY:
return -1
elif partX > partY:
return 1
else:
return 0
def complete_remove(partial_ref, remote, remove):
references = get_testing_full_references(partial_ref, remote)
staging_references = get_staging_full_references(partial_ref, remote)
staging_references = sorted(staging_references, key=cmp_to_key(stable_sorter))
print("Latest Staging version is::")
print(staging_references[-1])
del staging_references[-1]
references.extend(staging_references)
print("References to remove packages:")
for ref in references:
print(" " + ref)
for reference in references:
packages = get_package_ids(reference, remote)
print("For " + reference)
print(" Packages: " + str(packages))
if remove:
for p in packages:
res = exec_conan_remove(reference, p, remote)
print(res)
def main():
# partial_references = ["blockchain", "consensus", "database", "domain", "infrastructure", "kth", "network", "node", "secp256k1"]
partial_references = ["secp256k1", "infrastructure", "consensus", "domain", "database", "blockchain", "network", "node", "kth", "c-api"]
if (len(sys.argv) < 2):
print('Arguments: <remote> [remove]')
return
remove = False
if (len(sys.argv) >= 3):
if sys.argv[2] == "remove":
remove = True
remote = sys.argv[1]
# print("Reference: " + reference)
print("Remote: " + remote)
print("Remove packages: " + str(remove))
for partial_ref in partial_references:
complete_remove(partial_ref, remote, remove)
# # reference = "secp256k1/0.6.0@kth/staging"
# # remote = "kth"
# packages = get_package_ids(reference, remote)
# print("Packages: " + str(packages))
# if remove:
# for p in packages:
# res = exec_conan_remove(reference, p, remote)
# print(res)
if __name__ == "__main__":
# execute only if run as a script
main()