|
1 #!/usr/bin/env python |
|
2 # -*- coding: utf-8 -*- |
|
3 # |
|
4 # ============================================================================ |
|
5 # Name : installs.py |
|
6 # Part of : Hb |
|
7 # Description : Hb themes script for generating installs.pri |
|
8 # Version : %version: % |
|
9 # |
|
10 # Copyright (c) 2008-2010 Nokia. All rights reserved. |
|
11 # This material, including documentation and any related computer |
|
12 # programs, is protected by copyright controlled by Nokia. All |
|
13 # rights are reserved. Copying, including reproducing, storing, |
|
14 # adapting or translating, any or all of this material requires the |
|
15 # prior written consent of Nokia. This material also contains |
|
16 # confidential information which may not be disclosed to others |
|
17 # without the prior written consent of Nokia. |
|
18 # ============================================================================ |
|
19 |
|
20 import os |
|
21 import re |
|
22 import sys |
|
23 import fnmatch |
|
24 import optparse |
|
25 import posixpath |
|
26 |
|
27 # ============================================================================ |
|
28 # Globals |
|
29 # ============================================================================ |
|
30 INPUT_DIR = os.getcwd() |
|
31 OUTPUT_DIR = os.getcwd() |
|
32 INCLUDE = None |
|
33 EXCLUDE = None |
|
34 |
|
35 # ============================================================================ |
|
36 # OptionParser |
|
37 # ============================================================================ |
|
38 class OptionParser(optparse.OptionParser): |
|
39 def __init__(self): |
|
40 optparse.OptionParser.__init__(self) |
|
41 self.add_option("-i", "--input", dest="input", metavar="dir", |
|
42 help="specify the input <dir> (default %s)" % INPUT_DIR) |
|
43 self.add_option("-o", "--output", dest="output", metavar="dir", |
|
44 help="specify the output <dir> (default %s)" % OUTPUT_DIR) |
|
45 self.add_option("--include", dest="include", action="append", metavar="pattern", |
|
46 help="specify the include <pattern> (default %s)" % INCLUDE) |
|
47 self.add_option("--exclude", dest="exclude", action="append", metavar="pattern", |
|
48 help="specify the exclude <pattern> (default %s)" % EXCLUDE) |
|
49 |
|
50 # ============================================================================ |
|
51 # Utils |
|
52 # ============================================================================ |
|
53 if not hasattr(os.path, "relpath"): |
|
54 def relpath(path, start=os.curdir): |
|
55 abspath = os.path.abspath(path) |
|
56 absstart = os.path.abspath(start) |
|
57 if abspath == absstart: |
|
58 return "." |
|
59 i = len(absstart) |
|
60 if not absstart.endswith(os.path.sep): |
|
61 i += len(os.path.sep) |
|
62 if not abspath.startswith(absstart): |
|
63 i = 0 |
|
64 return abspath[i:] |
|
65 os.path.relpath = relpath |
|
66 |
|
67 def make_target(path): |
|
68 # generate a compatible make target name from path |
|
69 target = os.path.splitdrive(path)[1].strip("\\/") |
|
70 return "_".join(re.split("[\\\/\.]+", target)) |
|
71 |
|
72 def write_pri(filepath, input_dir): |
|
73 outpath = os.path.dirname(filepath) |
|
74 if not os.path.exists(outpath): |
|
75 os.makedirs(outpath) |
|
76 out = open(filepath, "w") |
|
77 |
|
78 roots = [] |
|
79 for root, dirs, files in os.walk(input_dir): |
|
80 for file in files: |
|
81 filepath = os.path.abspath(root + "/" + file).replace("\\", "/") |
|
82 filepath = os.path.splitdrive(filepath)[1] |
|
83 if include_exclude(filepath): |
|
84 target = make_target(root) |
|
85 relpath = os.path.relpath(root, input_dir).replace("\\", "/") |
|
86 if os.path.splitext(file)[1] == ".zip": |
|
87 out.write("symbian:BLD_INF_RULES.prj_exports += \":zip %s $${EPOCROOT}epoc32/data/z/resource/hb/themes/%s/\"\n" % (filepath, relpath)) |
|
88 out.write("symbian:BLD_INF_RULES.prj_exports += \":zip %s $${EPOCROOT}epoc32/winscw/c/resource/hb/themes/%s/\"\n" % (filepath, relpath)) |
|
89 out.write("!isEmpty(%s.commands): %s.commands += &&\n" % (target, target)) |
|
90 out.write("%s.commands += $$QMAKE_UNZIP %s -d $$(HB_THEMES_DIR)/themes/%s\n" % (target, filepath, relpath)) |
|
91 else: |
|
92 out.write("symbian:BLD_INF_RULES.prj_exports += \"%s $${EPOCROOT}epoc32/data/z/resource/hb/themes/%s/\"\n" % (filepath, relpath)) |
|
93 out.write("symbian:BLD_INF_RULES.prj_exports += \"%s $${EPOCROOT}epoc32/winscw/c/resource/hb/themes/%s/\"\n" % (filepath, relpath)) |
|
94 out.write("%s.files += %s\n" % (target, filepath)) |
|
95 if root not in roots: |
|
96 out.write("%s.CONFIG += no_build\n" % target) |
|
97 out.write("%s.path = $$(HB_THEMES_DIR)/themes/%s\n" % (target, relpath)) |
|
98 out.write("INSTALLS += %s\n" % target) |
|
99 roots.append(root) |
|
100 out.close() |
|
101 return 0 |
|
102 |
|
103 def include_exclude(filepath): |
|
104 global INCLUDE, EXCLUDE |
|
105 result = True |
|
106 if INCLUDE != None: |
|
107 for pattern in INCLUDE: |
|
108 if not fnmatch.fnmatch(filepath, pattern): |
|
109 result = False |
|
110 if EXCLUDE != None: |
|
111 for pattern in EXCLUDE: |
|
112 if fnmatch.fnmatch(filepath, pattern): |
|
113 result = False |
|
114 return result |
|
115 |
|
116 # ============================================================================ |
|
117 # main() |
|
118 # ============================================================================ |
|
119 def main(): |
|
120 global INPUT_DIR, OUTPUT_DIR, INCLUDE, EXCLUDE |
|
121 |
|
122 parser = OptionParser() |
|
123 (options, args) = parser.parse_args() |
|
124 |
|
125 if options.input != None: |
|
126 INPUT_DIR = options.input |
|
127 if options.output != None: |
|
128 OUTPUT_DIR = options.output |
|
129 if options.include != None: |
|
130 INCLUDE = options.include |
|
131 if options.exclude != None: |
|
132 EXCLUDE = options.exclude |
|
133 |
|
134 print "Generating: %s/installs.pri" % os.path.basename(OUTPUT_DIR) |
|
135 return write_pri(OUTPUT_DIR + "/installs.pri", INPUT_DIR) |
|
136 |
|
137 if __name__ == "__main__": |
|
138 sys.exit(main()) |