damned-lies r1413 - in trunk: . docs stats vertimus vertimus/tests



Author: claudep
Date: Fri Jan 30 22:27:41 2009
New Revision: 1413
URL: http://svn.gnome.org/viewvc/damned-lies?rev=1413&view=rev

Log:
2009-01-30  Claude Paroz  <claude 2xlibre net>

	* docs/notes-upgrade.txt: Add new field and migration script.
	* stats/utils.py: Compute number of figures in po(t) files.
	* stats/models.py: Store number of figures in database. This prevents
	constant filesystem accesses (msgcat|grep) while displaying module stats.
	Now filesystem access is only required when displaying doc images in
	module_images template.

Modified:
   trunk/ChangeLog
   trunk/docs/notes-upgrade.txt
   trunk/stats/models.py
   trunk/stats/utils.py
   trunk/vertimus/tests/__init__.py
   trunk/vertimus/views.py

Modified: trunk/docs/notes-upgrade.txt
==============================================================================
--- trunk/docs/notes-upgrade.txt	(original)
+++ trunk/docs/notes-upgrade.txt	Fri Jan 30 22:27:41 2009
@@ -34,3 +34,21 @@
 ALTER TABLE team DROP group_ptr_id;
 ALTER TABLE team MODIFY `id` int(11) NOT NULL auto_increment;
 ALTER TABLE team ADD primary key(`id`);
+
+# r1412
+ALTER TABLE statistics ADD num_figures int(11) NOT NULL DEFAULT 0;
+# migration script to populate num_figures for POT files
+import os
+from stats.utils import run_shell_command
+from stats.models import Statistics
+
+stats = Statistics.objects.filter(language=None, domain__dtype='doc')
+for stat in stats:
+    pofile = stat.po_path(potfile=True)
+    if os.access(pofile, os.R_OK):
+        command = "grep '^msgid \"@@image:' \"%s\" | wc -l" % pofile
+        (status, output, errs) = run_shell_command(command)
+        num = int(output)
+        if num > 0:
+            stat.num_figures = num
+            stat.save()

Modified: trunk/stats/models.py
==============================================================================
--- trunk/stats/models.py	(original)
+++ trunk/stats/models.py	Fri Jan 30 22:27:41 2009
@@ -323,6 +323,7 @@
             try:
                 stat = Statistics.objects.get(language=None, branch=self, domain=dom)
                 stat.untranslated = int(pot_stats['untranslated'])
+                stat.num_figures = int(pot_stats['num_figures'])
                 stat.date = datetime.now()
                 Information.objects.filter(statistics=stat).delete()
             except Statistics.DoesNotExist:
@@ -373,6 +374,7 @@
                     stat.translated = int(langstats['translated'])
                     stat.fuzzy = int(langstats['fuzzy'])
                     stat.untranslated = int(langstats['untranslated'])
+                    stat.num_figures = int(langstats['num_figures'])
                     stat.date = datetime.now()
                     Information.objects.filter(statistics=stat).delete()
                 except Statistics.DoesNotExist:
@@ -964,6 +966,8 @@
     translated = models.IntegerField(default=0)
     fuzzy = models.IntegerField(default=0)
     untranslated = models.IntegerField(default=0)
+    # Number of figures in doc templates
+    num_figures = models.IntegerField(default=0)
 
     class Meta:
         db_table = 'statistics'
@@ -1065,7 +1069,7 @@
     
     def fig_count(self):
         """ If stat of a document type, get the number of figures in the document """
-        return len(self.get_figures() or [])
+        return self.num_figures
     
     def fig_stats(self):
         stats = {'fuzzy':0, 'translated':0, 'total':0, 'prc':0}
@@ -1087,12 +1091,12 @@
         """ Return the Web interface path of file on remote vcs """
         return utils.url_join(self.branch.get_vcs_web_url(), self.domain.directory)
         
-    def po_path(self):
+    def po_path(self, potfile=False):
         """ Return path of po file on local filesystem """
         subdir = ""
         if self.domain.dtype == "doc":
             subdir = "docs"
-        return os.path.join(settings.POTDIR, self.module_name()+'.'+self.branch.name, subdir, self.filename())
+        return os.path.join(settings.POTDIR, self.module_name()+'.'+self.branch.name, subdir, self.filename(potfile))
         
     def po_url(self, potfile=False):
         """ Return URL of po file, e.g. for downloading the file """

Modified: trunk/stats/utils.py
==============================================================================
--- trunk/stats/utils.py	(original)
+++ trunk/stats/utils.py	Fri Jan 30 22:27:41 2009
@@ -174,6 +174,7 @@
         'translated' : 0,
         'fuzzy' : 0,
         'untranslated' : 0,
+        'num_figures' : 0,
         'errors' : [],
         }
     c_env = {"LC_ALL": "C", "LANG": "C", "LANGUAGE": "C"}
@@ -236,6 +237,10 @@
         if status != STATUS_OK:
             res['errors'].append(("warn",
                               ugettext_noop("PO file '%s' is not UTF-8 encoded.") % (filename)))
+    # Count number of figures in PO(T) file
+    command = "grep '^msgid \"@@image:' \"%s\" | wc -l" % pofile
+    (status, output, errs) = run_shell_command(command)
+    res['num_figures'] = int(output)
 
     return res
 

Modified: trunk/vertimus/tests/__init__.py
==============================================================================
--- trunk/vertimus/tests/__init__.py	(original)
+++ trunk/vertimus/tests/__init__.py	Fri Jan 30 22:27:41 2009
@@ -394,6 +394,16 @@
         self.assertEqual(state.name, 'None')
         
         action = ActionAbstract.new_by_name('RT')
+        state = state.apply_action(action, self.pt, "Reserved!")
+        state.save()
+
+        action = ActionAbstract.new_by_name('UNDO')
+        state = state.apply_action(action, self.pt, "Ooops! I don't want to do that. Sorry.")
+        state.save()
+
+        self.assertEqual(state.name, 'None')
+
+        action = ActionAbstract.new_by_name('RT')
         state = state.apply_action(action, self.pt, "Translating")
         state.save()
         

Modified: trunk/vertimus/views.py
==============================================================================
--- trunk/vertimus/views.py	(original)
+++ trunk/vertimus/views.py	Fri Jan 30 22:27:41 2009
@@ -28,7 +28,7 @@
 
 from people.models import Person
 from stats.models import Statistics, Module, Branch, Domain, Language
-from vertimus.models import StateDb, ActionDb, ActionAbstract
+from vertimus.models import StateDb, ActionDb, ActionAbstract, ActionBA, StateToCommit, StateCommitted
 from vertimus.forms import ActionForm
 
 def vertimus_by_stats_id(request, stats_id, lang_id):
@@ -87,6 +87,15 @@
                 action = ActionAbstract.new_by_name(action)
                 new_state = state.apply_action(action, person, comment, request.FILES.get('file', None))
                 new_state.save()
+                if isinstance(new_state, StateToCommit):
+                    try:
+                        action_with_po = action._action_db.get_previous_action_with_po()
+                        branch.commit_po(action_with_po.file.path, domain, language)
+                        action = ActionIC()
+                        new_state = new_state.apply_action(action, person)
+                        new_state.save()
+                    except:
+                        pass # The file cannot be autocommitted
 
                 return HttpResponseRedirect(
                     urlresolvers.reverse('vertimus-names-view', 
@@ -146,7 +155,7 @@
     content2 = [l.decode('utf-8') for l in open(file_path2, 'U').readlines()]
     d = difflib.HtmlDiff()
     diff_content = d.make_table(content2, content1,
-                                descr2, descr1, context=True)
+                                descr2, descr1, context=False)
 
     context = {
         'diff_content': diff_content,



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