OLD | NEW |
1 # This file is part of the Adblock Plus web scripts, | 1 # This file is part of the Adblock Plus web scripts, |
2 # Copyright (C) 2006-2016 Eyeo GmbH | 2 # Copyright (C) 2006-2016 Eyeo GmbH |
3 # | 3 # |
4 # Adblock Plus is free software: you can redistribute it and/or modify | 4 # Adblock Plus is free software: you can redistribute it and/or modify |
5 # it under the terms of the GNU General Public License version 3 as | 5 # it under the terms of the GNU General Public License version 3 as |
6 # published by the Free Software Foundation. | 6 # published by the Free Software Foundation. |
7 # | 7 # |
8 # Adblock Plus is distributed in the hope that it will be useful, | 8 # Adblock Plus is distributed in the hope that it will be useful, |
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of | 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 def has_include(self, include, format): | 199 def has_include(self, include, format): |
200 return self.has_file(self.include_filename(include, format)) | 200 return self.has_file(self.include_filename(include, format)) |
201 | 201 |
202 def read_include(self, include, format): | 202 def read_include(self, include, format): |
203 return self.read_file(self.include_filename(include, format)) | 203 return self.read_file(self.include_filename(include, format)) |
204 | 204 |
205 | 205 |
206 class MercurialSource(Source): | 206 class MercurialSource(Source): |
207 def __init__(self, repo): | 207 def __init__(self, repo): |
208 command = ['hg', '-R', repo, 'archive', '-r', 'default', | 208 command = ['hg', '-R', repo, 'archive', '-r', 'default', |
209 '-t', 'uzip', '-p', '.', '-'] | 209 '-t', 'uzip', '-p', 'root', '-'] |
210 data = subprocess.check_output(command) | 210 data = subprocess.check_output(command) |
211 self._archive = zipfile.ZipFile(StringIO(data), mode='r') | 211 self._archive = zipfile.ZipFile(StringIO(data), mode='r') |
212 | 212 |
213 command = ['hg', '-R', repo, 'id', '-n', '-r', 'default'] | 213 command = ['hg', '-R', repo, 'id', '-n', '-r', 'default'] |
214 self.version = subprocess.check_output(command).strip() | 214 self.version = subprocess.check_output(command).strip() |
215 | 215 |
216 self._name = os.path.basename(repo.rstrip(os.path.sep)) | 216 self._name = os.path.basename(repo.rstrip(os.path.sep)) |
217 | 217 |
218 def __enter__(self): | 218 def __enter__(self): |
219 return self | 219 return self |
220 | 220 |
221 def __exit__(self, type, value, traceback): | 221 def __exit__(self, type, value, traceback): |
222 self.close() | 222 self.close() |
223 return False | 223 return False |
224 | 224 |
225 def close(self): | 225 def close(self): |
226 self._archive.close() | 226 self._archive.close() |
227 | 227 |
228 def has_file(self, filename): | 228 def has_file(self, filename): |
229 try: | 229 try: |
230 self._archive.getinfo('./%s' % filename) | 230 self._archive.getinfo('root/' + filename) |
231 except KeyError: | 231 except KeyError: |
232 return False | 232 return False |
233 return True | 233 return True |
234 | 234 |
235 def read_file(self, filename, binary=False): | 235 def read_file(self, filename, binary=False): |
236 data = self._archive.read('./%s' % filename) | 236 data = self._archive.read('root/' + filename) |
237 if not binary: | 237 if not binary: |
238 data = data.decode('utf-8') | 238 data = data.decode('utf-8') |
239 return (data, '%s!%s' % (self._name, filename)) | 239 return (data, '%s!%s' % (self._name, filename)) |
240 | 240 |
241 def list_files(self, subdir): | 241 def list_files(self, subdir): |
242 prefix = './%s/' % subdir | 242 prefix = 'root/{}/'.format(subdir) |
243 for filename in self._archive.namelist(): | 243 for filename in self._archive.namelist(): |
244 if filename.startswith(prefix): | 244 if filename.startswith(prefix): |
245 yield filename[len(prefix):] | 245 yield filename[len(prefix):] |
246 | 246 |
247 if os.name == 'posix': | 247 if os.name == 'posix': |
248 def get_cache_dir(self): | 248 def get_cache_dir(self): |
249 return '/var/cache/' + self._name | 249 return '/var/cache/' + self._name |
250 | 250 |
251 | 251 |
252 class FileSource(Source): | 252 class FileSource(Source): |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 path = os.path.join(dir, filename) | 292 path = os.path.join(dir, filename) |
293 if os.path.isfile(path): | 293 if os.path.isfile(path): |
294 result.append(relpath + filename) | 294 result.append(relpath + filename) |
295 elif os.path.isdir(path): | 295 elif os.path.isdir(path): |
296 do_list(path, relpath + filename + '/') | 296 do_list(path, relpath + filename + '/') |
297 do_list(self.get_path(subdir), '') | 297 do_list(self.get_path(subdir), '') |
298 return result | 298 return result |
299 | 299 |
300 def get_cache_dir(self): | 300 def get_cache_dir(self): |
301 return os.path.join(self._dir, 'cache') | 301 return os.path.join(self._dir, 'cache') |
OLD | NEW |