Commit 19913bb2 authored by Weblate's avatar Weblate

Merge remote-tracking branch 'origin/master'

parents c4a58a1e 486582ec
...@@ -87,6 +87,12 @@ To customise the subproject's name, use the `--name-template` option. ...@@ -87,6 +87,12 @@ To customise the subproject's name, use the `--name-template` option.
Its parameter is a python formatting string, which will expect the Its parameter is a python formatting string, which will expect the
match from `<filemask>`. match from `<filemask>`.
By format string passed by the `--base-file-template` option you can customize
base file for monolingual translations.
You can also specify file format to use (see :ref:`formats`) by the
`--file-format` parameter. The default is autodetection.
For example: For example:
.. code-block:: bash .. code-block:: bash
......
...@@ -45,8 +45,27 @@ class Command(BaseCommand): ...@@ -45,8 +45,27 @@ class Command(BaseCommand):
help='Python formatting string, transforming the filemask ' help='Python formatting string, transforming the filemask '
'match to a project name' 'match to a project name'
), ),
make_option(
'--base-file-template',
default='%s',
help='Python formatting string, transforming the filemask '
'match to a monolingual base file name'
),
make_option(
'--file-format',
default='auto',
help='File format type, defaults to autodetection',
),
) )
def format_string(self, template, match):
'''
Formats template string with match.
'''
if '%s' in template:
return template % match
return template
def get_name(self, maskre, path): def get_name(self, maskre, path):
matches = maskre.match(path) matches = maskre.match(path)
return matches.group(1) return matches.group(1)
...@@ -148,12 +167,13 @@ class Command(BaseCommand): ...@@ -148,12 +167,13 @@ class Command(BaseCommand):
) )
else: else:
matches, sharedrepo = self.import_initial( matches, sharedrepo = self.import_initial(
project, repo, branch, filemask, options['name_template'] project, repo, branch, filemask, options['name_template'],
options['file_format'], options['base_file_template']
) )
# Create remaining subprojects sharing git repository # Create remaining subprojects sharing git repository
for match in matches: for match in matches:
name = options['name_template'] % match name = self.format_string(options['name_template'], match)
slug = slugify(name) slug = slugify(name)
subprojects = SubProject.objects.filter( subprojects = SubProject.objects.filter(
Q(name=name) | Q(slug=slug), Q(name=name) | Q(slug=slug),
...@@ -173,10 +193,13 @@ class Command(BaseCommand): ...@@ -173,10 +193,13 @@ class Command(BaseCommand):
project=project, project=project,
repo=sharedrepo, repo=sharedrepo,
branch=branch, branch=branch,
file_format=options['file_format'],
template=self.format_string(options['base_file_template'], match),
filemask=filemask.replace('**', match) filemask=filemask.replace('**', match)
) )
def import_initial(self, project, repo, branch, filemask, name_template): def import_initial(self, project, repo, branch, filemask, name_template,
file_format, base_file_template):
''' '''
Import the first repository of a project Import the first repository of a project
''' '''
...@@ -186,7 +209,7 @@ class Command(BaseCommand): ...@@ -186,7 +209,7 @@ class Command(BaseCommand):
# Create first subproject (this one will get full git repo) # Create first subproject (this one will get full git repo)
match = matches.pop() match = matches.pop()
name = name_template % match name = self.format_string(name_template, match)
slug = slugify(name) slug = slugify(name)
if SubProject.objects.filter(project=project, slug=slug).exists(): if SubProject.objects.filter(project=project, slug=slug).exists():
...@@ -212,6 +235,8 @@ class Command(BaseCommand): ...@@ -212,6 +235,8 @@ class Command(BaseCommand):
project=project, project=project,
repo=repo, repo=repo,
branch=branch, branch=branch,
file_format=file_format,
template=self.format_string(base_file_template, match),
filemask=filemask.replace('**', match) filemask=filemask.replace('**', match)
) )
......
...@@ -953,7 +953,7 @@ class Unit(models.Model): ...@@ -953,7 +953,7 @@ class Unit(models.Model):
for unit in Unit.objects.same(self).exclude(id=self.id): for unit in Unit.objects.same(self).exclude(id=self.id):
unit.update_has_failing_check(was_change) unit.update_has_failing_check(was_change)
def update_has_failing_check(self): def update_has_failing_check(self, was_change):
''' '''
Updates flag counting failing checks. Updates flag counting failing checks.
''' '''
......
...@@ -48,6 +48,47 @@ class ImportProjectTest(RepoTestCase): ...@@ -48,6 +48,47 @@ class ImportProjectTest(RepoTestCase):
# We should have loaded three subprojects # We should have loaded three subprojects
self.assertEqual(project.subproject_set.count(), 4) self.assertEqual(project.subproject_set.count(), 4)
def test_import_po(self):
project = self.create_project()
call_command(
'import_project',
'test',
self.repo_path,
'master',
'**/*.po',
file_format='po'
)
# We should have loaded three subprojects
self.assertEqual(project.subproject_set.count(), 4)
def test_import_aresource(self):
project = self.create_project()
call_command(
'import_project',
'test',
self.repo_path,
'master',
'**/values-*/strings.xml',
file_format='aresource',
base_file_template='android/values/strings.xml',
)
# We should have loaded one subproject
self.assertEqual(project.subproject_set.count(), 1)
def test_import_aresource_format(self):
project = self.create_project()
call_command(
'import_project',
'test',
self.repo_path,
'master',
'**/values-*/strings.xml',
file_format='aresource',
base_file_template='%s/values/strings.xml',
)
# We should have loaded one subproject
self.assertEqual(project.subproject_set.count(), 1)
def test_re_import(self): def test_re_import(self):
project = self.create_project() project = self.create_project()
call_command( call_command(
......
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