• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2# Copyright 2017 gRPC authors.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#     http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16import yaml
17import argparse
18import datetime
19import csv
20
21argp = argparse.ArgumentParser(description='Convert cloc yaml to bigquery csv')
22argp.add_argument('-i', '--input', type=str)
23argp.add_argument(
24    '-d',
25    '--date',
26    type=str,
27    default=datetime.date.today().strftime('%Y-%m-%d'))
28argp.add_argument('-o', '--output', type=str, default='out.csv')
29args = argp.parse_args()
30
31data = yaml.load(open(args.input).read())
32with open(args.output, 'w') as outf:
33    writer = csv.DictWriter(
34        outf, ['date', 'name', 'language', 'code', 'comment', 'blank'])
35    for key, value in data.iteritems():
36        if key == 'header': continue
37        if key == 'SUM': continue
38        if key.startswith('third_party/'): continue
39        row = {'name': key, 'date': args.date}
40        row.update(value)
41        writer.writerow(row)
42