File: concatenate_protocols.py

package info (click to toggle)
nodejs 22.14.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 246,928 kB
  • sloc: cpp: 1,582,349; javascript: 582,017; ansic: 82,400; python: 60,561; sh: 4,009; makefile: 2,263; asm: 1,732; pascal: 1,565; perl: 248; lisp: 222; xml: 42
file content (42 lines) | stat: -rwxr-xr-x 1,085 bytes parent folder | download | duplicates (26)
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
34
35
36
37
38
39
40
41
42
#!/usr/bin/env python3
# Copyright 2016 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import os.path
import sys

try:
  import json
except ImportError:
  import simplejson as json

import pdl

def main(argv):
  if len(argv) < 1:
    sys.stderr.write(
        "Usage: %s <protocol-1> [<protocol-2> [, <protocol-3>...]] "
        "<output-file>\n" % sys.argv[0])
    return 1

  domains = []
  version = None
  for protocol in argv[:-1]:
    file_name = os.path.normpath(protocol)
    if not os.path.isfile(file_name):
      sys.stderr.write("Cannot find %s\n" % file_name)
      return 1
    input_file = open(file_name, "r")
    parsed_json = pdl.loads(input_file.read(), file_name)
    domains += parsed_json["domains"]
    version = parsed_json["version"]

  output_file = open(argv[-1], "w")
  json.dump({"version": version, "domains": domains}, output_file,
            indent=4, sort_keys=False, separators=(',', ': '))
  output_file.close()


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