]> git.proxmox.com Git - rustc.git/blame - debian/prune-checksums
Ignore some other minor tests, bugs have been filed upstream
[rustc.git] / debian / prune-checksums
CommitLineData
94bd9ad3 1#!/usr/bin/python3
e9a8101d
XL
2# Copyright: 2015-2017 The Debian Project
3# License: MIT or Apache-2.0
4#
5# Helper to remove removed-files from .cargo-checksum
6# TODO: rewrite to perl and add to dh-cargo, maybe?
7
8from collections import OrderedDict
9import argparse
10import json
11import os
12import sys
13
14def prune_keep(cfile):
15 with open(cfile) as fp:
16 sums = json.load(fp, object_pairs_hook=OrderedDict)
17
18 oldfiles = sums["files"]
19 newfiles = OrderedDict([entry for entry in oldfiles.items() if os.path.exists(entry[0])])
20 sums["files"] = newfiles
21
22 if len(oldfiles) == len(newfiles):
23 return
24
25 with open(cfile, "w") as fp:
26 json.dump(sums, fp, separators=(',', ':'))
27
28def prune(cfile):
29 with open(cfile, "r+") as fp:
30 sums = json.load(fp, object_pairs_hook=OrderedDict)
31 sums["files"] = {}
32 fp.seek(0)
33 json.dump(sums, fp, separators=(',', ':'))
34 fp.truncate()
35
36if __name__ == "__main__":
37 parser = argparse.ArgumentParser()
38 parser.add_argument("-k", "--keep", action="store_true", help="keep "
39 "checksums of files that still exist, and assume they haven't changed.")
40 parser.add_argument('crates', nargs=argparse.REMAINDER,
41 help="crates whose checksums to prune. (default: ./)")
42 args = parser.parse_args(sys.argv[1:])
43 crates = args.crates or ["."]
44 f = prune_keep if args.keep else prune
45 for c in crates:
46 cfile = os.path.join(c, ".cargo-checksum.json") if os.path.isdir(c) else c
47 f(cfile)