-
Notifications
You must be signed in to change notification settings - Fork 6
/
project_list_from_debian.py
executable file
·75 lines (63 loc) · 2.22 KB
/
project_list_from_debian.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
#!/usr/bin/env python3
import argparse as ap
import gzip
import json
import os
from urllib.parse import urljoin
from urllib.request import urlretrieve
# TODO:
# * Filter packages based on dependencies that are installed
# on the host system.
# * Filter packages based on language/build system.
# * Support building packages in a fake-root environment.
# * Suggest apt command to install dependencies.
FOLDERS = '0123456789abcdefghijklmnopqrstuvwxyz'
def main():
parser = ap.ArgumentParser(description="Create project list from debian "
"source packages.",
formatter_class=ap.RawTextHelpFormatter)
parser.add_argument("--output", metavar="FILE",
help="JSON file holding a list of projects")
parser.add_argument("-u", "--url", metavar="URL",
help="debian FTP mirror")
args = parser.parse_args()
path, _ = urlretrieve(urljoin(args.url, "ls-lR.gz"))
with gzip.open(path, 'rb') as f:
lines = f.readlines()
os.remove(path)
archives = []
for folder in FOLDERS:
filename = None
for line in lines:
if isinstance(line, bytes):
line = line.decode('utf-8')
line = line.strip()
if len(line) < 4:
if filename:
archives.append(path + '/' + filename)
path = None
filename = None
elif line[:13 + len(folder)] == './pool/main/' + folder + '/':
path = line[2:-1]
elif path and line.find('.orig.tar.') > 0:
filename = line[1 + line.rfind(' '):]
result = {"projects": [],
'configurations': [
{
'name': 'baseline'
}
],
"CodeChecker": {
"url": "http://localhost:8001/Default"
}
}
for a in archives:
project = {
"name": a.split("/")[-2],
"url": urljoin(args.url, a)
}
result["projects"].append(project)
with open(args.output, 'w') as outfile:
json.dump(result, outfile, indent=2)
if __name__ == '__main__':
main()