File: update_refpkg.py

package info (click to toggle)
pplacer 1.1~alpha19-8
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 17,324 kB
  • sloc: ml: 20,927; ansic: 9,002; python: 1,641; makefile: 171; sh: 77; xml: 50
file content (33 lines) | stat: -rwxr-xr-x 925 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env python

import argparse
import shutil
import json
import sys

replacements = {
    'tree_file': 'tree',
    'phylo_model_file': 'phylo_model',
}

def main(args):
    parser = argparse.ArgumentParser()
    parser.add_argument('infile', metavar='CONTENTS.json',
                        type=argparse.FileType('rb+'))
    args = parser.parse_args(args)

    shutil.copyfile(args.infile.name, args.infile.name + '.bak')
    contents = json.load(args.infile)
    for key in ['files', 'md5']:
        records = contents[key]
        for repl_in, repl_out in replacements.iteritems():
            if repl_in not in records:
                continue
            records[repl_out] = records.pop(repl_in)
    contents.setdefault('metadata', {})['format_version'] = '1.1'
    args.infile.seek(0)
    args.infile.truncate()
    json.dump(contents, args.infile, indent=2)

if __name__ == '__main__':
    main(sys.argv[1:])