1 #!/usr/bin/env nix-shell
2 #!nix-shell -i python3 -p "python3.withPackages(ps: [ ps.beautifulsoup4 ps.click ps.httpx ps.jinja2 ps.pyyaml ])"
7 from typing
import Optional
8 from urllib
.parse
import urlparse
18 LEAF_TEMPLATE
= jinja2
.Template('''
21 pname = "{{ pname }}";
25 ROOT_TEMPLATE
= jinja2
.Template('''
27 {%- for p in packages %}
28 {{ p }} = callPackage ./{{ p }} { };
34 raw
= binascii
.unhexlify(hash)
35 b64
= base64
.b64encode(raw
).decode()
36 return f
"sha256-{b64}"
42 type=click
.Choice(["frameworks", "gear", "plasma"]),
57 path_type
=pathlib
.Path
,
59 default
=pathlib
.Path(__file__
).parent
.parent
.parent
.parent
66 def main(set: str, version
: str, nixpkgs
: pathlib
.Path
, sources_url
: Optional
[str]):
67 root_dir
= nixpkgs
/ "pkgs/kde"
68 set_dir
= root_dir
/ set
69 generated_dir
= root_dir
/ "generated"
70 metadata
= utils
.KDERepoMetadata
.from_json(generated_dir
)
72 if sources_url
is None:
78 sources_url
= f
"https://kde.org/info/sources/source-{set_url}-{version}/"
80 sources
= httpx
.get(sources_url
)
81 sources
.raise_for_status()
82 bs
= bs4
.BeautifulSoup(sources
.text
, features
="html.parser")
85 for item
in bs
.select("tr")[1:]:
86 link
= item
.select_one("td:nth-child(1) a")
89 hash = item
.select_one("td:nth-child(3) tt")
92 project_name
, version
= link
.text
.rsplit("-", maxsplit
=1)
93 if project_name
not in metadata
.projects_by_name
:
94 print(f
"Warning: unknown tarball: {project_name}")
96 results
[project_name
] = {
98 "url": "mirror://kde" + urlparse(link
.attrs
["href"]).path
,
99 "hash": to_sri(hash.text
)
102 pkg_dir
= set_dir
/ project_name
103 pkg_file
= pkg_dir
/ "default.nix"
104 if not pkg_file
.exists():
105 print(f
"Generated new package: {set}/{project_name}")
106 pkg_dir
.mkdir(parents
=True, exist_ok
=True)
107 with pkg_file
.open("w") as fd
:
108 fd
.write(LEAF_TEMPLATE
.render(pname
=project_name
) + "\n")
110 set_dir
.mkdir(parents
=True, exist_ok
=True)
111 with (set_dir
/ "default.nix").open("w") as fd
:
112 fd
.write(ROOT_TEMPLATE
.render(packages
=sorted(results
.keys())) + "\n")
114 sources_dir
= generated_dir
/ "sources"
115 sources_dir
.mkdir(parents
=True, exist_ok
=True)
116 with (sources_dir
/ f
"{set}.json").open("w") as fd
:
117 json
.dump(results
, fd
, indent
=2)
120 if __name__
== "__main__":
121 main() # type: ignore