| Index: cms/sources.py |
| =================================================================== |
| --- a/cms/sources.py |
| +++ b/cms/sources.py |
| @@ -14,19 +14,18 @@ |
| # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| import io |
| import collections |
| import ConfigParser |
| import json |
| import os |
| from StringIO import StringIO |
| -import subprocess |
| +from random import randint |
| import urlparse |
| -import zipfile |
| import logging |
| class Source: |
| def resolve_link(self, url, locale): |
| parsed = urlparse.urlparse(url) |
| page = parsed.path |
| if parsed.scheme != '' or page.startswith('/') or page.startswith('.'): |
| @@ -216,75 +215,33 @@ |
| def has_include(self, include, format): |
| return self.has_file(self.include_filename(include, format)) |
| def read_include(self, include, format): |
| return self.read_file(self.include_filename(include, format)) |
| -class MercurialSource(Source): |
| - def __init__(self, repo, revision): |
| - command = ['hg', '-R', repo, 'archive', '-r', revision, |
| - '-t', 'uzip', '-p', 'root', '-'] |
| - data = subprocess.check_output(command) |
| - self._archive = zipfile.ZipFile(StringIO(data), mode='r') |
| - |
| - command = ['hg', '-R', repo, 'id', '-n', '-r', revision] |
| - self.version = subprocess.check_output(command).strip() |
| - |
| - self._name = os.path.basename(repo.rstrip(os.path.sep)) |
| - |
| - def __enter__(self): |
| - return self |
| - |
| - def __exit__(self, type, value, traceback): |
| - self.close() |
| - return False |
| - |
| - def close(self): |
| - self._archive.close() |
| - |
| - def has_file(self, filename): |
| - try: |
| - self._archive.getinfo('root/' + filename) |
| - except KeyError: |
| - return False |
| - return True |
| - |
| - def read_file(self, filename, binary=False): |
| - data = self._archive.read('root/' + filename) |
| - if not binary: |
| - data = data.decode('utf-8') |
| - return (data, '%s!%s' % (self._name, filename)) |
| - |
| - def list_files(self, subdir): |
| - prefix = 'root/{}/'.format(subdir) |
| - for filename in self._archive.namelist(): |
| - if filename.startswith(prefix): |
| - yield filename[len(prefix):] |
| - |
| - if os.name == 'posix': |
| - def get_cache_dir(self): |
| - return '/var/cache/' + self._name |
| - |
| - |
| class FileSource(Source): |
| def __init__(self, dir): |
| self._dir = dir |
| def __enter__(self): |
| return self |
| def __exit__(self, type, value, traceback): |
| return False |
| def close(self): |
| pass |
| + @property |
| + def version(self): |
| + return randint(1, 10) |
| + |
| def get_path(self, filename): |
| return os.path.join(self._dir, *filename.split('/')) |
| def has_file(self, filename): |
| return os.path.isfile(self.get_path(filename)) |
| def read_file(self, filename, binary=False): |
| path = self.get_path(filename) |
| @@ -419,20 +376,17 @@ |
| If `settings.ini` in the source contains `[paths]` section with an |
| `additional-paths` key that contains the list of additional root folders, |
| `MultiSource` will be instantiated and its bases will be the original |
| source plus an additional source for each additional root folder. |
| `MultiSource` looks up files in its base sources in the order they are |
| provided, so the files in the additional folders will only be used if the |
| original source doesn't contain that file. |
| """ |
| - if revision is not None: |
| - source = MercurialSource(path, revision) |
| - else: |
| - source = FileSource(path) |
| + source = FileSource(path) |
| config = source.read_config() |
| try: |
| ap = config.get('paths', 'additional-paths').strip() |
| additional_paths = filter(None, ap.split()) |
| except (ConfigParser.NoSectionError, ConfigParser.NoOptionError): |
| additional_paths = [] |