2013-12-23 06:08:44 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# Copyright (C) 2013 Igalia S.L.
|
|
|
|
#
|
|
|
|
# This library is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU Lesser General Public
|
|
|
|
# License as published by the Free Software Foundation; either
|
|
|
|
# version 2 of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This library is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
# Lesser General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Lesser General Public
|
|
|
|
# License along with this library; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
|
2014-04-02 15:38:40 +00:00
|
|
|
import argparse
|
2013-12-23 06:08:44 +00:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
2017-11-08 07:23:38 +00:00
|
|
|
VALID_EXTENSIONS = ['.html', '.js', '.css', '.svg', '.png']
|
2014-04-15 13:13:42 +00:00
|
|
|
COMPRESSIBLE_EXTENSIONS = ['.html', '.js', '.css', '.svg']
|
2014-09-19 09:21:16 +00:00
|
|
|
BASE_DIR = 'WebInspectorUI/'
|
2014-04-02 15:38:40 +00:00
|
|
|
|
|
|
|
|
2017-11-08 07:23:38 +00:00
|
|
|
def get_filenames(directory):
|
2014-09-19 09:21:16 +00:00
|
|
|
filenames = []
|
2014-04-02 15:38:40 +00:00
|
|
|
|
2017-11-08 07:23:38 +00:00
|
|
|
def should_ignore_resource(resource):
|
|
|
|
if resource.startswith(os.path.join('Protocol', 'Legacy')):
|
|
|
|
return True
|
|
|
|
if os.path.splitext(resource)[1] not in VALID_EXTENSIONS:
|
|
|
|
return True
|
|
|
|
|
|
|
|
for root, dirs, files in os.walk(directory):
|
2018-08-20 16:49:10 +00:00
|
|
|
dirs.sort()
|
|
|
|
files.sort()
|
2017-11-08 07:23:38 +00:00
|
|
|
for file in files:
|
|
|
|
filename = os.path.join(root, file)
|
2015-05-26 11:26:51 +00:00
|
|
|
base_dir_index = filename.rfind(BASE_DIR)
|
2017-11-08 07:23:38 +00:00
|
|
|
if base_dir_index == -1:
|
|
|
|
continue
|
|
|
|
|
|
|
|
name = filename[base_dir_index + len(BASE_DIR):]
|
|
|
|
# The result should use forward slashes, thus make sure any os-specific
|
|
|
|
# separator, is properly replaced
|
|
|
|
if os.sep != '/':
|
|
|
|
name = name.replace(os.sep, '/')
|
|
|
|
if not should_ignore_resource(name):
|
2015-05-26 11:26:51 +00:00
|
|
|
filenames.append(name)
|
2017-11-08 07:23:38 +00:00
|
|
|
|
2014-09-19 09:21:16 +00:00
|
|
|
return filenames
|
2014-04-02 15:38:40 +00:00
|
|
|
|
2014-04-15 13:13:42 +00:00
|
|
|
|
|
|
|
def is_compressible(filename):
|
|
|
|
return os.path.splitext(filename)[1] in COMPRESSIBLE_EXTENSIONS
|
|
|
|
|
|
|
|
|
2014-04-02 15:38:40 +00:00
|
|
|
if __name__ == "__main__":
|
|
|
|
parser = argparse.ArgumentParser(description='Generate a GResources file for the inspector.')
|
2017-11-08 07:23:38 +00:00
|
|
|
parser.add_argument('--input', type=str,
|
|
|
|
help='the input directory')
|
2014-04-02 15:38:40 +00:00
|
|
|
parser.add_argument('--output', nargs='?', type=argparse.FileType('w'), default=sys.stdout,
|
|
|
|
help='the output file')
|
|
|
|
|
2014-09-19 09:21:16 +00:00
|
|
|
args = parser.parse_args(sys.argv[1:])
|
2014-04-02 15:38:40 +00:00
|
|
|
|
2014-09-19 09:21:16 +00:00
|
|
|
args.output.write(\
|
2014-04-02 15:38:40 +00:00
|
|
|
"""<?xml version=1.0 encoding=UTF-8?>
|
|
|
|
<gresources>
|
2018-06-14 06:39:15 +00:00
|
|
|
<gresource prefix="/org/webkit/inspector">
|
2014-04-02 15:38:40 +00:00
|
|
|
""")
|
|
|
|
|
2017-11-08 07:23:38 +00:00
|
|
|
for filename in get_filenames(args.input):
|
2014-09-19 09:21:16 +00:00
|
|
|
line = ' <file'
|
|
|
|
if is_compressible(filename):
|
|
|
|
line += ' compressed="true"'
|
2017-11-08 07:23:38 +00:00
|
|
|
if not filename.startswith('Localization'):
|
|
|
|
alias = 'UserInterface/' + filename
|
|
|
|
line += ' alias="%s"' % alias
|
2014-09-19 09:21:16 +00:00
|
|
|
line += '>%s</file>\n' % filename
|
2014-04-15 13:13:42 +00:00
|
|
|
|
2014-09-19 09:21:16 +00:00
|
|
|
args.output.write(line)
|
2014-04-02 15:38:40 +00:00
|
|
|
|
2014-09-19 09:21:16 +00:00
|
|
|
args.output.write(\
|
2014-04-02 15:38:40 +00:00
|
|
|
""" </gresource>
|
2013-12-23 06:08:44 +00:00
|
|
|
</gresources>
|
2014-04-02 15:38:40 +00:00
|
|
|
""")
|