[damned-lies] Fixed stats update after commit of a new language



commit 46efdb698fe8f89bcac2cfb6a29cbc8047d59141
Author: Claude Paroz <claude 2xlibre net>
Date:   Sat Feb 8 12:11:28 2014 +0100

    Fixed stats update after commit of a new language
    
    Fixes bug #723852.

 stats/models.py      |   16 +++++++++++-----
 stats/tests/tests.py |   36 +++++++++++++++++++++++++-----------
 2 files changed, 36 insertions(+), 16 deletions(-)
---
diff --git a/stats/models.py b/stats/models.py
index 96817a7..cb701f1 100644
--- a/stats/models.py
+++ b/stats/models.py
@@ -1,6 +1,6 @@
 # -*- coding: utf-8 -*-
 #
-# Copyright (c) 2008-2013 Claude Paroz <claude 2xlibre net>.
+# Copyright (c) 2008-2014 Claude Paroz <claude 2xlibre net>.
 # Copyright (c) 2008 Stephane Raimbault <stephane raimbault gmail com>.
 #
 # This file is part of Damned Lies.
@@ -391,12 +391,15 @@ class Branch(models.Model):
             self._ui_stats = self.get_stats('ui', mandatory_langs)
         return self._ui_stats
 
-    def update_stats(self, force, checkout=True):
+    def update_stats(self, force, checkout=True, domain=None):
         """ Update statistics for all po files from the branch """
         with ModuleLock(self.module):
             if checkout:
                 self.checkout()
-            domains = Domain.objects.filter(module=self.module).all()
+            if domain is None:
+                domains = Domain.objects.filter(module=self.module).all()
+            else:
+                domains = [domain]
             string_frozen = self.has_string_frozen()
             for dom in domains:
                 # 1. Initial settings
@@ -722,8 +725,11 @@ class Branch(models.Model):
                         "cd \"%(dest)s\" && git reset --hard origin/%(branch)s" % var_dict)
                     raise
         # Finish by updating stats
-        stat = Statistics.objects.get(language=language, branch=self, domain=domain)
-        stat.update_stats(dest_path)
+        if already_exist:
+            stat = Statistics.objects.get(language=language, branch=self, domain=domain)
+            stat.update_stats(dest_path)
+        else:
+            self.update_stats(force=False, checkout=False, domain=domain)
 
 
 DOMAIN_TYPE_CHOICES = (
diff --git a/stats/tests/tests.py b/stats/tests/tests.py
index 16f5054..a4a6a3b 100644
--- a/stats/tests/tests.py
+++ b/stats/tests/tests.py
@@ -1,6 +1,6 @@
 # -*- coding: utf-8 -*-
 #
-# Copyright (c) 2008-2012 Claude Paroz <claude 2xlibre net>
+# Copyright (c) 2008-2014 Claude Paroz <claude 2xlibre net>
 #
 # This file is part of Damned Lies.
 #
@@ -235,25 +235,39 @@ class ModuleTestCase(TestCase):
         branch = self.mod.get_head_branch()
         po_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'test.po')
         domain = self.mod.domain_set.get(name='po')
-        lang = Language.objects.get(locale='fr')
+        fr_lang = Language.objects.get(locale='fr')
         with self.assertRaisesRegexp(Exception, 'read-only mode'):
-            branch.commit_po(po_file, domain, lang, 'Author <someone example org>')
+            branch.commit_po(po_file, domain, fr_lang, 'Author <someone example org>')
         self.mod.vcs_root = self.mod.vcs_root.replace('git://', 'ssh://')
         self.mod.save()
+
+        # User interface (existing language)
+        git_ops = ('git checkout master', 'git pull', 'git add fr.po',
+                   'git commit -m "Updated French translation" --author "Author <someone example org>"',
+                   'git push origin master')
+        with patch_shell_command() as cmds:
+            branch.commit_po(po_file, domain, fr_lang, 'Author <someone example org>')
+            for idx, cmd in enumerate(git_ops):
+                self.assertIn(cmd, cmds[idx])
+
+        # User interface (new language)
+        bem_lang = Language.objects.get(locale='bem')
+        git_ops = ('git checkout master', 'git pull', 'git add bem.po', 'git add LINGUAS',
+                   'git commit -m "Added Bemba translation" --author "Author <someone example org>"',
+                   'git push origin master')
         with patch_shell_command() as cmds:
-            branch.commit_po(po_file, domain, lang, 'Author <someone example org>')
-            git_ops = ('git checkout master', 'git pull', 'git add fr.po',
-                       'git commit -m "Updated French translation" --author "Author <someone example org>"',
-                       'git push origin master')
+            branch.commit_po(po_file, domain, bem_lang, 'Author <someone example org>')
             for idx, cmd in enumerate(git_ops):
                 self.assertIn(cmd, cmds[idx])
+            self.assertIn('intltool-update -g', cmds[-1])
 
+        # Documentation
         domain = self.mod.domain_set.get(name='help')
+        git_ops = ('git checkout master', 'git pull', 'git add fr/fr.po',
+                   'git commit -m "Updated French translation" --author "Author <someone example org>"',
+                   'git push origin master')
         with patch_shell_command() as cmds:
-            branch.commit_po(po_file, domain, lang, 'Author <someone example org>')
-            git_ops = ('git checkout master', 'git pull', 'git add fr/fr.po',
-                       'git commit -m "Updated French translation" --author "Author <someone example org>"',
-                       'git push origin master')
+            branch.commit_po(po_file, domain, fr_lang, 'Author <someone example org>')
             for idx, cmd in enumerate(git_ops):
                 self.assertIn(cmd, cmds[idx])
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]