示例#1
0
def main():
  parser = ArgumentParser(description='Count lines of source code.')
  parser.add_argument('paths', nargs='+', help='Directories to explore.')
  args = parser.parse_args()

  ext_counts = defaultdict(int)

  for path in walk_files(*args.paths):
    ext = path_ext(path)
    ext_counts[ext] += 1

  empty_name = '[none]'
  max_len = max(len(empty_name), max(len(k) for k in ext_counts))

  for k in sorted(ext_counts.keys()):
    v = ext_counts[k]
    print('{0:{1}}: {2}'.format(k or empty_name, max_len, v))
示例#2
0
文件: json-schema.py 项目: gwk/gloss
def main():
    parser = ArgumentParser(description="Count lines of source code.")
    parser.add_argument("-count-atoms", action="store_true")
    parser.add_argument("paths", nargs="+", help="Directories to explore.")
    args = parser.parse_args()

    schema = None
    for path in walk_files(*args.paths, file_exts=".json"):
        with open(path) as f:
            try:
                j = json.load(f)
            except json.JSONDecodeError as e:
                print("error: {}: {}".format(path, e), file=stderr)
                continue
            schema = compile_schema(j, schema=schema)

    write_schema(stdout, schema, count_atoms=args.count_atoms)