OLD | NEW |
1 # coding: utf-8 | 1 # coding: utf-8 |
2 | 2 |
3 # This Source Code Form is subject to the terms of the Mozilla Public | 3 # This Source Code Form is subject to the terms of the Mozilla Public |
4 # License, v. 2.0. If a copy of the MPL was not distributed with this | 4 # License, v. 2.0. If a copy of the MPL was not distributed with this |
5 # file, You can obtain one at http://mozilla.org/MPL/2.0/. | 5 # file, You can obtain one at http://mozilla.org/MPL/2.0/. |
6 | 6 |
7 # Note: These are the base functions common to all packagers, the actual | 7 # Note: These are the base functions common to all packagers, the actual |
8 # packagers are implemented in packagerGecko and packagerChrome. | 8 # packagers are implemented in packagerGecko and packagerChrome. |
9 | 9 |
10 import sys, os, re, codecs, subprocess, json, zipfile | 10 import sys, os, re, codecs, subprocess, json, zipfile |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 | 81 |
82 def isIncluded(self, relpath): | 82 def isIncluded(self, relpath): |
83 parts = relpath.split('/') | 83 parts = relpath.split('/') |
84 if not parts[0] in self.includedFiles: | 84 if not parts[0] in self.includedFiles: |
85 return False | 85 return False |
86 for part in parts: | 86 for part in parts: |
87 if part in self.ignoredFiles: | 87 if part in self.ignoredFiles: |
88 return False | 88 return False |
89 return True | 89 return True |
90 | 90 |
91 def read(self, path, relpath='', skip=None): | 91 def read(self, path, relpath='', skip=()): |
92 if os.path.isdir(path): | 92 if os.path.isdir(path): |
93 for file in os.listdir(path): | 93 for file in os.listdir(path): |
94 name = relpath + ('/' if relpath != '' else '') + file | 94 name = relpath + ('/' if relpath != '' else '') + file |
95 if (skip == None or file not in skip) and self.isIncluded(name): | 95 if name not in skip and self.isIncluded(name): |
96 self.read(os.path.join(path, file), name) | 96 self.read(os.path.join(path, file), name, skip) |
97 else: | 97 else: |
98 with open(path, 'rb') as file: | 98 with open(path, 'rb') as file: |
99 if relpath in self: | 99 if relpath in self: |
100 print >>sys.stderr, 'Warning: File %s defined multiple times' % relpat
h | 100 print >>sys.stderr, 'Warning: File %s defined multiple times' % relpat
h |
101 else: | 101 self[relpath] = file.read() |
102 self[relpath] = file.read() | |
103 | 102 |
104 def readMappedFiles(self, mappings): | 103 def readMappedFiles(self, mappings): |
105 for item in mappings: | 104 for item in mappings: |
106 target, source = item | 105 target, source = item |
107 | 106 |
108 # Make sure the file is inside an included directory | 107 # Make sure the file is inside an included directory |
109 if '/' in target and not self.isIncluded(target): | 108 if '/' in target and not self.isIncluded(target): |
110 continue | 109 continue |
111 parts = source.split('/') | 110 parts = source.split('/') |
112 path = os.path.join(os.path.dirname(item.source), *parts) | 111 path = os.path.join(os.path.dirname(item.source), *parts) |
(...skipping 16 matching lines...) Expand all Loading... |
129 names = self.keys() | 128 names = self.keys() |
130 names.sort(key=sortKey) | 129 names.sort(key=sortKey) |
131 for name in names: | 130 for name in names: |
132 zip.writestr(name, self[name]) | 131 zip.writestr(name, self[name]) |
133 zip.close() | 132 zip.close() |
134 | 133 |
135 def zipToString(self, sortKey=None): | 134 def zipToString(self, sortKey=None): |
136 buffer = StringIO() | 135 buffer = StringIO() |
137 self.zip(buffer, sortKey=sortKey) | 136 self.zip(buffer, sortKey=sortKey) |
138 return buffer.getvalue() | 137 return buffer.getvalue() |
OLD | NEW |