Index: cms/sources.py |
=================================================================== |
--- a/cms/sources.py |
+++ b/cms/sources.py |
@@ -53,17 +53,17 @@ |
locale = default_locale |
else: |
logging.warning('Link to %s cannot be resolved', page) |
parts = page.split('/') |
if parts[-1] == default_page: |
page = '/'.join(parts[:-1]) |
- path = '/%s/%s' % (locale, page) |
+ path = '/{}/{}'.format(locale, page) |
Sebastian Noack
2016/07/01 14:56:23
As mentioned in the other review, please remove th
Jon Sonesen
2016/07/01 15:58:12
This is already handled. This patch set was upload
|
return locale, urlparse.urlunparse(parsed[0:2] + (path,) + parsed[3:]) |
def read_config(self): |
configdata = self.read_file('settings.ini')[0] |
config = ConfigParser.SafeConfigParser() |
config.readfp(StringIO(configdata)) |
return config |
@@ -75,17 +75,17 @@ |
return namespace |
# |
# Page helpers |
# |
@staticmethod |
def page_filename(page, format): |
- return 'pages/%s.%s' % (page, format) |
+ return 'pages/{}.{}'.format(page, format) |
def list_pages(self): |
for filename in self.list_files('pages'): |
root, ext = os.path.splitext(filename) |
format = ext[1:].lower() |
yield root, format |
def has_page(self, page, format=None): |
@@ -102,38 +102,38 @@ |
return self.read_file(self.page_filename(page, format)) |
# |
# Localizable files helpers |
# |
@staticmethod |
def localizable_file_filename(locale, filename): |
- return 'locales/%s/%s' % (locale, filename) |
+ return 'locales/{}/{}'.format(locale, filename) |
def list_localizable_files(self): |
default_locale = self.read_config().get('general', 'defaultlocale') |
return filter( |
lambda f: os.path.splitext(f)[1].lower() != '.json', |
- self.list_files('locales/%s' % default_locale) |
+ self.list_files('locales/{}'.format(default_locale)) |
) |
def has_localizable_file(self, locale, filename): |
return self.has_file(self.localizable_file_filename(locale, filename)) |
def read_localizable_file(self, locale, filename): |
return self.read_file(self.localizable_file_filename(locale, filename), binary=True)[0] |
# |
# Static file helpers |
# |
@staticmethod |
def static_filename(filename): |
- return 'static/%s' % filename |
+ return 'static/{}'.format(filename) |
def list_static(self): |
return self.list_files('static') |
def has_static(self, filename): |
return self.has_file(self.static_filename(filename)) |
def read_static(self, filename): |
@@ -178,40 +178,40 @@ |
return result |
# |
# Template helpers |
# |
@staticmethod |
def template_filename(template): |
- return 'templates/%s.tmpl' % template |
+ return 'templates/{}.tmpl'.format(template) |
def read_template(self, template): |
return self.read_file(self.template_filename(template)) |
# |
# Include helpers |
# |
@staticmethod |
def include_filename(include, format): |
- return 'includes/%s.%s' % (include, format) |
+ return 'includes/{}.{}'.format(include, format) |
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): |
command = ['hg', '-R', repo, 'archive', '-r', 'default', |
- '-t', 'uzip', '-p', '.', '-'] |
+ '-t', 'uzip', '-p', 'root', '-'] |
data = subprocess.check_output(command) |
self._archive = zipfile.ZipFile(StringIO(data), mode='r') |
command = ['hg', '-R', repo, 'id', '-n', '-r', 'default'] |
self.version = subprocess.check_output(command).strip() |
self._name = os.path.basename(repo.rstrip(os.path.sep)) |
@@ -222,29 +222,29 @@ |
self.close() |
return False |
def close(self): |
self._archive.close() |
def has_file(self, filename): |
try: |
- self._archive.getinfo('./%s' % filename) |
+ self._archive.getinfo('root/{}'.format(filename)) |
except KeyError: |
return False |
return True |
def read_file(self, filename, binary=False): |
- data = self._archive.read('./%s' % filename) |
+ data = self._archive.read('root/{}'.format(filename)) |
if not binary: |
data = data.decode('utf-8') |
- return (data, '%s!%s' % (self._name, filename)) |
+ return (data, '{}!{}'.format(self._name, filename)) |
def list_files(self, subdir): |
- prefix = './%s/' % 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 |