damned-lies r1433 - in trunk: . stats



Author: claudep
Date: Wed Feb  4 17:19:11 2009
New Revision: 1433
URL: http://svn.gnome.org/viewvc/damned-lies?rev=1433&view=rev

Log:
2009-02-04  Claude Paroz  <claude 2xlibre net>

	* stats/potdiff.py: potdiff returns two result sets in all cases, so as it
	has not to be called twice.
	* stats/utils.py: Added a pot diff function.
	* stats/models.py: Uses utils.pot_diff_status and act upon the result
	code.
	The pot_has_changed signal is now sent even for formatting changes, so as
	the diff view get rid of code line numbers stuff.

Modified:
   trunk/ChangeLog
   trunk/stats/models.py
   trunk/stats/potdiff.py
   trunk/stats/utils.py

Modified: trunk/stats/models.py
==============================================================================
--- trunk/stats/models.py	(original)
+++ trunk/stats/models.py	Wed Feb  4 17:19:11 2009
@@ -297,20 +297,15 @@
                     # Not sure if we should do something here
                     continue
 
-            pot_has_changed = True
+            changed_status = utils.CHANGED_WITH_ADDITIONS
 
-            # If old pot already exists and we are in string freeze
             if os.access(previous_pot, os.R_OK):
-                if string_frozen and dom.dtype == 'ui':
-                    diff = potdiff.diff(previous_pot, potfile, 1)
-                    if len(diff):
-                        utils.notify_list("%s.%s" % (self.module.name, self.name), diff)
-
-                # If old pot already exists, lets see if it has changed at all
-                diff = potdiff.diff(previous_pot, potfile)
-                if not len(diff):
-                    pot_has_changed = False
-                else:
+                # Compare old and new POT
+                changed_status, diff = utils.pot_diff_status(previous_pot, potfile)
+                if string_frozen and dom.dtype == 'ui' and changed_status == utils.CHANGED_WITH_ADDITIONS:
+                    utils.notify_list("%s.%s" % (self.module.name, self.name), diff)
+                
+                if changed_status != utils.NOT_CHANGED:
                     signals.pot_has_changed.send(sender=self, potfile=potfile, branch=self, domain=dom)
             
             # 5. Generate pot stats and update DB
@@ -341,8 +336,8 @@
             for lang, pofile in self.get_lang_files(dom, domain_path):
                 outpo = os.path.join(self.output_dir(dom.dtype), dom.potbase() + "." + self.name + "." + lang + ".po")
 
-                if not force and not pot_has_changed and os.access(outpo, os.R_OK) and os.stat(pofile)[8] < os.stat(outpo)[8] \
-                   and not lang in langs_with_linguas_errors :
+                if not force and changed_status in (utils.NOT_CHANGED, utils.CHANGED_ONLY_FORMATTING) and os.access(outpo, os.R_OK) \
+                   and os.stat(pofile)[8] < os.stat(outpo)[8] and not lang in langs_with_linguas_errors :
                     continue
 
                 realcmd = command % {

Modified: trunk/stats/potdiff.py
==============================================================================
--- trunk/stats/potdiff.py	(original)
+++ trunk/stats/potdiff.py	Wed Feb  4 17:19:11 2009
@@ -23,7 +23,7 @@
 
 USE_DIFFLIB = 0
 
-def diff(pota, potb, only_additions = 0):
+def diff(pota, potb):
     """Returns a list of differing lines between two files."""
     f1 = open(pota, "r")
     data1 = f1.read()
@@ -39,19 +39,19 @@
         # since we are working with sorted data, we can speed up the process by doing compares ourselves
         # instead of using difflib stuff
         i, j = 0, 0
-        result = []
+        result_add_only = []
+        result_all = []
         while i < len(res1) and j < len(res2):
             if res1[i] == res2[j]:
                 i+=1; j+=1
             elif res1[i] < res2[j]:
-                if not only_additions:
-                    result.append("- " + res1[i])
+                result_all.append("- " + res1[i])
                 i+=1
             elif res1[i] > res2[j]:
-                result.append("+ " + res2[j])
+                result_all.append("+ " + res2[j])
+                result_add_only.append("+ " + res2[j])
                 j+=1
-        #print "\n".join(result)
-        return result
+        return result_all, result_add_only
     else:
         import difflib
         d = difflib.Differ()

Modified: trunk/stats/utils.py
==============================================================================
--- trunk/stats/utils.py	(original)
+++ trunk/stats/utils.py	Wed Feb  4 17:19:11 2009
@@ -29,8 +29,15 @@
 from django.core.files.base import File
 from django.conf import settings
 
+import potdiff
+
 STATUS_OK = 0
 
+NOT_CHANGED = 0
+CHANGED_ONLY_FORMATTING = 1
+CHANGED_WITH_ADDITIONS  = 2
+CHANGED_NO_ADDITIONS    = 3
+
 def sort_object_list(lst, sort_meth):
     """ Sort an object list with sort_meth (which should return a translated string) """
     templist = [(getattr(obj_, sort_meth)().lower(), obj_) for obj_ in lst]
@@ -167,6 +174,19 @@
             fullline = ""
     return ""
 
+def pot_diff_status(pota, potb):
+    (status, output, errs) = run_shell_command("diff %s %s|wc -l" % (pota, potb))
+    # POT generation date always change and produce a 4 line diff
+    if int(output) <= 4:
+        return NOT_CHANGED, ""
+    
+    result_all, result_add_only = potdiff.diff(pota, potb)
+    if not len(result_all) and not len(result_add_only):
+        return CHANGED_ONLY_FORMATTING, ""
+    elif len(result_add_only):
+        return CHANGED_WITH_ADDITIONS, result_add_only
+    else:
+        return CHANGED_NO_ADDITIONS, result_all
 
 def po_file_stats(pofile, msgfmt_checks = True):
     """ Compute pofile translation statistics, and proceed to some validity checks if msgfmt_checks is True """



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