| OLD | NEW |
| 1 # Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2014 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import os | 5 import os |
| 6 import sys | 6 import sys |
| 7 import subprocess | 7 import subprocess |
| 8 import tempfile | 8 import tempfile |
| 9 import StringIO | 9 import StringIO |
| 10 | 10 |
| 11 from tvcm import html_generation_controller | 11 from py_vulcanize import html_generation_controller |
| 12 | 12 |
| 13 | 13 |
| 14 html_warning_message = """ | 14 html_warning_message = """ |
| 15 | 15 |
| 16 | 16 |
| 17 <!-- | 17 <!-- |
| 18 WARNING: This file is auto generated. | 18 WARNING: This file is auto generated. |
| 19 | 19 |
| 20 Do not edit directly. | 20 Do not edit directly. |
| 21 --> | 21 --> |
| (...skipping 22 matching lines...) Expand all Loading... |
| 44 """ | 44 """ |
| 45 | 45 |
| 46 | 46 |
| 47 def _AssertIsUTF8(f): | 47 def _AssertIsUTF8(f): |
| 48 if isinstance(f, StringIO.StringIO): | 48 if isinstance(f, StringIO.StringIO): |
| 49 return | 49 return |
| 50 assert f.encoding == 'utf-8' | 50 assert f.encoding == 'utf-8' |
| 51 | 51 |
| 52 | 52 |
| 53 def _MinifyJS(input_js): | 53 def _MinifyJS(input_js): |
| 54 tvcm_path = os.path.abspath(os.path.join( | 54 py_vulcanize_path = os.path.abspath(os.path.join( |
| 55 os.path.dirname(__file__), '..')) | 55 os.path.dirname(__file__), '..')) |
| 56 rjsmin_path = os.path.abspath( | 56 rjsmin_path = os.path.abspath( |
| 57 os.path.join(tvcm_path, 'third_party', 'rjsmin', 'rjsmin.py')) | 57 os.path.join(py_vulcanize_path, 'third_party', 'rjsmin', 'rjsmin.py')) |
| 58 | 58 |
| 59 with tempfile.NamedTemporaryFile() as _: | 59 with tempfile.NamedTemporaryFile() as _: |
| 60 args = [ | 60 args = [ |
| 61 'python', | 61 'python', |
| 62 rjsmin_path | 62 rjsmin_path |
| 63 ] | 63 ] |
| 64 p = subprocess.Popen(args, | 64 p = subprocess.Popen(args, |
| 65 stdin=subprocess.PIPE, | 65 stdin=subprocess.PIPE, |
| 66 stdout=subprocess.PIPE, | 66 stdout=subprocess.PIPE, |
| 67 stderr=subprocess.PIPE) | 67 stderr=subprocess.PIPE) |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 if len(attrs) > 0: | 169 if len(attrs) > 0: |
| 170 output_file.write('<script %s>\n' % ' '.join(attrs)) | 170 output_file.write('<script %s>\n' % ' '.join(attrs)) |
| 171 else: | 171 else: |
| 172 output_file.write('<script>\n') | 172 output_file.write('<script>\n') |
| 173 if self.text_content: | 173 if self.text_content: |
| 174 output_file.write(self.text_content) | 174 output_file.write(self.text_content) |
| 175 output_file.write('</script>\n') | 175 output_file.write('</script>\n') |
| 176 | 176 |
| 177 | 177 |
| 178 def _MinifyCSS(css_text): | 178 def _MinifyCSS(css_text): |
| 179 tvcm_path = os.path.abspath(os.path.join( | 179 py_vulcanize_path = os.path.abspath(os.path.join( |
| 180 os.path.dirname(__file__), '..')) | 180 os.path.dirname(__file__), '..')) |
| 181 rcssmin_path = os.path.abspath( | 181 rcssmin_path = os.path.abspath( |
| 182 os.path.join(tvcm_path, 'third_party', 'rcssmin', 'rcssmin.py')) | 182 os.path.join(py_vulcanize_path, 'third_party', 'rcssmin', 'rcssmin.py')) |
| 183 | 183 |
| 184 with tempfile.NamedTemporaryFile() as _: | 184 with tempfile.NamedTemporaryFile() as _: |
| 185 rcssmin_args = ['python', rcssmin_path] | 185 rcssmin_args = ['python', rcssmin_path] |
| 186 p = subprocess.Popen(rcssmin_args, | 186 p = subprocess.Popen(rcssmin_args, |
| 187 stdin=subprocess.PIPE, | 187 stdin=subprocess.PIPE, |
| 188 stdout=subprocess.PIPE, | 188 stdout=subprocess.PIPE, |
| 189 stderr=subprocess.PIPE) | 189 stderr=subprocess.PIPE) |
| 190 res = p.communicate(input=css_text) | 190 res = p.communicate(input=css_text) |
| 191 errorcode = p.wait() | 191 errorcode = p.wait() |
| 192 if errorcode != 0: | 192 if errorcode != 0: |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 output_file.write('<script>\n') | 265 output_file.write('<script>\n') |
| 266 js = GenerateJS(load_sequence, minify=minify, report_sizes=report_sizes) | 266 js = GenerateJS(load_sequence, minify=minify, report_sizes=report_sizes) |
| 267 output_file.write(js) | 267 output_file.write(js) |
| 268 output_file.write('</script>\n') | 268 output_file.write('</script>\n') |
| 269 | 269 |
| 270 for extra_script in extra_scripts: | 270 for extra_script in extra_scripts: |
| 271 extra_script.WriteToFile(output_file) | 271 extra_script.WriteToFile(output_file) |
| 272 | 272 |
| 273 if output_html_head_and_body: | 273 if output_html_head_and_body: |
| 274 output_file.write('</head>\n <body>\n </body>\n</html>\n') | 274 output_file.write('</head>\n <body>\n </body>\n</html>\n') |
| OLD | NEW |