Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: cms/sources.py

Issue 29805580: Issue 6728 - Remove Mercurial dependency (Closed)
Patch Set: Addremove files to diff Created June 12, 2018, 11:01 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/conftest.py » ('j') | tests/conftest.py » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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)
mathias 2018/06/13 06:04:50 I think this should be a way higher range. The lik
Vasily Kuznetsov 2018/06/13 13:35:23 Yeah, a range of 10 is too small. This would give
Jon Sonesen 2018/06/14 19:24:14 My bad, meant to increase the size here, it was ju
+
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)
@@ -406,33 +363,25 @@
def create_source(path, cached=False, revision=None):
"""Create a source from path and optional revision.
`cached` flag activates caching. This can be used to optimize performance
if no changes are expected on the filesystem after the source was created.
This is usually the case with static generation (as opposed to dynamic
preview).
- If `revision` option is provided, the `path` is assumed to be pointing to a
- Mercurial repository. In this case the source will return the content of
- selected revision (using `MercurialSource`) instead of the content of the
- directory. Note that any local changes will be ignored in this case.
-
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 = []
« no previous file with comments | « no previous file | tests/conftest.py » ('j') | tests/conftest.py » ('J')

Powered by Google App Engine
This is Rietveld