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



Author: claudep
Date: Wed Oct 22 18:52:15 2008
New Revision: 1072
URL: http://svn.gnome.org/viewvc/damned-lies?rev=1072&view=rev

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

	* stats/management/commands/migrate.py: Allow to migrate with a fresh
	damned-lies checkout (xml.in files).

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

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 18:52:15 2008
@@ -1,17 +1,18 @@
 from django.core.management.base import BaseCommand
 import os
-import data
-from djamnedlies.stats.models import Person, Team, Language, Module, Branch, Domain, Release, Category, Statistics
+
+from stats.models import Person, Team, Language, Module, Branch, Domain, Release, Category, Statistics
 
 class Command(BaseCommand):
-    """ Before the migration:
-        1. cp or link the legacy D-L data.py file in this directory
-        2. set the xml_base directory where you can find the original .xml files to migrate their content """
+    """ Before the migration, set the xml_base directory to a legacy Damned Lies checkout """
     
     help = "Migrate current D-L XML files into database content"
 
     output_transaction = False
-    xml_base = "/home/claude/www/damned-lies/po/C"
+    xml_base = "/home/claude/Bureau/TraductionsGNOME/damned-lies/trunk"
+    import sys
+    sys.path.append (xml_base)
+    import data
 
     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;
@@ -21,11 +22,12 @@
         print self.migrateModules()
         print self.migrateReleases()
         print self.migrateStats()
-       
+        
+        # Network_manager domains may need renaming (vpn-daemons/openvpn/po -> po-openvpn, ...)
         return "Migration completed."
 
     def migratePeople(self):
-        people = data.readFromFile(os.path.join(self.xml_base, "people.xml"))
+        people = self.data.readFromFile(os.path.join(self.xml_base, "people.xml.in"))
         for key, p in people.items():
             if not p.has_key('bugzilla-account'):
                 p['bugzilla-account'] = None
@@ -41,37 +43,39 @@
         return "People migrated successfully"
 
     def migrateTeams(self):
-        teams = data.readFromFile(os.path.join(self.xml_base, "translation-teams.xml"))
+        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:
-                team['description'] = team['language'].items()[0][1]['content']
+            if len(team['_language'].items()) <= 1:
+                team['_description'] = team['_language'].items()[0][1]['content']
             coord = Person.objects.get(old_id=team['coordinator'].keys()[0])
             if not team.has_key('mailing-list'):
                 team['mailing-list'] = None
             if not team.has_key('mailing-list-subscribe'):
                 team['mailing-list-subscribe'] = None
-            if not team.has_key('description'):
-                team['description'] = 'Catalan'
+            if not team.has_key('_description'):
+                team['_description'] = 'Catalan'
                 print "Forced Catalan description"
-            new_t = Team(lang_code=key, description=team['description'], coordinator=coord,
+            new_t = Team(lang_code=key, description=team['_description'], coordinator=coord,
                          webpage_url=team['webpage'],
                          mailing_list=team['mailing-list'],
                          mailing_list_subscribe=team['mailing-list-subscribe'])
             new_t.save()
-            for lkey, lang in team['language'].items():
+            for lkey, lang in team['_language'].items():
                 new_l = Language(name=lang['content'], 
                                  locale=lang['id'], team=new_t)
                 new_l.save()
         return "Teams migrated successfully"
 
     def migrateModules(self):
-        modules = data.readFromFile(os.path.join(self.xml_base, "gnome-modules.xml"))
+        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']:
+            for prop in ['webpage', '_comment']:
                 if not module.has_key(prop):
                     module[prop] = None
-            new_m = Module(name=module['id'], description=module['description'], 
-                           homepage=module['webpage'], comment=module['comment'],
+            if not module.has_key('_description'):
+                module['_description'] = module['id']
+            new_m = Module(name=module['id'], description=module['_description'], 
+                           homepage=module['webpage'], comment=module['_comment'],
                            bugs_base=module['bugs-baseurl'], bugs_product=module['bugs-product'], bugs_component=module['bugs-component'],
                            vcs_type=module['scmroot']['type'], vcs_root=module['scmroot']['path'], vcs_web=module['scmweb'])
             new_m.save()
@@ -91,12 +95,12 @@
                     if dval.has_key('directory'):
                         ddir = dval['directory']
                     else:
-                        ddir = 'po'
+                        ddir = dval['id']
                     existing_d = Domain.objects.filter(module=new_m, dtype='ui', directory=ddir)
                     if len(existing_d) < 1:
-                        if not dval.has_key('description'):
-                            dval['description'] = None
-                        new_domain = Domain(module=new_m, name=dkey, description=dval['description'], dtype='ui', directory=ddir)
+                        if not dval.has_key('_description'):
+                            dval['_description'] = None
+                        new_domain = Domain(module=new_m, name=dkey, description=dval['_description'], dtype='ui', directory=ddir)
                         new_domain.save()
                     #else:
                 for dkey, dval in bval['document'].items():
@@ -106,24 +110,24 @@
                         ddir = 'help'
                     existing_d = Domain.objects.filter(module=new_m, dtype='doc', directory=ddir)
                     if len(existing_d) < 1:
-                        if not dval.has_key('description'):
-                            dval['description'] = None
-                        new_domain = Domain(module=new_m, name=dkey, description=dval['description'], dtype='doc', directory=ddir)
+                        if not dval.has_key('_description'):
+                            dval['_description'] = None
+                        new_domain = Domain(module=new_m, name=dkey, description=dval['_description'], dtype='doc', directory=ddir)
                         new_domain.save()
                     
         return "Modules migrated successfully"
 
     def migrateReleases(self):
-        releases = data.readFromFile(os.path.join(self.xml_base, "releases.xml"))
+        releases = self.data.readFromFile(os.path.join(self.xml_base, "releases.xml.in"))
         for key, release in releases.items():
             try:
-                new_r = Release.objects.get(name=release['description'])
+                new_r = Release.objects.get(name=release['_description'])
             except:
-                new_r = Release(name=release['description'], stringfrozen=False, status=release['status'])
+                new_r = Release(name=release['_description'], stringfrozen=False, status=release['status'])
                 new_r.save()
             if release.has_key('category'):
                 for catname, catcontent in release['category'].items():
-                    relcat = Category(release=new_r, description=catcontent['description'])
+                    relcat = Category(release=new_r, description=catcontent['_description'])
                     relcat.save()
                     for mod, content in catcontent['module'].items():
                         # find the right component
@@ -144,7 +148,11 @@
                 relcat = Category(release=new_r, description='default')
                 relcat.save()
                 for mod, content in release['module'].items():
-                    module = Module.objects.get(name=mod)
+                    try:
+                        module = Module.objects.get(name=mod)
+                    except:
+                        print "Unable to find module '%s'" % mod
+                        continue
                     if content.has_key('branch'):
                         branch_name = content['branch']
                     else:



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