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



Author: stephaner
Date: Sun Nov  2 12:11:44 2008
New Revision: 1123
URL: http://svn.gnome.org/viewvc/damned-lies?rev=1123&view=rev

Log:
2008-11-02  StÃphane Raimbault  <stephane raimbault gmail com>

	* stats/conf/settings_sample.py: Added setting to use an external
	MySQL database.		
	* stats/management/commands/migrate.py: Use the new settings. Fix
	return from migrate_stats when the old_statistics table doesn't
	exist.


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

Modified: branches/djamnedlies/stats/conf/settings_sample.py
==============================================================================
--- branches/djamnedlies/stats/conf/settings_sample.py	(original)
+++ branches/djamnedlies/stats/conf/settings_sample.py	Sun Nov  2 12:11:44 2008
@@ -16,3 +16,10 @@
 
 # Used for migration
 OLD_DAMNEDLIES = ""
+
+# Uncomment to migrate the old_statistics table from an external MySQL
+# database.
+# MYSQL_SETTINGS = dict(db='db',
+#                       user='user',
+#                       host='localhost',
+#                       passwd='pwd')

Modified: branches/djamnedlies/stats/management/commands/migrate.py
==============================================================================
--- branches/djamnedlies/stats/management/commands/migrate.py	(original)
+++ branches/djamnedlies/stats/management/commands/migrate.py	Sun Nov  2 12:11:44 2008
@@ -188,12 +188,22 @@
 
     def migrate_stats(self):
         """ This method migrate statistics if there is an old_statistics table (from previous DL)"""
-        from django.db import connection
-        cursor = connection.cursor()
+        import pdb; pdb.set_trace()
+        try:
+            mysql_settings = settings.MYSQL_SETTINGS
+            # Import just after dict access to avoid a useless import
+            import MySQLdb
+            conn = MySQLdb.connect(**mysql_settings)
+            cursor = conn.cursor()
+        except:
+            from django.db import connection
+            cursor = connection.cursor()
+            
         try:
             cursor.execute("SELECT module, branch, language, type, domain, date, translated, fuzzy, untranslated FROM old_statistics")
         except:
-            print "No statistics to migrate"
+            return "No statistics to migrate from old_statistics."
+
         MODULE, BRANCH, LANGUAGE, TYPE, DOMAIN, DATE, TRANSLATED, FUZZY, UNTRANSLATED = 0, 1, 2, 3, 4, 5, 6, 7, 8
         for stat in cursor.fetchall():
             # link to Branch, Domain and Language



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