Chromium Code Reviews| Index: tools/grit/grit/node/include.py |
| diff --git a/tools/grit/grit/node/include.py b/tools/grit/grit/node/include.py |
| index ebcd53108f503005dadae9ae67b192245fb0a66d..caa7782cbba38ae8988e0122af829d4905a95261 100755 |
| --- a/tools/grit/grit/node/include.py |
| +++ b/tools/grit/grit/node/include.py |
| @@ -6,14 +6,17 @@ |
| """Handling of the <include> element. |
| """ |
| +import gzip |
| import os |
| +import StringIO |
| +import subprocess |
| +import sys |
| +from grit import util |
| import grit.format.html_inline |
| -import grit.format.rc_header |
| import grit.format.rc |
| - |
| +import grit.format.rc_header |
| from grit.node import base |
| -from grit import util |
| class IncludeNode(base.Node): |
| """An <include> element.""" |
| @@ -90,6 +93,31 @@ class IncludeNode(base.Node): |
| filename = self.ToRealPath(self.GetInputPath()) |
| data = util.ReadFile(filename, util.BINARY) |
| + if self.attrs['type'] == 'GZIPPABLE_BINDATA': |
| + raw_data = data |
| + try: |
|
agrieve
2016/05/11 18:29:52
nit: extract this into a private helper function.
smaier
2016/05/13 15:27:25
Done.
|
| + # Make call to OS's gzip to get access to --rsyncable option |
|
agrieve
2016/05/11 18:29:52
nit: end with a period.
smaier
2016/05/13 15:27:25
Done.
|
| + gzip_proc = subprocess.Popen(['gzip', '--stdout', '--rsyncable', |
| + '--best', '--no-name'], |
| + stdin=subprocess.PIPE, |
| + stdout=subprocess.PIPE, |
| + stderr=subprocess.PIPE) |
| + data, stderr = gzip_proc.communicate(raw_data) |
| + if gzip_proc.returncode != 0: |
| + raise subprocess.CalledProcessError(gzip_proc.returncode, 'gzip', |
| + stderr) |
| + except Exception: |
| + if sys.platform == 'linux2': |
| + # Only expecting linux gzip calls to work: windows doesn't ship with |
| + # gzip, and OSX's gzip does not have an --rsyncable option built in. |
| + raise |
|
agrieve
2016/05/11 18:29:52
nit: might be a good idea to store whether this wo
flackr
2016/05/11 18:54:33
I'm a little uncomfortable with maybe using the pl
smaier
2016/05/13 15:27:25
I've decided to move away from the fallback entire
|
| + else: |
| + # On all non-linux platforms, fall back to python's gzip. |
| + gzip_output = StringIO.StringIO() |
| + gzip.GzipFile('', 'wb', 9, gzip_output, 0).write(raw_data) |
|
agrieve
2016/05/11 18:29:52
nit: I think GzipFile probably wants to be closed.
smaier
2016/05/13 15:27:25
Done.
|
| + data = gzip_output.getvalue() |
| + gzip_output.close() |
| + |
| # Include does not care about the encoding, because it only returns binary |
| # data. |
| return id, data |