summaryrefslogtreecommitdiff
path: root/Tools/gtk/generate-inspector-gresource-manifest.py
blob: d319eba0c7c687845ebee123db55f23811989131 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/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

import argparse
import glob
import os
import sys

COMPRESSIBLE_EXTENSIONS = ['.html', '.js', '.css', '.svg']
BASE_DIR = 'WebInspectorUI/'


def get_filenames(args):
    filenames = []

    for pattern in args:
        paths = glob.glob(pattern)
        for filename in paths:
            base_dir_index = filename.rfind(BASE_DIR)
            if base_dir_index != -1:
                name = filename[base_dir_index + len(BASE_DIR):]
		# The result should use forward slashes, thus make sure any os-specific
		# separator, added by the glob.glob() call, is properly replaced
                if os.sep != '/':
                    name = name.replace(os.sep, '/')
                filenames.append(name)
    return filenames


def is_compressible(filename):
    return os.path.splitext(filename)[1] in COMPRESSIBLE_EXTENSIONS


if __name__ == "__main__":
    parser = argparse.ArgumentParser(description='Generate a GResources file for the inspector.')
    parser.add_argument('--output', nargs='?', type=argparse.FileType('w'), default=sys.stdout,
                        help='the output file')
    parser.add_argument('filenames', metavar='FILES', nargs='+',
                        help='the list of files to include')

    args = parser.parse_args(sys.argv[1:])

    args.output.write(\
"""<?xml version=1.0 encoding=UTF-8?>
<gresources>
    <gresource prefix="/org/webkitgtk/inspector">
""")

    for filename in get_filenames(args.filenames):
        line = '        <file'
        if is_compressible(filename):
            line += ' compressed="true"'
        if 'Images/gtk/' in filename:
            line += ' alias="%s"' % filename.replace('gtk/', '')
        line += '>%s</file>\n' % filename

        args.output.write(line)

    args.output.write(\
"""    </gresource>
</gresources>
""")