1 #!/usr/bin/env nix-shell
2 #!nix-shell -i python -p python39Packages.requests
7 pkgbuild
= requests
.get('https://aur.archlinux.org/cgit/aur.git/plain/PKGBUILD?h=btdu').text
9 def grabDepVersions(depDict
, pkgbuild
=pkgbuild
):
10 for line
in pkgbuild
.split('\n'):
11 if depDict
["string"] in line
:
12 start
= len(depDict
["string"]) + 1
13 depDict
["version"] = line
[start
:]
16 def grabDepHashes(key
,pkgbuild
=pkgbuild
):
17 start
= pkgbuild
.find(key
) + len(key
)
21 hashes
.append(pkgbuild
[start
:end
])
22 start
= pkgbuild
.find("'",end
+1) + 1
26 def findLine(key
,derivation
):
29 for line
in derivation
:
35 def updateVersions(btdu
,ae
,btrfs
,ncurses
,containers
,derivation
):
37 line
= findLine(key
,derivation
)[0] + 1
38 derivation
[line
+0] = f
' _d_ae_ver = "{ae["version"]}";\n'
39 derivation
[line
+1] = f
' _d_btrfs_ver = "{btrfs["version"]}";\n'
40 derivation
[line
+2] = f
' _d_ncurses_ver = "{ncurses["version"]}";\n'
41 derivation
[line
+3] = f
' _d_emsi_containers_ver = "{containers["version"]}";\n'
44 line
= findLine(key
,derivation
)[0]
45 derivation
[line
] = f
' version = "{btdu["version"]}";\n'
49 def updateHashes(btdu
,ae
,btrfs
,ncurses
,containers
,derivation
):
51 hashLines
= findLine(key
,derivation
)
52 for i
in range(len(hashes
)):
53 derivation
[hashLines
[i
]] = f
' sha256 = "{hashes[i]}";\n'
57 if __name__
== "__main__":
59 btdu
= {"string": "pkgver"}
60 ae
= {"string": "_d_ae_ver"}
61 btrfs
= {"string": "_d_btrfs_ver"}
62 ncurses
= {"string": "_d_ncurses_ver"}
63 containers
= {"string": "_d_emsi_containers_ver"}
67 grabDepVersions(btrfs
)
68 grabDepVersions(ncurses
)
69 grabDepVersions(containers
)
71 hashes
= grabDepHashes("sha256sums=('")
73 nixpkgs
= subprocess
.check_output(["git", "rev-parse", "--show-toplevel"]).decode("utf-8").strip('\n')
74 btduFolder
= "/pkgs/tools/misc/btdu/"
75 with
open(nixpkgs
+ btduFolder
+ "default.nix", 'r') as arq
:
76 derivation
= arq
.readlines()
78 derivation
= updateVersions(btdu
,ae
,btrfs
,ncurses
,containers
,derivation
)
79 derivation
= updateHashes(btdu
,ae
,btrfs
,ncurses
,containers
,derivation
)
81 with
open(nixpkgs
+ btduFolder
+ "default.nix", 'w') as arq
:
82 arq
.writelines(derivation
)