Commit 6ef69dc9 authored by Michal Čihař's avatar Michal Čihař

Merge remote-tracking branch 'origin/master'

parents 6ea8c4a2 a585cb14
......@@ -18,6 +18,12 @@ All settings are stored in :file:`settings.py` (as usual for Django).
Path where Weblate will store cloned Git repositories. Defaults to
:file:`repos` subdirectory.
.. envvar:: LAZY_COMMITS
Delay creating Git commits until this is necessary. This heavily reduces
number of commits generated by Weblate at expense of temporarily not being
able to merge some changes as they are not yet committed.
.. envvar:: MT_APERTIUM_KEY
API key for Apertium Web Service, you can register at http://api.apertium.org/register.jsp
......
......@@ -258,5 +258,8 @@ NEARBY_MESSAGES = 5
# Minimal number of similar messages to show
SIMILAR_MESSAGES = 5
# Enable lazy commits
LAZY_COMMITS = True
# Where to put Whoosh index
WHOOSH_INDEX = os.path.join(WEB_ROOT, 'whoosh-index')
......@@ -17,8 +17,7 @@ class SubProjectAdmin(admin.ModelAdmin):
def update_from_git(self, request, queryset):
for s in queryset:
s.update_branch()
s.create_translations()
s.do_update()
self.message_user(request, "Updated %d git repos." % queryset.count())
def update_checks(self, request, queryset):
......
......@@ -16,17 +16,14 @@ class Command(BaseCommand):
def handle(self, *args, **options):
if options['all']:
for s in SubProject.objects.all():
s.update_branch()
s.create_translations()
s.do_update()
for arg in args:
parts = arg.split('/')
if len(parts) == 2:
prj, subprj = parts
s = SubProject.objects.get(slug = subprj, project__slug = prj)
s.update_branch()
s.create_translations()
s.do_update()
else:
for s in SubProject.objects.filter(project__slug = parts[0]):
s.update_branch()
s.create_translations()
s.do_update()
......@@ -151,6 +151,21 @@ class SubProject(models.Model):
gitrepo.git.checkout(self.branch)
del gitrepo
def do_update(self):
'''
Wrapper for doing repository update and pushing them to translations.
'''
self.check_commit_needed()
self.update_branch()
self.create_translations()
def check_commit_needed(self):
'''
Checks whether there is any translation which needs commit.
'''
for translation in self.translation_set.all():
translation.check_commit_needed(None)
def update_branch(self):
'''
Updates current branch to match remote (if possible).
......@@ -209,6 +224,7 @@ class SubProject(models.Model):
def save(self, *args, **kwargs):
self.configure_repo()
self.configure_branch()
self.check_commit_needed()
self.update_branch()
super(SubProject, self).save(*args, **kwargs)
......@@ -357,11 +373,24 @@ class Translation(models.Model):
self.revision = blob_hash
self.save()
def get_author_name(self, request):
full_name = request.user.get_full_name()
def get_last_author(self):
try:
change = self.change_set.order_by('-timestamp')[0]
return self.get_author_name(change.user)
except:
return None
def check_commit_needed(self, author):
last = self.get_last_author()
if author == last or last is None:
return
self.git_commit(last, True)
def get_author_name(self, user):
full_name = user.get_full_name()
if full_name == '':
full_name = request.user.username
return '%s <%s>' % (full_name, request.user.email)
full_name = user.username
return '%s <%s>' % (full_name, user.email)
def __git_commit(self, gitrepo, author):
'''
......@@ -373,7 +402,7 @@ class Translation(models.Model):
m = settings.COMMIT_MESSAGE
)
def git_commit(self, author):
def git_commit(self, author, force_commit = False):
'''
Wrapper for commiting translation to git.
'''
......@@ -382,6 +411,9 @@ class Translation(models.Model):
if status == '':
# No changes to commit
return False
if not force_commit and settings.LAZY_COMMITS:
logger.info('Delaying commiting %s as %s', self.filename, author)
return False
logger.info('Commiting %s as %s', self.filename, author)
try:
self.__git_commit(gitrepo, author)
......@@ -416,7 +448,8 @@ class Translation(models.Model):
# We should have only one match
break
if need_save:
author = self.get_author_name(request)
author = self.get_author_name(request.user)
self.check_commit_needed(author)
if hasattr(store, 'updateheader'):
po_revision_date = datetime.now().strftime('%Y-%m-%d %H:%M') + poheader.tzstring()
......@@ -480,8 +513,9 @@ class Translation(models.Model):
if not overwrite and unit1.istranslated():
continue
unit1.merge(unit2, overwrite=True, comments=False)
self.check_commit_needed(author)
store1.save()
ret = self.git_commit(author)
ret = self.git_commit(author, True)
self.check_sync()
return ret
......@@ -493,7 +527,7 @@ class Translation(models.Model):
fileobj.mode = "r"
store2 = factory.getobject(fileobj)
if author is None:
author = self.get_author_name(request)
author = self.get_author_name(request.user)
ret = False
......
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