Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1472)

Unified Diff: third_party/WebKit/Tools/Scripts/csv_to_json

Issue 2155523002: Add mapping of directories to owners as json file (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: change json to only contain files in imported Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | third_party/WebKit/Tools/Scripts/webkitpy/w3c/directory_owners.json » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Tools/Scripts/csv_to_json
diff --git a/third_party/WebKit/Tools/Scripts/csv_to_json b/third_party/WebKit/Tools/Scripts/csv_to_json
new file mode 100755
index 0000000000000000000000000000000000000000..f77ec8bbd457cb3a2d003c1414c1ded2b30ce472
--- /dev/null
+++ b/third_party/WebKit/Tools/Scripts/csv_to_json
@@ -0,0 +1,52 @@
+#!/usr/bin/python
qyearsley 2016/07/20 17:57:09 Possibly consider a more specific name for the scr
+# Copyright 2016 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""Converts CSV files to machine-readable JSON.
+
+ Example usage:
+
+ ./csv_to_json input.csv --output directory_owners.json \
+ --skip-keys="Number of tests"
qyearsley 2016/07/20 17:57:09 Could add a backslash at the end of this one (so t
+ -f directory number-tests
qyearsley 2016/07/20 17:57:09 Also add "... team notification-email other-contac
+"""
+
+import argparse
+import csv
+import json
+import sys
+
+
+def main(argv):
+ parser = argparse.ArgumentParser()
+ parser.add_argument('filename', metavar='filename',
+ help='The path to the input CSV file.')
+ parser.add_argument('-o', '--output',
+ help='The output file name.')
+ parser.add_argument('-f', '--field-names', nargs='*',
+ help='The ordered field names of the CSV file. Defaults to first row.')
+ parser.add_argument('-s', '--skip-keys', nargs='*',
+ help='Fields that should be skipped.')
+ args = parser.parse_args()
+ convert_csv_to_json(args.filename, args.output, args.field_names, args.skip_keys)
+
+
+def convert_csv_to_json(filename, output_filename=None, field_names=None, skip_keys=None):
+ out = output_filename or (filename + '.json')
+ dict_list = []
+ json_file = open(out, 'w')
+ with open(filename) as csv_file:
+ reader = csv.DictReader(csv_file, fieldnames=field_names)
+ for row in reader:
+ if not row['directory'].startswith('imported'):
+ continue
+ if skip_keys:
+ for s in skip_keys:
+ del row[s]
+ dict_list.append(row)
+ json.dump(dict_list, json_file, indent=4)
+
+
+if __name__ == '__main__':
+ main(sys.argv[1:])
« no previous file with comments | « no previous file | third_party/WebKit/Tools/Scripts/webkitpy/w3c/directory_owners.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698