-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_symlinks.py
75 lines (64 loc) · 2.36 KB
/
create_symlinks.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
# Create a directory of symlinks to optimize and correct the appstream build
import pathlib
import argparse
import os
from xml.etree import ElementTree
def main():
parser = argparse.ArgumentParser(
prog='create_symlinks',
description='Create symbolic links to eopkg files to optimize and correct our appstream build'
)
parser.add_argument(
"eopkg_index",
action="store",
help="Path to the eopkg index file to be validated against. This must be an uncompressed XML file.",
type=pathlib.Path,
)
parser.add_argument(
"packages_directory",
action="store",
help="Path to the packages (input) directory.",
type=pathlib.Path,
)
parser.add_argument(
"symlinks_directory",
action="store",
help="Path to the symlinks (output) directory.",
type=pathlib.Path,
)
args = parser.parse_args()
eopkg_packages = get_packages_from_eopkg_index(args.eopkg_index)
symlinks_created = 0
for package_file in args.packages_directory.glob('**/*.eopkg'):
if check_file(package_file, eopkg_packages):
# Create a symlink for this package, we like it
os.symlink(package_file, pathlib.Path.joinpath(args.symlinks_directory, pathlib.Path(package_file.name)))
symlinks_created += 1
print(f'Created {symlinks_created} symlinks.')
def get_packages_from_eopkg_index(xml_path: pathlib.Path) -> dict:
solus_xml = open(xml_path, 'r')
tree = ElementTree.parse(solus_xml)
root = tree.getroot()
packages = {
package.find("Name").text: package.find("History").findall("Update")[0].attrib['release']
for package in root.findall("Package")
}
return packages
def parse_package_filename(package_filename: str) -> dict:
package_split = package_filename.rsplit('-', 4)
output = {
'name': package_split[0],
'release': package_split[2],
'dbginfo': 'dbginfo' in package_filename
}
return output
def check_file(path: pathlib.Path, eopkg_packages: dict) -> bool:
eopkg_info = parse_package_filename(path.name)
if (eopkg_info['name'] in eopkg_packages.keys() and eopkg_info['release'] == eopkg_packages[eopkg_info['name']])\
and not eopkg_info['dbginfo']\
:
return True
else:
return False
if __name__ == '__main__':
main()