浏览代码

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

Yann Weber 9 年前
父节点
当前提交
6a55df202e
共有 3 个文件被更改,包括 12 次插入4 次删除
  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 查看文件

3
 import copy
3
 import copy
4
 import pymysql
4
 import pymysql
5
 
5
 
6
+from Lodel.settings import Settings
7
+
6
 import EditorialModel
8
 import EditorialModel
7
 import EditorialModel.classtypes
9
 import EditorialModel.classtypes
8
 import EditorialModel.fieldtypes
10
 import EditorialModel.fieldtypes
44
     # @param user str : The db user
46
     # @param user str : The db user
45
     # @param password str : The db password
47
     # @param password str : The db password
46
     # @param db str : The db name
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
         self._dbmodule = module
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
         #Connect to MySQL
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
         self.dryrun = dryrun
58
         self.dryrun = dryrun
53
         self.db_engine = db_engine
59
         self.db_engine = db_engine
54
         self.foreign_keys = foreign_keys if db_engine == 'InnoDB' else False
60
         self.foreign_keys = foreign_keys if db_engine == 'InnoDB' else False

+ 2
- 0
install/settings.py 查看文件

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

+ 1
- 1
install/utils.py 查看文件

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

正在加载...
取消
保存