]>
git.proxmox.com Git - rustc.git/blob - debian/prune-checksums
2 # Copyright: 2015-2017 The Debian Project
3 # License: MIT or Apache-2.0
5 # Helper to remove removed-files from .cargo-checksum
6 # TODO: rewrite to perl and add to dh-cargo, maybe?
8 from collections
import OrderedDict
14 def prune_keep(cfile
):
15 with
open(cfile
) as fp
:
16 sums
= json
.load(fp
, object_pairs_hook
=OrderedDict
)
18 oldfiles
= sums
["files"]
19 newfiles
= OrderedDict([entry
for entry
in oldfiles
.items() if os
.path
.exists(entry
[0])])
20 sums
["files"] = newfiles
22 if len(oldfiles
) == len(newfiles
):
25 with
open(cfile
, "w") as fp
:
26 json
.dump(sums
, fp
, separators
=(',', ':'))
29 with
open(cfile
, "r+") as fp
:
30 sums
= json
.load(fp
, object_pairs_hook
=OrderedDict
)
33 json
.dump(sums
, fp
, separators
=(',', ':'))
36 if __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
46 cfile
= os
.path
.join(c
, ".cargo-checksum.json") if os
.path
.isdir(c
) else c