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

Side by Side Diff: third_party/WebKit/Source/devtools/scripts/build/generate_supported_css.py

Issue 2620883002: Convert Settings.in, CSSValueKeywords.in, SVGCSSValueKeywords.in to json5 (Closed)
Patch Set: Convert CSSProperties.in to json5 format Created 3 years, 11 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 unified diff | Download patch
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2014 Google Inc. All rights reserved. 2 # Copyright (c) 2014 Google Inc. All rights reserved.
3 # 3 #
4 # Redistribution and use in source and binary forms, with or without 4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are 5 # modification, are permitted provided that the following conditions are
6 # met: 6 # met:
7 # 7 #
8 # * Redistributions of source code must retain the above copyright 8 # * Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer. 9 # notice, this list of conditions and the following disclaimer.
10 # * Redistributions in binary form must reproduce the above 10 # * Redistributions in binary form must reproduce the above
(...skipping 17 matching lines...) Expand all
28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 29
30 try: 30 try:
31 import simplejson as json 31 import simplejson as json
32 except ImportError: 32 except ImportError:
33 import json 33 import json
34 34
35 import sys 35 import sys
36 import re 36 import re
37 37
38 from json5_generator import Json5File # pylint: disable=W0403
39
38 def properties_from_file(file_name): 40 def properties_from_file(file_name):
41 doc = Json5File.load_from_files([file_name])
42
39 properties = [] 43 properties = []
40 propertyNames = set() 44 propertyNames = set()
41 with open(file_name, "r") as f: 45 for entry in doc.name_dictionaries:
42 for line in f: 46 if entry["alias_for"]:
43 line = line.strip() 47 continue
44 if not line or line.startswith("//") or "alias_for" in line: 48 properties.append(entry)
45 continue 49 propertyNames.add(entry["name"])
46 partition = re.split("[, ]", line)
47 name = partition[0]
48 attributes = partition[1:]
49 entry = {"name": name}
50 if "inherited" in attributes:
51 entry["inherited"] = True
52 if "svg" in attributes:
53 entry["svg"] = True
54 propertyNames.add(name)
55 longhands = line.partition("longhands=")[2].partition(",")[0]
56 if longhands:
57 entry["longhands"] = longhands.split(";")
58 properties.append(entry)
59 50
60 # Filter out unsupported longhands. 51 # Filter out unsupported longhands.
61 for property in properties: 52 for property in properties:
62 if "longhands" not in property: 53 if "longhands" not in property:
63 continue 54 continue
64 longhands = property["longhands"] 55 longhands = property["longhands"].split(";")
65 longhands = [longhand for longhand in longhands if longhand in propertyN ames] 56 longhands = [longhand for longhand in longhands if longhand in propertyN ames]
66 if not longhands: 57 if not longhands:
67 del property["longhands"] 58 del property["longhands"]
68 else: 59 else:
69 property["longhands"] = longhands 60 property["longhands"] = longhands
61
70 return properties 62 return properties
71 63
72 properties = properties_from_file(sys.argv[1]) 64 properties = properties_from_file(sys.argv[1])
73 with open(sys.argv[2], "w") as f: 65 with open(sys.argv[2], "w") as f:
74 f.write("SDK.CSSMetadata._generatedProperties = %s;" % json.dumps(properties )) 66 f.write("SDK.CSSMetadata._generatedProperties = %s;" % json.dumps(properties ))
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/devtools/BUILD.gn ('k') | third_party/WebKit/Source/devtools/scripts/build/json5_generator.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698