damned-lies r1099 - in branches/djamnedlies: . stats/management/commands



Author: stephaner
Date: Sun Oct 26 02:07:22 2008
New Revision: 1099
URL: http://svn.gnome.org/viewvc/damned-lies?rev=1099&view=rev

Log:
2008-10-26  StÃphane Raimbault  <stephane raimbault gmail com>

	* stats/management/commands/migrate.py: SVN is our memory :)
	* stats/management/commands/update-stats.py: Minor changes.


Modified:
   branches/djamnedlies/ChangeLog
   branches/djamnedlies/stats/management/commands/migrate.py
   branches/djamnedlies/stats/management/commands/update-stats.py

Modified: branches/djamnedlies/stats/management/commands/migrate.py
==============================================================================
--- branches/djamnedlies/stats/management/commands/migrate.py	(original)
+++ branches/djamnedlies/stats/management/commands/migrate.py	Sun Oct 26 02:07:22 2008
@@ -1,7 +1,7 @@
 import os
 import sys
 from django.core.management.base import BaseCommand
-from stats.models import Person, Team, Language, Module, Branch, Domain, Release, Category, Statistics
+from stats.models import Person, Team, Language, Module, Branch, Domain, Release, Category
 from stats.conf import settings
 
 class Command(BaseCommand):
@@ -16,16 +16,15 @@
 
     def handle(self, **options):
                 
-        print self.migratePeople()
-        print self.migrateTeams()
-        print self.migrateModules()
-        print self.migrateReleases()
-        #print self.migrateStats()
+        print self.migrate_people()
+        print self.migrate_teams()
+        print self.migrate_modules()
+        print self.migrate_releases()
         
         # Network_manager domains may need renaming (vpn-daemons/openvpn/po -> po-openvpn, ...)
         return "Migration completed."
 
-    def migratePeople(self):
+    def migrate_people(self):
         people = self.data.readFromFile(os.path.join(self.xml_base, "people.xml.in"))
         for key, p in people.items():
 
@@ -60,7 +59,7 @@
             new_p.save()
         return "People migrated successfully"
 
-    def migrateTeams(self):
+    def migrate_teams(self):
         teams = self.data.readFromFile(os.path.join(self.xml_base, "translation-teams.xml.in"))
         for key, team in teams.items():
             if len(team['_language'].items()) <= 1:
@@ -84,7 +83,7 @@
                 new_l.save()
         return "Teams migrated successfully"
 
-    def migrateModules(self):
+    def migrate_modules(self):
         modules = self.data.readFromFile(os.path.join(self.xml_base, "gnome-modules.xml.in"))
         for key, module in modules.items():
             for prop in ['webpage', '_comment']:
@@ -141,7 +140,7 @@
                     
         return "Modules migrated successfully"
 
-    def migrateReleases(self):
+    def migrate_releases(self):
         releases = self.data.readFromFile(os.path.join(self.xml_base, "releases.xml.in"))
         for key, release in releases.items():
             try:
@@ -190,38 +189,3 @@
                             br.category = relcat
                             br.save()
         return "Releases migrated successfully"
-
-    def migrateStats(self):
-        stats = Statistics.objects.all()
-        for stat in stats:
-            # link to Branch, Domain and Language
-            try:
-                mod = Module.objects.get(name=stat.Module)
-            except:
-                print "Unable to find module corresponding to '%s'." % stat.Module
-                continue
-            try:
-                br = Branch.objects.get(name=stat.Branch, module=mod.id)
-            except:
-                print "Unable to find branch corresponding to '%s.%s'." % (stat.Module, stat.Branch)
-                continue
-            if stat.Language is not None:
-                try:
-                    lang = Language.objects.get(locale=stat.Language)
-                except:
-                    lang = Language(name=stat.Language, 
-                                 locale=stat.Language)
-                    lang.save()
-                    print "Unable to find language corresponding to '%s'. Language created." % (stat.Language)
-            else:
-                # The POT file
-                lang = None
-            stat.branch = br
-            stat.language = lang
-            for p in mod.domain_set.all():
-                if p.dtype == stat.Type and p.name == stat.Domain:
-                    stat.domain = p
-                    break
-            #import pdb; pdb.set_trace()
-            stat.save()
-        return "Statistics migrated successfully"

Modified: branches/djamnedlies/stats/management/commands/update-stats.py
==============================================================================
--- branches/djamnedlies/stats/management/commands/update-stats.py	(original)
+++ branches/djamnedlies/stats/management/commands/update-stats.py	Sun Oct 26 02:07:22 2008
@@ -1,7 +1,7 @@
-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
+from optparse import make_option
+from django.core.management.base import BaseCommand
+from stats.models import Module, Branch
 
 class Command(BaseCommand):
     help = "Update statistics about po file"
@@ -15,8 +15,8 @@
     output_transaction = False
 
     def handle(self, *args, **options):
-        if len(args)<=2:
-            if len(args)==2:
+        if len(args) <= 2:
+            if len(args) == 2:
                 module_arg = args[0]
                 branch_arg = args[1]
                 if branch_arg == "trunk":
@@ -24,11 +24,11 @@
                 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 "Unable to find branch '%s' for module '%s' in the database." % (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:
+            elif len(args) == 1:
                 module_arg = args[0]
                 print "Updating stats for %s..." % (module_arg)
                 branches = Branch.objects.filter(module__name=module_arg)
@@ -42,7 +42,7 @@
                     for branch in branches.all():
                         branch.update_stats(options['force'])
         else:
-            return "Too much command line arguments"
+            return "Too much command line arguments."
 
         return "Update completed."
 



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