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

Side by Side Diff: Source/devtools/scripts/convert_svg_images_to_png.py

Issue 345713004: DevTools: update responsive design icon. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « Source/devtools/front_end/inspector.css ('k') | Source/devtools/scripts/optimize_png_images.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 11 matching lines...) Expand all
22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
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 import devtools_file_hashes 30 import devtools_file_hashes
31 import hashlib 31 import hashlib
32 import optimize_svg_file
33 import os 32 import os
34 import os.path 33 import os.path
35 import re 34 import re
36 import subprocess 35 import subprocess
37 import sys 36 import sys
38 37
39 try: 38 try:
40 import json 39 import json
41 except ImportError: 40 except ImportError:
42 import simplejson as json 41 import simplejson as json
43 42
44 43
45 def check_installed(app_name): 44 def check_installed(app_name):
46 proc = subprocess.Popen("which %s" % app_name, stdout=subprocess.PIPE, shell =True) 45 proc = subprocess.Popen("which %s" % app_name, stdout=subprocess.PIPE, shell =True)
47 proc.communicate() 46 proc.communicate()
48 if proc.returncode != 0: 47 if proc.returncode != 0:
49 print "This script needs \"%s\" to be installed." % app_name 48 print "This script needs \"%s\" to be installed." % app_name
50 sys.exit(1) 49 sys.exit(1)
51 50
52 51
53 def optimize_svg(svg_file_path):
54 errors = []
55 optimize_svg_file.optimize_svg(svg_file_path, errors)
56 if len(errors) != 0:
57 print "Failed to optimize '%s'" % (svg_file_path)
58 for error in errors:
59 print "ERROR: %s" % (error)
60 return True
61 return False
62
63 check_installed("inkscape") 52 check_installed("inkscape")
64 53
65 scripts_path = os.path.dirname(os.path.abspath(__file__)) 54 scripts_path = os.path.dirname(os.path.abspath(__file__))
66 devtools_path = os.path.dirname(scripts_path) 55 devtools_path = os.path.dirname(scripts_path)
67 devtools_frontend_path = devtools_path + "/front_end" 56 devtools_frontend_path = devtools_path + "/front_end"
68 images_path = devtools_frontend_path + "/Images" 57 images_path = devtools_frontend_path + "/Images"
69 image_sources_path = images_path + "/src" 58 image_sources_path = images_path + "/src"
70 hashes_file_name = "svg2png.hashes" 59 hashes_file_name = "svg2png.hashes"
71 hashes_file_path = image_sources_path + "/" + hashes_file_name 60 hashes_file_path = image_sources_path + "/" + hashes_file_name
72 61
73 file_names = os.listdir(image_sources_path) 62 file_names = os.listdir(image_sources_path)
74 svg_file_paths = [image_sources_path + "/" + file_name for file_name in file_nam es if file_name.endswith(".svg")] 63 svg_file_paths = [image_sources_path + "/" + file_name for file_name in file_nam es if file_name.endswith(".svg")]
75 64
76 svg_optimization_failures = [optimize_svg(svg_file_path) for svg_file_path in sv g_file_paths]
77 if any(svg_optimization_failures):
78 sys.exit(1)
79
80 svg_file_paths_to_convert = devtools_file_hashes.files_with_invalid_hashes(hashe s_file_path, svg_file_paths) 65 svg_file_paths_to_convert = devtools_file_hashes.files_with_invalid_hashes(hashe s_file_path, svg_file_paths)
81 svg_file_names = [re.sub(".svg$", "", re.sub(".*/", "", file_path)) for file_pat h in svg_file_paths_to_convert] 66 svg_file_names = [re.sub(".svg$", "", re.sub(".*/", "", file_path)) for file_pat h in svg_file_paths_to_convert]
82 67
83 68
84 def convert_svg_to_png(svg_file_name, png_file_name, dpi): 69 def convert_svg_to_png(svg_file_name, png_file_name, dpi):
85 svg_full_path = image_sources_path + "/" + svg_file_name + ".svg" 70 svg_full_path = image_sources_path + "/" + svg_file_name + ".svg"
86 png_full_path = images_path + "/" + png_file_name + ".png" 71 png_full_path = images_path + "/" + png_file_name + ".png"
87 convert_command = "inkscape -f %s -e %s -d %s" % (svg_full_path, png_full_pa th, dpi) 72 convert_command = "inkscape -f %s -e %s -d %s" % (svg_full_path, png_full_pa th, dpi)
88 proc = subprocess.Popen(convert_command, stdout=subprocess.PIPE, stderr=subp rocess.STDOUT, shell=True) 73 proc = subprocess.Popen(convert_command, stdout=subprocess.PIPE, stderr=subp rocess.STDOUT, shell=True)
89 return proc 74 return proc
90 75
91 processes = {} 76 processes = {}
92 for file_name in svg_file_names: 77 for file_name in svg_file_names:
93 name = re.sub(".svg$", "", file_name) 78 name = re.sub(".svg$", "", file_name)
94 name2x = name + "_2x" 79 name2x = name + "_2x"
95 processes[name] = convert_svg_to_png(name, name, 90) 80 processes[name] = convert_svg_to_png(name, name, 90)
96 processes[name2x] = convert_svg_to_png(name, name2x, 180) 81 processes[name2x] = convert_svg_to_png(name, name2x, 180)
97 82
98 for file_name, proc in processes.items(): 83 for file_name, proc in processes.items():
99 (convert_out, _) = proc.communicate() 84 (convert_out, _) = proc.communicate()
100 print("Conversion of %s finished: %s" % (file_name, convert_out)) 85 print("Conversion of %s finished: %s" % (file_name, convert_out))
101 86
102 devtools_file_hashes.update_file_hashes(hashes_file_path, svg_file_paths) 87 devtools_file_hashes.update_file_hashes(hashes_file_path, svg_file_paths)
OLDNEW
« no previous file with comments | « Source/devtools/front_end/inspector.css ('k') | Source/devtools/scripts/optimize_png_images.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698