]> git.scottworley.com Git - nix-currently-building/blob - nix_currently_building.py
Release 1.0.1
[nix-currently-building] / nix_currently_building.py
1 import os
2 import subprocess
3 import time
4
5
6 MIN_AGE = time.time() - 86400 * 1
7
8
9 def removesuffix(s, suf): # Until python 3.9
10 return s[:len(s) - len(suf)] if s.endswith(suf) else s
11
12
13 def truncated(log):
14 return subprocess.run(['bunzip2', '--test', log], stderr=subprocess.DEVNULL).returncode == 2
15
16
17 def main():
18 for d, _, files in os.walk(os.environ.get('NIX_LOG_DIR', '/nix/var/log/nix')):
19 for f in files:
20 path = os.path.join(d, f)
21 st = os.stat(path)
22 if st.st_mtime > MIN_AGE and truncated(path):
23 print(d[-2:] + removesuffix(f, '.bz2'))
24
25
26 if __name__ == '__main__':
27 main()