diff options
Diffstat (limited to 'chrome/tools/build/win/html_inline.py')
-rw-r--r-- | chrome/tools/build/win/html_inline.py | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/chrome/tools/build/win/html_inline.py b/chrome/tools/build/win/html_inline.py index 17d24ca..1ae5ea1 100644 --- a/chrome/tools/build/win/html_inline.py +++ b/chrome/tools/build/win/html_inline.py @@ -38,11 +38,17 @@ This does not inline CSS styles, nor does it inline anything referenced from an inlined file. """ +import os import re import sys import base64 import mimetypes -from os import path + +# TODO(rahulk) The default here will change to 'CHROMIUM' as soon as the buildbots +# are ready with the correct environment variable +DIST_DEFAULT = 'GOOGLE_CHROME' +DIST_ENV_VAR = 'CHROMIUM_BUILD' +DIST_SUBSTR = '%DISTRIBUTION%' def ReadFile(input_filename): """Helper function that returns input_filename as a string. @@ -58,16 +64,18 @@ def ReadFile(input_filename): f.close() return file_contents -def SrcInline(src_match, base_path): +def SrcInline(src_match, base_path, distribution): """regex replace function. Takes a regex match for src="filename", attempts to read the file at 'filename' and returns the src attribute with the file inlined - as a data URI + as a data URI. If it finds DIST_SUBSTR string in file name, replaces + it with distribution. Args: src_match: regex match object with 'filename' named capturing group base_path: path that to look for files in + distribution: string that should replace DIST_SUBSTR Returns: string @@ -78,7 +86,8 @@ def SrcInline(src_match, base_path): # filename is probably a URL, which we don't want to bother inlining return src_match.group(0) - filepath = path.join(base_path, filename) + filename = filename.replace('%DISTRIBUTION%', distribution) + filepath = os.path.join(base_path, filename) mimetype = mimetypes.guess_type(filename)[0] or 'text/plain' inline_data = base64.standard_b64encode(ReadFile(filepath)) @@ -97,11 +106,17 @@ def InlineFile(input_filename, output_filename): output_filename: name of file to be written to """ print "inlining %s to %s" % (input_filename, output_filename) - input_filepath = path.dirname(input_filename) + input_filepath = os.path.dirname(input_filename) + distribution = DIST_DEFAULT + if DIST_ENV_VAR in os.environ.keys(): + distribution = os.environ[DIST_ENV_VAR] + if len(distribution) > 1 and distribution[0] == '_': + distribution = distribution[1:].lower() + def SrcReplace(src_match): """Helper function to provide SrcInline with the base file path""" - return SrcInline(src_match, input_filepath) + return SrcInline(src_match, input_filepath, distribution) # TODO(glen): Make this regex not match src="" text that is not inside a tag flat_text = re.sub('src="(?P<filename>[^"\']*)"', |