95 self.name = name |
96 self.name = name |
96 self.paths = [] |
97 self.paths = [] |
97 self.files = {} |
98 self.files = {} |
98 self.archives = {} |
99 self.archives = {} |
99 |
100 |
|
101 def add_file(self, filepath): |
|
102 if self._include(filepath): |
|
103 filepath = filepath.replace("\\", "/") |
|
104 path = os.path.split(filepath)[0] |
|
105 extension = os.path.splitext(filepath)[1] |
|
106 if extension == ".zip": |
|
107 if path not in self.archives: |
|
108 self.archives[path] = list() |
|
109 if filepath not in self.archives[path]: |
|
110 self.archives[path].append(filepath) |
|
111 else: |
|
112 if path not in self.files: |
|
113 self.files[path] = list() |
|
114 if filepath not in self.files[path]: |
|
115 self.files[path].append(filepath) |
|
116 |
100 def initialize(self): |
117 def initialize(self): |
101 for path in self.paths: |
118 for path in self.paths: |
102 for root, dirs, files in os.walk(path): |
119 for root, dirs, files in os.walk(path): |
103 for file in files: |
120 for file in files: |
104 filepath = posixpath.join(root, file).replace("\\", "/") |
121 self.add_file(os.path.join(root, file)) |
105 if self._include(filepath): |
|
106 extension = os.path.splitext(filepath)[1] |
|
107 if extension == ".zip": |
|
108 if root not in self.archives: |
|
109 self.archives[root] = list() |
|
110 self.archives[root].append(filepath) |
|
111 else: |
|
112 if root not in self.files: |
|
113 self.files[root] = list() |
|
114 self.files[root].append(filepath) |
|
115 |
122 |
116 def write_iby(self, ibypath): |
123 def write_iby(self, ibypath): |
117 global SOURCE_PREFIX, TARGET_PREFIX, EXIT_STATUS |
124 global SOURCE_PREFIX, TARGET_PREFIX, EXIT_STATUS |
118 outpath = os.path.dirname(ibypath) |
125 outpath = os.path.dirname(ibypath) |
119 if not os.path.exists(outpath): |
126 if not os.path.exists(outpath): |
151 EXIT_STATUS = -1 |
158 EXIT_STATUS = -1 |
152 out.write("\n") |
159 out.write("\n") |
153 out.write("#endif __%s_IBY__\n" % self.name.upper()) |
160 out.write("#endif __%s_IBY__\n" % self.name.upper()) |
154 out.close() |
161 out.close() |
155 |
162 |
|
163 def write_thx(self, thxpath): |
|
164 global SOURCE_PREFIX, TARGET_PREFIX, EXIT_STATUS |
|
165 outpath = os.path.dirname(thxpath) |
|
166 if not os.path.exists(outpath): |
|
167 os.makedirs(outpath) |
|
168 archive = zipfile.ZipFile(thxpath, "w") |
|
169 os.chdir(INPUT_DIR) |
|
170 written_entries = list() |
|
171 for path, files in self.files.iteritems(): |
|
172 relpath = os.path.relpath(path, INPUT_DIR).replace("\\", "/") |
|
173 for filepath in files: |
|
174 filename = os.path.basename(filepath) |
|
175 entry = posixpath.join(relpath, filename) |
|
176 if entry not in written_entries: |
|
177 written_entries.append(entry) |
|
178 archive.write(entry) |
|
179 else: |
|
180 print "ERROR: %s duplicate entry %s" % (thxpath, entry) |
|
181 EXIT_STATUS = -1 |
|
182 archive.close() |
|
183 |
|
184 def hidden(self): |
|
185 result = False |
|
186 config = ConfigParser.ConfigParser() |
|
187 indexthemepath = INPUT_DIR + '/icons/' + self.name + '/index.theme' |
|
188 if os.path.exists(indexthemepath): |
|
189 config.read(indexthemepath) |
|
190 result = config.getboolean('Icon Theme', 'Hidden') |
|
191 return result |
|
192 |
156 def _include(self, filepath): |
193 def _include(self, filepath): |
157 result = True |
194 result = True |
158 if INCLUDE != None: |
195 if INCLUDE != None: |
159 for pattern in INCLUDE: |
196 for pattern in INCLUDE: |
160 if not fnmatch.fnmatch(filepath, pattern): |
197 if not fnmatch.fnmatch(filepath, pattern): |
177 themepath = posixpath.join(basepath, theme) |
214 themepath = posixpath.join(basepath, theme) |
178 if os.path.isdir(themepath): |
215 if os.path.isdir(themepath): |
179 if theme not in themes: |
216 if theme not in themes: |
180 themes[theme] = Theme(theme) |
217 themes[theme] = Theme(theme) |
181 themes[theme].paths.append(themepath) |
218 themes[theme].paths.append(themepath) |
|
219 # special case: themeindex |
|
220 themeindex = os.path.join(path, theme + ".themeindex") |
|
221 if os.path.exists(themeindex): |
|
222 themes[theme].add_file(themeindex) |
182 return themes |
223 return themes |
183 |
224 |
184 # ============================================================================ |
225 # ============================================================================ |
185 # main() |
226 # main() |
186 # ============================================================================ |
227 # ============================================================================ |
206 TARGET_PREFIX = options.targetprefix |
247 TARGET_PREFIX = options.targetprefix |
207 |
248 |
208 themes = lookup_themes(INPUT_DIR) |
249 themes = lookup_themes(INPUT_DIR) |
209 for name, theme in themes.iteritems(): |
250 for name, theme in themes.iteritems(): |
210 theme.initialize() |
251 theme.initialize() |
211 print "Generating: %s.iby" % name |
252 if theme.hidden(): |
212 theme.write_iby(posixpath.join(OUTPUT_DIR, "%s.iby" % name)) |
253 print "Generating: %s.iby" % name |
|
254 theme.write_iby(posixpath.join(OUTPUT_DIR, "%s.iby" % name)) |
|
255 else: |
|
256 print "Generating: %s.thx" % name |
|
257 theme.write_thx(posixpath.join(OUTPUT_DIR, "%s.thx" % name)) |
213 |
258 |
214 return EXIT_STATUS |
259 return EXIT_STATUS |
215 |
260 |
216 if __name__ == "__main__": |
261 if __name__ == "__main__": |
217 sys.exit(main()) |
262 sys.exit(main()) |