damned-lies r1070 - in branches/djamnedlies: . docs stats stats/conf stats/management/commands stats/templates



Author: claudep
Date: Wed Oct 22 07:08:45 2008
New Revision: 1070
URL: http://svn.gnome.org/viewvc/damned-lies?rev=1070&view=rev

Log:
2008-10-22  Claude Paroz  <claude 2xlibre net>

	* docs/DataModel.odg: Added vcs_subdir to branch table.
	* stats/conf/settings.py: Added DEBUG variable (referring to global DEBUG)
	* stats/management/commands/migrate.py: Populate vcs_subpath.
	* stats/management/commands/update-stats.py: Added script to update
	statistics.
	* stats/models.py: Added code to checkout branches and skeleton for
	updating stats (wip).
	* stats/templates/language-release-stats.tmpl: Fixed relative path for
	/data content.

Added:
   branches/djamnedlies/stats/management/commands/update-stats.py
Modified:
   branches/djamnedlies/ChangeLog
   branches/djamnedlies/docs/DataModel.odg
   branches/djamnedlies/stats/conf/settings.py
   branches/djamnedlies/stats/management/commands/migrate.py
   branches/djamnedlies/stats/models.py
   branches/djamnedlies/stats/templates/language-release-stats.tmpl

Modified: branches/djamnedlies/docs/DataModel.odg
==============================================================================
Binary files. No diff available.

Modified: branches/djamnedlies/stats/conf/settings.py
==============================================================================
--- branches/djamnedlies/stats/conf/settings.py	(original)
+++ branches/djamnedlies/stats/conf/settings.py	Wed Oct 22 07:08:45 2008
@@ -1,5 +1,6 @@
 from django.conf import settings
 
+DEBUG = getattr(settings, "DEBUG", True)
 WEBROOT = "/stats"
 POTDIR = "/home/claude/www/damned-lies/cvs/POT"
 SCRATCHDIR = "/home/claude/www/damned-lies/cvs/"

Modified: branches/djamnedlies/stats/management/commands/migrate.py
==============================================================================
--- branches/djamnedlies/stats/management/commands/migrate.py	(original)
+++ branches/djamnedlies/stats/management/commands/migrate.py	Wed Oct 22 07:08:45 2008
@@ -11,7 +11,7 @@
     help = "Migrate current D-L XML files into database content"
 
     output_transaction = False
-    xml_base = ""
+    xml_base = "/home/claude/www/damned-lies/po/C"
 
     def handle(self, app, **options):
         #drop table language;drop table module;drop table module_maintainer;drop table person;drop table release;drop table category;drop table team;drop table branch;
@@ -83,6 +83,8 @@
             # Adding branches
             for bkey, bval in module['branch'].items():
                 new_b = Branch(name=bkey, module=new_m)
+                if bval.has_key('subpath'):
+                    new_b.vcs_subpath = bval['subpath']
                 new_b.save()
                 # Adding domains (to module), if not exist
                 for dkey, dval in bval['domain'].items():

Added: branches/djamnedlies/stats/management/commands/update-stats.py
==============================================================================
--- (empty file)
+++ branches/djamnedlies/stats/management/commands/update-stats.py	Wed Oct 22 07:08:45 2008
@@ -0,0 +1,49 @@
+from django.core.management.base import BaseCommand
+from optparse import make_option
+import os
+from stats.models import Person, Team, Language, Module, Branch, Domain, Release, Category, Statistics
+
+class Command(BaseCommand):
+    help = "Update statistics about po file"
+    args = "[MODULE_ID [BRANCH]]"
+    
+    option_list = BaseCommand.option_list + (
+        make_option('--force', action='store_true', dest='force', default=False,
+            help="force statistics generation, even if files didn't change"),
+    )        
+
+    output_transaction = False
+
+    def handle(self, *args, **options):
+        if len(args)<=2:
+            if len(args)==2:
+                module_arg = args[0]
+                branch_arg = args[1]
+                if branch_arg == "trunk":
+                    branch_arg = "HEAD"
+                try:
+                    branch = Branch.objects.get(module__name=module_arg, name=branch_arg)
+                except:
+                    print "Unable to find branch '%s' for module '%s'" % (branch_arg, module_arg)
+                    return "Update unsuccessful"
+                print "Updating stats for %s.%s..." % (module_arg, branch_arg)
+                branch.update_stats(options['force'])
+            elif len(args)==1:
+                module_arg = args[0]
+                print "Updating stats for %s..." % (module_arg)
+                branches = Branch.objects.filter(module__name=module_arg)
+                for branch in branches.all():
+                    branch.update_stats(options['force'])
+            else:
+                modules = Module.objects.all()
+                for mod in modules:
+                    print "Updating stats for %s..." % (mod.name)
+                    branches = Branch.objects.filter(module__name=modu)
+                    for branch in branches.all():
+                        branch.update_stats(options['force'])
+        else:
+            return "Too much command line arguments"
+
+        return "Update completed."
+
+

Modified: branches/djamnedlies/stats/models.py
==============================================================================
--- branches/djamnedlies/stats/models.py	(original)
+++ branches/djamnedlies/stats/models.py	Wed Oct 22 07:08:45 2008
@@ -19,11 +19,11 @@
 # 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
 from django.db import models, connection
-from django.utils.translation import ungettext, ugettext as _
+from django.utils.translation import ungettext, ugettext as _, ugettext_noop as N_
 from stats.conf import settings
 from stats import utils
 from time import tzname
-import os, re, commands
+import os, sys, re, commands
 
 class Person(models.Model):
     old_id = models.CharField(max_length=50)
@@ -126,11 +126,15 @@
     """ Branch of a module """
     name = models.CharField(max_length=50)
     #description = models.TextField(null=True)
+    vcs_subpath = models.CharField(max_length=50, null=True)
     module = models.ForeignKey(Module)
     category = models.ForeignKey('Category', null=True)
     class Meta:
         db_table = 'branch'
     
+    def __unicode__(self):
+        return "Branch: %s" % self.name
+
     def is_head(self):
         if self.module.vcs_type in ('cvs', 'svn') and self.name == "HEAD":
             return True
@@ -139,7 +143,11 @@
         return False
     
     def get_vcsurl(self):
-        if self.is_head():
+        if self.module.vcs_type in ('hg', 'git'):
+            return "%s/%s" % (self.module.vcs_root, self.module_name)
+        elif self.vcs_subpath:
+            return "%s/%s/%s" % (self.module.vcs_root, self.module.name, self.vcs_subpath)
+        elif self.is_head():
             return "%s/%s/trunk" % (self.module.vcs_root, self.module.name)
         else:
             return "%s/%s/branches/%s" % (self.module.vcs_root, self.module.name, self.name)
@@ -176,7 +184,159 @@
         return self.get_stats('doc')
     def get_uistats(self):
         return self.get_stats('ui')
+    
+    def update_stats(self, force):
+        """ Update statistics for all po files from the branch """
+        self.checkout()
+        domains = Domain.objects.filter(module=self.module)
+        for dom in domains.all():
+            domain_path = os.path.join(self.co_path(), dom.directory)
+            if not os.access(domain_path, os.X_OK):
+                # TODO: should check if existing stats, and delete (archive) them in this case
+                continue
+            errors = []
+            if dom.dtype == 'ui':
+                # Run intltool-update -m to check for some errors
+                errors.extend(self.check_pot_regeneration(domain_path))
+            # TODO: update pot file and update DB
+            # TODO: update po files and update DB
+            #stats = Statistics.objects.filter(branch = self)
+            #for stat in stats.all():
+            #    stat.update()
+    
+    def checkout(self):
+        """ Do a checkout or an update of the VCS files """
+        module_name = self.module.name
+        vcs_type = self.module.vcs_type
+        localroot = os.path.join(settings.SCRATCHDIR, vcs_type)
+        moduledir = self.module.name + "." + self.name
+        modulepath = os.path.join(localroot, moduledir)
+        scmroot = self.module.vcs_root
+
+        try: os.makedirs(localroot)
+        except: pass
+        
+        commandList = []
+        if os.access(modulepath, os.X_OK | os.W_OK):
+            # Path exists, update repos
+            if vcs_type == "cvs":
+                commandList.append("cd \"%(localdir)s\" && cvs -z4 up -Pd" % {
+                    "localdir" : modulepath,
+                    })
+            elif vcs_type == "svn":
+                commandList.append("cd \"%(localdir)s\" && svn up --non-interactive" % {
+                    "localdir" : modulepath,
+                    })
+            elif vcs_type == "hg":
+                commandList.append("cd \"%(localdir)s\" && hg revert --all" % {
+                    "localdir" : modulepath,
+                    })
+            elif vcs_type == "git":
+                commandList.append("cd \"%(localdir)s\" && git checkout %(branch)s && git reset --hard && git clean -df" % {
+                    "localdir" : modulepath,
+                    "branch" : self.name,
+                    })
+            elif vcs_type == "bzr":
+                commandList.append("cd \"%(localdir)s\" && bzr up" % {
+                    "localdir" : modulepath,
+                    })
+        else:
+            # Checkout
+            vcs_path = self.get_vcsurl()
+            if vcs_type == "cvs":
+                commandList.append("cd \"%(localroot)s\" && cvs -d%(cvsroot)s -z4 co -d%(dir)s -r%(branch)s %(module)s" % {
+                "localroot" : localroot,
+                "cvsroot" : scmroot,
+                "dir" : moduledir,
+                "branch" : self.name,
+                "module" : module_name,
+                })
+            elif vcs_type == "svn":
+                commandList.append("cd \"%(localroot)s\" && svn co --non-interactive %(svnpath)s \"%(dir)s\"" % {
+                    "localroot" : localroot,
+                    "svnpath" : vcs_path,
+                    "dir" : moduledir,
+                    })
+            elif vcs_type == "hg":
+                commandList.append("cd \"%(localroot)s\" && hg clone %(hgpath)s \"%(dir)s\"" % {
+                    "localroot" : localroot,
+                    "hgpath" : vcs_path,
+                    "dir" : moduledir,
+                    })
+                commandList.append("cd \"%(localdir)s\" && hg update %(branch)s" % {
+                    "localdir" : modulepath,
+                    "branch" : self.name,
+                    })
+            elif vcs_type == "git":
+                commandList.append("cd \"%(localroot)s\" && git clone %(gitpath)s \"%(dir)s\"" % {
+                    "localroot" : localroot,
+                    "gitpath" : vcs_path,
+                    "dir" : moduledir,
+                    })
+                commandList.append("cd \"%(localdir)s\" && git checkout %(branch)s" % {
+                    "localdir" : modulepath,
+                    "branch" : self.name,
+                    })
+            elif vcs_type == "bzr":
+                commandList.append("cd \"%(localroot)s\" && bzr co --lightweight %(bzrpath)s \"%(dir)s\"" % {
+                    "localroot" : localroot,
+                    "bzrpath" : vcs_path,
+                    "dir" : moduledir,
+                    })
+        
+        # Run command(s)
+        errorsOccured = 0
+        if settings.DEBUG:
+            print >>sys.stdout, "Checking '%s.%s' out to '%s'..." % (module_name, self.name, modulepath)
+        for command in commandList:
+            if settings.DEBUG:
+                print >>sys.stdout, command
+            (error, output) = commands.getstatusoutput(command)
+            if settings.DEBUG:
+                print >> sys.stderr, output
+            if error:
+                errorsOccured = 1
+                if settings.DEBUG:
+                    print >> sys.stderr, error
+        if errorsOccured:
+            print >> sys.stderr, "Problem checking out module %s.%s" % (module_name, self.name)
+            return 0
+        else:
+            return 1
+
+    def check_pot_regeneration(self, po_path):
+        """Check if there were any problems regenerating a POT file (intltool-update -m)."""
+        errors = []
+
+        command = "cd \"%(dir)s\" && rm -f missing notexist && intltool-update -m" % { "dir" : po_path, }
+        if settings.DEBUG: print >>sys.stderr, command
+        (error, output) = commands.getstatusoutput(command)
+        if settings.DEBUG: print >> sys.stderr, output
+
+        if error:
+            if settings.DEBUG: print >> sys.stderr, "Error running 'intltool-update -m' check."
+            errors.append( ("error", N_("Errors while running 'intltool-update -m' check.")) )
+
+        missing = os.path.join(po_path, "missing")
+        if os.access(missing, os.R_OK):
+            f = open(missing, "r")
+            errors.append( ("warn",
+                            N_("There are some missing files from POTFILES.in: %s")
+                            % ("<ul><li>"
+                            + "</li>\n<li>".join(f.readlines())
+                            + "</li>\n</ul>")) )
+
+        notexist = os.path.join(po_path, "notexist")
+        if os.access(notexist, os.R_OK):
+            f = open(notexist, "r")
+            errors.append(("error",
+                           N_("Following files are referenced in either POTFILES.in or POTFILES.skip, yet they don't exist: %s")
+                           % ("<ul><li>"
+                           + "</li>\n<li>".join(f.readlines())
+                           + "</li>\n</ul>")))
+        return errors
 
+        
 class Domain(models.Model):
     module = models.ForeignKey(Module)
     name = models.CharField(max_length=50)
@@ -551,7 +711,12 @@
             if not error or e.Type == 'error' or (e.Type == 'warn' and error.Type == 'info'):
                 error = e
         return error
-
+    
+    def update(self):
+        """ Update stats in database """
+        # TODO
+        print("Updating %s/%s (%s-%s)" % (self.branch.module.name, self.branch.name, self.language.name, self.domain.name))
+        
 class FakeStatistics(object):
     """ This is a fake statistics class where a summary value is needed for a multi-domain module
         This is used in get_lang_stats for the language-release-stats template """

Modified: branches/djamnedlies/stats/templates/language-release-stats.tmpl
==============================================================================
--- branches/djamnedlies/stats/templates/language-release-stats.tmpl	(original)
+++ branches/djamnedlies/stats/templates/language-release-stats.tmpl	Wed Oct 22 07:08:45 2008
@@ -37,13 +37,13 @@
           {% if dom.1.partial_po %}
             {# This is a partial po, indented, with the domain description #}
             <td class="leftcell" style="padding-left:2em; padding-right:2em;">
-            <a href="{{ dom.1.po_url }}"><img src="/data/download.png" alt="{% trans "Download po file" %}"></a>
+            <a href="{{ dom.1.po_url }}"><img src="{{ webroot }}/data/download.png" alt="{% trans "Download po file" %}"></a>
             {{ dom.1.domain.description }}
             </td>
           {% else %}
             <td class="leftcell">
             {% if not dom.1.is_fake %}
-              <a href="{{ dom.1.po_url }}"><img src="/data/download.png" alt="{% trans "Download po file" %}"></a>
+              <a href="{{ dom.1.po_url }}"><img src="{{ webroot }}/data/download.png" alt="{% trans "Download po file" %}"></a>
               <a href="{% url stats.views.module modname %}">
             {% else %}
               <a href="{% url stats.views.module modname %}" style="font-style: italic;">



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