Commit 9c734895 authored by Michal Čihař's avatar Michal Čihař

Fixed validation of subprojects with language filter.

The validation now properly honors language filter and does not complain
about duplicate languages which will be filtered out. Also it no longer
filters out template.

Fixes #1023
Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent bc6f6b2d
...@@ -6,6 +6,8 @@ weblate 2.6 ...@@ -6,6 +6,8 @@ weblate 2.6
Released on ? 2016. Released on ? 2016.
* Fixed validation of subprojects with language filter.
weblate 2.5 weblate 2.5
----------- -----------
......
...@@ -942,21 +942,28 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin): ...@@ -942,21 +942,28 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin):
def get_mask_matches(self): def get_mask_matches(self):
"""Returns files matching current mask.""" """Returns files matching current mask."""
prefix = os.path.join(self.get_path(), '') prefix = os.path.join(self.get_path(), '')
matches = set([ matches = set()
f.replace(prefix, '') for f in glob(os.path.join(self.get_path(), self.filemask)):
for f in glob(os.path.join(self.get_path(), self.filemask)) path = f.replace(prefix, '')
]) code = self.get_lang_code(path)
if re.match(self.language_regex, code):
matches.add(path)
else:
self.log_info('skipping language %s [%s]', code, path)
# We want to list template among translations as well # We want to list template among translations as well
if self.has_template(): if self.has_template():
if self.edit_template: if self.edit_template:
matches.add(self.template) matches.add(self.template)
else: else:
matches.discard(self.template) matches.discard(self.template)
# Remove symlinked translations # Remove symlinked translations
for filename in list(matches): for filename in list(matches):
resolved = self.repository.resolve_symlinks(filename) resolved = self.repository.resolve_symlinks(filename)
if resolved != filename and resolved in matches: if resolved != filename and resolved in matches:
matches.discard(filename) matches.discard(filename)
return sorted(matches) return sorted(matches)
def create_translations(self, force=False, langs=None, request=None, def create_translations(self, force=False, langs=None, request=None,
...@@ -965,16 +972,12 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin): ...@@ -965,16 +972,12 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin):
translations = set() translations = set()
languages = set() languages = set()
matches = self.get_mask_matches() matches = self.get_mask_matches()
language_re = re.compile(self.language_regex)
for pos, path in enumerate(matches): for pos, path in enumerate(matches):
with transaction.atomic(): with transaction.atomic():
code = self.get_lang_code(path) code = self.get_lang_code(path)
if langs is not None and code not in langs: if langs is not None and code not in langs:
self.log_info('skipping %s', path) self.log_info('skipping %s', path)
continue continue
if not language_re.match(code):
self.log_info('skipping language %s', code)
continue
self.log_info( self.log_info(
'checking %s (%s) [%d/%d]', 'checking %s (%s) [%d/%d]',
...@@ -1252,6 +1255,7 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin): ...@@ -1252,6 +1255,7 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin):
# Template validation # Template validation
self.clean_template() self.clean_template()
try:
matches = self.get_mask_matches() matches = self.get_mask_matches()
# Verify language codes # Verify language codes
...@@ -1259,6 +1263,11 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin): ...@@ -1259,6 +1263,11 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin):
# Try parsing files # Try parsing files
self.clean_files(matches) self.clean_files(matches)
except re.error:
raise ValidationError(_(
'Can not validate file matches due to invalid '
'regullar expression.'
))
# New language options # New language options
self.clean_new_lang() self.clean_new_lang()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment