Browse Source

Changed the way to instanciate the MigrationHandler to fit with the DataSource

Yann Weber 8 years ago
parent
commit
6a55df202e
3 changed files with 12 additions and 4 deletions
  1. 9
    3
      DataSource/MySQL/migrationhandler.py
  2. 2
    0
      install/settings.py
  3. 1
    1
      install/utils.py

+ 9
- 3
DataSource/MySQL/migrationhandler.py View File

@@ -3,6 +3,8 @@
3 3
 import copy
4 4
 import pymysql
5 5
 
6
+from Lodel.settings import Settings
7
+
6 8
 import EditorialModel
7 9
 import EditorialModel.classtypes
8 10
 import EditorialModel.fieldtypes
@@ -44,11 +46,15 @@ class MysqlMigrationHandler(DummyMigrationHandler):
44 46
     # @param user str : The db user
45 47
     # @param password str : The db password
46 48
     # @param db str : The db name
47
-    def __init__(self, host, user, passwd, db, module=pymysql, db_engine='InnoDB', foreign_keys=True, debug=False, dryrun=False, drop_if_exists=False):
49
+    def __init__(self, module = pymysql, conn_args = None, db_engine='InnoDB', foreign_keys=True, debug=None, dryrun=False, drop_if_exists=False):
48 50
         self._dbmodule = module
51
+        if conn_args is None:
52
+            conn_args = copy.copy(Settings.get('datasource')['default'])
53
+            self._dbmodule = conn_args['module']
54
+            del conn_args['module']
55
+        self.db = self._dbmodule.connect(**conn_args)
49 56
         #Connect to MySQL
50
-        self.db = self._dbmodule.connect(host=host, user=user, passwd=passwd, db=db)
51
-        self.debug = debug
57
+        self.debug = Settings.get('debug') if debug is None else debug
52 58
         self.dryrun = dryrun
53 59
         self.db_engine = db_engine
54 60
         self.foreign_keys = foreign_keys if db_engine == 'InnoDB' else False

+ 2
- 0
install/settings.py View File

@@ -5,6 +5,8 @@ import pymysql
5 5
 name = 'LODEL2_INSTANCE_NAME'
6 6
 lodel2_lib_path = 'LODEL2_LIB_ABS_PATH'
7 7
 
8
+debug = False
9
+
8 10
 emfile = 'em.json'
9 11
 dynamic_code = 'dynleapi.py'
10 12
 

+ 1
- 1
install/utils.py View File

@@ -22,7 +22,7 @@ def refreshdyn():
22 22
 def db_init():
23 23
     from EditorialModel.backend.json_backend import EmBackendJson
24 24
     from EditorialModel.model import Model
25
-    mh = getattr(migrationhandler,settings.mh_classname)(**(settings.datasource['default']))
25
+    mh = getattr(migrationhandler,settings.mh_classname)()
26 26
     em = Model(EmBackendJson(settings.emfile))
27 27
     em.migrate_handler(mh)
28 28
 

Loading…
Cancel
Save