Commit 19246a72 authored by Demetrios Papadopoulos's avatar Demetrios Papadopoulos Committed by Commit Bot

Revert "Use cpp file map to unpack gzipped resources"

This reverts commit 0e1e6eb3.

Reason for revert:
 - gzipped_resource_* Grit output no longer exists.
 - the feature added by this CL is not actually used.
 - if it ends up needed, an alternative exists (inspect gzip header)

Original change's description:
> Use cpp file map to unpack gzipped resources
>
> We can get gzipped flag from gzipped_resource_map_source or
> gzipped_resource_file_map_source and use it to unpack gzipped resources
> with unpack.py.
>
> Bug: 738243
> Change-Id: I1bf56126f702fa6efbd2b3e8806ade9bdf904d1f
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1518520
> Commit-Queue: Dmitry Guketlev <yavanosta@yandex-team.ru>
> Reviewed-by: Dan Beam <dbeam@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#640738}

TBR=dbeam@chromium.org,dpapad@chromium.org,aee@chromium.org,yavanosta@yandex-team.ru

# Not skipping CQ checks because original CL landed > 1 day ago.

Bug: 961063
Change-Id: If5f277929127207d018e9da30b7b6714000db2ee
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1612088
Commit-Queue: Demetrios Papadopoulos <dpapad@chromium.org>
Reviewed-by: default avatarDemetrios Papadopoulos <dpapad@chromium.org>
Cr-Commit-Position: refs/heads/master@{#659721}
parent 8eb7150b
......@@ -4,9 +4,6 @@
# found in the LICENSE file.
import argparse
import collections
import cStringIO
import gzip
import os
import re
import sys
......@@ -23,16 +20,9 @@ _SRC_PATH = os.path.normpath(os.path.join(_HERE_PATH, '..', '..', '..'))
sys.path.insert(1, os.path.join(_SRC_PATH, 'tools', 'grit'))
from grit.format import data_pack
ResourceFile = collections.namedtuple('ResourceFile',
['path', 'gzipped'])
def UngzipString(data):
# Ungzipping using Python's built in gzip.
with gzip.GzipFile(fileobj=cStringIO.StringIO(data)) as gzip_file:
return gzip_file.read()
def ParseLine(line):
return re.match(' {"([^"]+)", ([^},]+)(?:, ([^},]+))?', line)
return re.match(' {"([^"]+)", ([^},]+)', line)
def Unpack(pak_path, out_path):
......@@ -53,29 +43,23 @@ def Unpack(pak_path, out_path):
assert resource_ids
# Associate numerical string IDs to files.
resource_files = dict()
resource_filenames = dict()
resources_map_path = os.path.join(pak_dir, 'grit', pak_id + '_map.cc')
with open(resources_map_path) as resources_map:
for line in resources_map:
res = ParseLine(line)
if res:
resource_files[res.group(2)] = ResourceFile(
path=res.group(1),
gzipped=res.group(3) == 'true')
assert resource_files
resource_filenames[res.group(2)] = res.group(1)
assert resource_filenames
# Extract packed files, while preserving directory structure.
for (resource_id, text) in data.resources.iteritems():
resource_file = resource_files[resource_ids[resource_id]]
file_path = resource_file.path
file_gzipped = resource_file.gzipped
file_dir = os.path.join(out_path, os.path.dirname(file_path))
if not os.path.exists(file_dir):
os.makedirs(file_dir)
if file_gzipped:
text = UngzipString(text)
with open(os.path.join(out_path, file_path), 'w') as f:
f.write(text)
filename = resource_filenames[resource_ids[resource_id]]
dirname = os.path.join(out_path, os.path.dirname(filename))
if not os.path.exists(dirname):
os.makedirs(dirname)
with open(os.path.join(out_path, filename), 'w') as file:
file.write(text)
def main():
......
......@@ -15,13 +15,6 @@ class UnpackPakTest(unittest.TestCase):
self.assertTrue(unpack_pak.ParseLine(' {"path.js", IDR_PATH, false}'))
self.assertTrue(unpack_pak.ParseLine(' {"path.js", IDR_PATH, true}'))
def testUngzipString(self):
self.assertEqual(
unpack_pak.UngzipString(
'\x1f\x8b\x08\x00\x00\x00\x00\x00\x02\xff\xcbH\xcd\xc9\xc9W' +
'(\xcf/\xcaI\x01\x00\x85\x11J\r\x0b\x00\x00\x00'),
'hello world')
if __name__ == '__main__':
unittest.main()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment