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 16 import yaml 17 import argparse 18 import datetime 19 import csv 20 21 argp = argparse.ArgumentParser(description='Convert cloc yaml to bigquery csv') 22 argp.add_argument('-i', '--input', type=str) 23 argp.add_argument( 24 '-d', 25 '--date', 26 type=str, 27 default=datetime.date.today().strftime('%Y-%m-%d')) 28 argp.add_argument('-o', '--output', type=str, default='out.csv') 29 args = argp.parse_args() 30 31 data = yaml.load(open(args.input).read()) 32 with 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