Commit 3d890e8c authored by Weblate's avatar Weblate

Merge remote-tracking branch 'origin/master'

parents 52218c2d ff489030
...@@ -735,6 +735,32 @@ class SubProject(models.Model): ...@@ -735,6 +735,32 @@ class SubProject(models.Model):
self.update_remote_branch() self.update_remote_branch()
self.update_branch() self.update_branch()
def clean_repo_link(self):
'''
Validates repository link.
'''
if self.push != '':
raise ValidationError(
_('Push URL is not used when repository is linked!')
)
validate_repo(self.repo)
def clean_template(self):
'''
Validates whether template can be loaded.
'''
try:
self.load_template_store()
except ValueError:
raise ValidationError(
_('Format of translation template could not be recognized.')
)
except Exception as e:
raise ValidationError(
_('Failed to parse translation template.')
)
def clean(self): def clean(self):
''' '''
Validator fetches repository and tries to find translation files. Validator fetches repository and tries to find translation files.
...@@ -748,62 +774,49 @@ class SubProject(models.Model): ...@@ -748,62 +774,49 @@ class SubProject(models.Model):
self.sync_git_repo(True) self.sync_git_repo(True)
# Push repo is not used with link # Push repo is not used with link
if self.is_repo_link() and self.push != '': if self.is_repo_link():
raise ValidationError( self.clean_repo_link()
_('Push URL is not used when repository is linked!')
) matches = self.get_mask_matches()
if len(matches) == 0:
try: raise ValidationError(_('The mask did not match any files!'))
matches = self.get_mask_matches() langs = set()
if len(matches) == 0: for match in matches:
raise ValidationError(_('The mask did not match any files!')) code = self.get_lang_code(match)
langs = {} if code in langs:
for match in matches: raise ValidationError(_(
code = self.get_lang_code(match) 'There are more files for single language, please '
if code in langs: 'adjust the mask and use subprojects for translating '
raise ValidationError(_( 'different resources.'
'There are more files for single language, please '
'adjust the mask and use subprojects for translating '
'different resources.'
))
langs[code] = match
# Try parsing files
notrecognized = []
errors = []
for match in matches:
try:
self.file_format_cls.load(
os.path.join(self.get_path(), match),
)
except ValueError:
notrecognized.append(match)
except Exception as e:
errors.append('%s: %s' % (match, str(e)))
if len(notrecognized) > 0:
raise ValidationError('%s\n%s' % (
(_('Format of %d matched files could not be recognized.') % len(notrecognized)),
'\n'.join(notrecognized)
))
if len(errors) > 0:
raise ValidationError('%s\n%s' % (
(_('Failed to parse %d matched files!') % len(errors)),
'\n'.join(errors)
)) ))
langs.add(code)
# Validate template # Try parsing files
if self.has_template(): notrecognized = []
try: errors = []
self.load_template_store() for match in matches:
except ValueError: try:
raise ValidationError(_('Format of translation template could not be recognized.')) self.file_format_cls.load(
except Exception as e: os.path.join(self.get_path(), match),
raise ValidationError( )
_('Failed to parse translation template.') except ValueError:
) notrecognized.append(match)
except SubProject.DoesNotExist: except Exception as e:
# Happens with invalid link errors.append('%s: %s' % (match, str(e)))
pass if len(notrecognized) > 0:
raise ValidationError('%s\n%s' % (
(_('Format of %d matched files could not be recognized.') % len(notrecognized)),
'\n'.join(notrecognized)
))
if len(errors) > 0:
raise ValidationError('%s\n%s' % (
(_('Failed to parse %d matched files!') % len(errors)),
'\n'.join(errors)
))
# Validate template
if self.has_template():
self.clean_template()
def get_template_filename(self): def get_template_filename(self):
''' '''
......
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