-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cache.py
53 lines (45 loc) · 1.58 KB
/
Cache.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
import subprocess
import json
class Cache(object):
def __init__(self):
self.__remotes = None
self.__data = None
@property
def data(self):
return self.__data
@property
def remotes(self):
if not self.__remotes:
remotes = []
cmd = subprocess.run(["conan", "remote", "list", "--raw"], stdout=subprocess.PIPE)
output = cmd.stdout.decode("utf-8")
for remote in output.split("\n"):
if remote:
remotes.append(remote) # Only the name. For the moment.
self.__remotes = remotes
return self.__remotes
def scan_remotes(self):
cache = []
for remote in self.remotes:
element = {}
name, url, ssl = remote.split()
temp_file = "/tmp/{}.json".format(name)
_ = subprocess.run(["conan", "search", "*", "-r", name, "--json", temp_file], stdout=subprocess.PIPE)
element["name"] = name
element["url"] = url
element["ssl"] = ssl
element["packages"] = []
with open(temp_file) as f:
results = json.load(f)["results"]
for item in results[0]["items"]:
element["packages"].append(item["recipe"]["id"])
cache.append(element)
self.__data = cache
def dump(self, filename):
""" Writes a JSON file with the data of the object."""
with open(filename, "w") as o:
json.dump(self.__data, o)
if __name__ == "__main__":
c = Cache()
c.scan_remotes()
print(c.data)