python3Packages.orjson: Disable failing tests on 32 bit
[NixPkgs.git] / pkgs / tools / misc / btdu / update.py
blobaa3b149d733ea11eeba431f98a9b684ede9e8973
1 #!/usr/bin/env nix-shell
2 #!nix-shell -i python -p python39Packages.requests
4 import requests
5 import subprocess
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:]
14 break
16 def grabDepHashes(key,pkgbuild=pkgbuild):
17 start = pkgbuild.find(key) + len(key)
18 end = start+64
19 hashes = []
20 for i in range(5):
21 hashes.append(pkgbuild[start:end])
22 start = pkgbuild.find("'",end+1) + 1
23 end = start+64
24 return hashes
26 def findLine(key,derivation):
27 count = 0
28 lines = []
29 for line in derivation:
30 if key in line:
31 lines.append(count)
32 count += 1
33 return lines
35 def updateVersions(btdu,ae,btrfs,ncurses,containers,derivation):
36 key = "let"
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'
43 key = "version = "
44 line = findLine(key,derivation)[0]
45 derivation[line] = f' version = "{btdu["version"]}";\n'
47 return derivation
49 def updateHashes(btdu,ae,btrfs,ncurses,containers,derivation):
50 key = "sha256 = "
51 hashLines = findLine(key,derivation)
52 for i in range(len(hashes)):
53 derivation[hashLines[i]] = f' sha256 = "{hashes[i]}";\n'
55 return derivation
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"}
65 grabDepVersions(btdu)
66 grabDepVersions(ae)
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)