| OLD | NEW |
| 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 10 matching lines...) Expand all Loading... |
| 21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 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 glob | |
| 32 import hashlib | |
| 33 import os | 31 import os |
| 34 import os.path | 32 import os.path |
| 35 import re | |
| 36 import subprocess | 33 import subprocess |
| 37 import sys | 34 import sys |
| 38 | 35 |
| 39 try: | 36 try: |
| 40 import json | 37 import json |
| 41 except ImportError: | 38 except ImportError: |
| 42 import simplejson as json | 39 import simplejson as json |
| 43 | 40 |
| 44 scripts_path = os.path.dirname(os.path.abspath(__file__)) | 41 scripts_path = os.path.dirname(os.path.abspath(__file__)) |
| 45 devtools_path = os.path.dirname(scripts_path) | 42 devtools_path = os.path.dirname(scripts_path) |
| 46 blink_source_path = os.path.dirname(devtools_path) | 43 blink_source_path = os.path.dirname(devtools_path) |
| 47 blink_path = os.path.dirname(blink_source_path) | 44 blink_path = os.path.dirname(blink_source_path) |
| 48 chromium_src_path = os.path.dirname(os.path.dirname(blink_path)) | 45 chromium_src_path = os.path.dirname(os.path.dirname(blink_path)) |
| 49 devtools_frontend_path = os.path.join(devtools_path, "front_end") | 46 devtools_frontend_path = os.path.join(devtools_path, "front_end") |
| 50 images_path = os.path.join(devtools_frontend_path, "Images") | 47 images_path = os.path.join(devtools_frontend_path, "Images") |
| 51 image_sources_path = os.path.join(images_path, "src") | 48 image_sources_path = os.path.join(images_path, "src") |
| 52 hashes_file_name = "optimize_png.hashes" | 49 hashes_file_name = "optimize_png.hashes" |
| 53 hashes_file_path = os.path.join(image_sources_path, hashes_file_name) | 50 hashes_file_path = os.path.join(image_sources_path, hashes_file_name) |
| 54 | 51 |
| 55 file_names = os.listdir(image_sources_path) | 52 file_names = os.listdir(image_sources_path) |
| 56 svg_file_paths = [os.path.join(image_sources_path, file_name) for file_name in f
ile_names if file_name.endswith(".svg")] | 53 svg_file_paths = [os.path.join(image_sources_path, file_name) for file_name in f
ile_names if file_name.endswith(".svg")] |
| 57 svg_file_paths_to_optimize = devtools_file_hashes.files_with_invalid_hashes(hash
es_file_path, svg_file_paths) | 54 svg_file_paths_to_optimize = devtools_file_hashes.files_with_invalid_hashes(hash
es_file_path, svg_file_paths) |
| 58 svg_file_names = [re.sub(".svg$", "", os.path.basename(file_path)) for file_path
in svg_file_paths_to_optimize] | 55 svg_file_names = [os.path.basename(file_path) for file_path in svg_file_paths_to
_optimize] |
| 59 | 56 |
| 60 optimize_script_path = os.path.join("tools", "resources", "optimize-png-files.sh
") | 57 optimize_script_path = os.path.join("tools", "resources", "optimize-png-files.sh
") |
| 61 | 58 |
| 62 | 59 |
| 63 def check_installed(app_name, package, how_to): | 60 def check_installed(app_name, package, how_to): |
| 64 proc = subprocess.Popen("which %s" % app_name, stdout=subprocess.PIPE, shell
=True) | 61 proc = subprocess.Popen("which %s" % app_name, stdout=subprocess.PIPE, shell
=True) |
| 65 proc.communicate() | 62 proc.communicate() |
| 66 if proc.returncode != 0: | 63 if proc.returncode != 0: |
| 67 print "This script needs \"%s\" to be installed." % app_name | 64 print "This script needs \"%s\" to be installed." % app_name |
| 68 if how_to: | 65 if how_to: |
| (...skipping 15 matching lines...) Expand all Loading... |
| 84 return proc | 81 return proc |
| 85 | 82 |
| 86 if len(svg_file_names): | 83 if len(svg_file_names): |
| 87 print "%d unoptimized png files found." % len(svg_file_names) | 84 print "%d unoptimized png files found." % len(svg_file_names) |
| 88 else: | 85 else: |
| 89 print "All png files are already optimized." | 86 print "All png files are already optimized." |
| 90 sys.exit() | 87 sys.exit() |
| 91 | 88 |
| 92 processes = {} | 89 processes = {} |
| 93 for file_name in svg_file_names: | 90 for file_name in svg_file_names: |
| 94 name = re.sub(".svg$", "", file_name) | 91 name = os.path.splitext(file_name)[0] |
| 95 name2x = name + "_2x" | 92 name2x = name + "_2x" |
| 96 processes[name] = optimize_png(name) | 93 processes[name] = optimize_png(name) |
| 97 processes[name2x] = optimize_png(name2x) | 94 processes[name2x] = optimize_png(name2x) |
| 98 | 95 |
| 99 for file_name, proc in processes.items(): | 96 for file_name, proc in processes.items(): |
| 100 (optimize_out, _) = proc.communicate() | 97 (optimize_out, _) = proc.communicate() |
| 101 print("Optimization of %s finished: %s" % (file_name, optimize_out)) | 98 print("Optimization of %s finished: %s" % (file_name, optimize_out)) |
| 102 | 99 |
| 103 devtools_file_hashes.update_file_hashes(hashes_file_path, svg_file_paths) | 100 devtools_file_hashes.update_file_hashes(hashes_file_path, svg_file_paths) |
| OLD | NEW |