Browse Source

More fixes due to Datasource changes

Yann Weber 9 years ago
parent
commit
b41b7f2bd7

+ 19
- 8
DataSource/MySQL/migrationhandler.py View File

@@ -41,27 +41,38 @@ import DataSource.dummy
41 41
 
42 42
 
43 43
 ## @brief Modify a MySQL database given editorial model changes
44
-class MigrationHandler(DataSource.dummy.MigrationHandler):
44
+class MigrationHandler(DataSource.dummy.migrationhandler.MigrationHandler):
45 45
 
46 46
     ## @brief Construct a MysqlMigrationHandler
47 47
     # @param module : sql module
48 48
     # @param conn_args dict : A dict containing connection options
49 49
     # @param db_engine str : Name of a MySQL db engine (default is InnoDB, don't change it ! ;) ) 
50 50
     # @param **kwargs : arguement given to the module.connect() method
51
-    def __init__(self, module=pymysql, conn_args=None, db_engine='InnoDB', **kwargs):
51
+    def __init__(self, module=pymysql, conn_args=None, db_engine='InnoDB'):
52 52
         # Database connection
53 53
         self._dbmodule = module
54 54
         if conn_args is None:
55
-            conn_args = copy.copy(Settings.get('datasource')['default'])
55
+            conn_args = copy.copy(Settings.datasource_options['default'])
56 56
             self._dbmodule = conn_args['module']
57 57
             del conn_args['module']
58 58
         self.db_conn = self._dbmodule.connect(**conn_args)
59 59
         # Fetch options
60
-        mh_settings = Settings.migration_options
61
-        self.debug = kwargs['debug'] if 'debug' in kwargs else Settings.debug_sql
62
-        self.dryrun = kwargs['dryrun'] if 'dryrun' in kwargs else mh_settings['dryrun']
63
-        self.foreign_keys = kwargs['foreign_keys'] if 'foreign_keys' in kwargs else mh_settings['foreign_keys']
64
-        self.drop_if_exists = kwargs['drop_if_exists'] if 'drop_if_exists' in kwargs else mh_settings['drop_if_exists']
60
+        mh_settings = Settings.migrationhandler_options
61
+
62
+        defaults = {
63
+            'debug': False,
64
+            'dryrun': False,
65
+            'foreign_keys': True,
66
+            'drop_if_exists': False
67
+        }
68
+
69
+        for opt_name in defaults:
70
+            if opt_name in mh_settings:
71
+                opt_val = mh_settings[opt_name]
72
+            else:
73
+                opt_val = defaults[opt_name]
74
+            setattr(self, opt_name, opt_val)
75
+
65 76
         self.db_engine = db_engine
66 77
         #Create default tables
67 78
         self._create_default_tables(self.drop_if_exists)

+ 3
- 3
EditorialModel/model.py View File

@@ -4,7 +4,7 @@
4 4
 # Contains the class managing and editorial model
5 5
 
6 6
 import EditorialModel
7
-from DataSource.dummy.migrationhandler import MigrationHandler
7
+import DataSource.dummy.migrationhandler
8 8
 from EditorialModel.backend.dummy_backend import EmBackendDummy
9 9
 from EditorialModel.classes import EmClass
10 10
 from EditorialModel.fields import EmField
@@ -24,8 +24,8 @@ class Model(object):
24 24
     # @param migration_handler : A migration handler
25 25
     def __init__(self, backend, migration_handler=None):
26 26
         if migration_handler is None:
27
-            self.migration_handler = MigrationHandler()
28
-        elif issubclass(migration_handler.__class__, MigrationHandler):
27
+            self.migration_handler = DataSource.dummy.migrationhandler.MigrationHandler()
28
+        elif issubclass(migration_handler.__class__, DataSource.dummy.migrationhandler.MigrationHandler):
29 29
             self.migration_handler = migration_handler
30 30
         else:
31 31
             raise TypeError("migration_handler should be an instance from a subclass of DummyMigrationhandler")

+ 1
- 1
Lodel/settings_format.py View File

@@ -11,7 +11,7 @@ MANDATORY = [
11 11
     'dynamic_code_file',
12 12
     'ds_package',
13 13
     'datasource_options',
14
-    'migration_options',
14
+    'migrationhandler_options',
15 15
     'base_path',
16 16
     'plugins',
17 17
     'logging',

+ 6
- 2
install/instance_settings.py View File

@@ -14,8 +14,7 @@ em_file = 'em.json'
14 14
 dynamic_code_file = 'dynleapi.py'
15 15
 
16 16
 ds_package = 'MySQL'
17
-mh_classname = 'MysqlMigrationHandler'
18
-datasource = {
17
+datasource_options = {
19 18
     'default': {
20 19
         'module': pymysql,
21 20
         'host': '127.0.0.1',
@@ -24,3 +23,8 @@ datasource = {
24 23
         'db': 'DBNAME'
25 24
     }
26 25
 }
26
+
27
+""" # example
28
+ds_package = 'jsondiff'
29
+datasource_options = { 'json_file': 'output.json' }
30
+"""

+ 3
- 0
install/loader.py View File

@@ -19,6 +19,7 @@ from plugins import * #Load activated plugins
19 19
 if os.path.isfile(Settings.dynamic_code_file):
20 20
     from dynleapi import *
21 21
 
22
+""" # useless ?
22 23
 # Import wanted datasource objects
23 24
 for db_modname in ['leapidatasource', 'migrationhandler']:
24 25
     mod = importlib.import_module("DataSource.{pkg_name}.{mod_name}".format(
@@ -28,6 +29,8 @@ for db_modname in ['leapidatasource', 'migrationhandler']:
28 29
     )
29 30
     # Expose the module in globals
30 31
     globals()[db_modname] = mod
32
+"""
33
+
31 34
 
32 35
 if __name__ == '__main__':
33 36
     import code

+ 3
- 3
install/utils.py View File

@@ -9,7 +9,6 @@ def refreshdyn():
9 9
     from EditorialModel.model import Model
10 10
     from leapi.lefactory import LeFactory
11 11
     from EditorialModel.backend.json_backend import EmBackendJson
12
-    from DataSource.MySQL.leapidatasource import LeDataSourceSQL
13 12
     OUTPUT = Settings.dynamic_code_file
14 13
     EMJSON = Settings.em_file
15 14
     # Load editorial model
@@ -17,13 +16,14 @@ def refreshdyn():
17 16
     # Generate dynamic code
18 17
     fact = LeFactory(OUTPUT)
19 18
     # Create the python file
20
-    fact.create_pyfile(em, LeDataSourceSQL, {})
19
+    fact.create_pyfile(em)
21 20
 
22 21
 
23 22
 def db_init():
24 23
     from EditorialModel.backend.json_backend import EmBackendJson
25 24
     from EditorialModel.model import Model
26
-    mh = getattr(migrationhandler,Settings.mh_classname)()
25
+    import DataSource.utils
26
+    mh = DataSource.utils.get_migrationhandler_instance()
27 27
     em = Model(EmBackendJson(Settings.em_file))
28 28
     em.migrate_handler(mh)
29 29
 

+ 6
- 4
settings.py View File

@@ -14,8 +14,10 @@ plugins = ['dummy', 'dummy_auth']
14 14
 
15 15
 ds_package = 'dummy'
16 16
 datasource_options = {}
17
-""" #example
18
-datasource = {
17
+migrationhandler_options = {}
18
+""" # MySQL example
19
+ds_package = 'MySQL'
20
+datasource_options = {
19 21
     'default': {
20 22
         'module':pymysql,
21 23
         'host': None,
@@ -24,13 +26,13 @@ datasource = {
24 26
         'db': None,
25 27
     }
26 28
 }
27
-"""
28 29
 
29
-migration_options = {
30
+migrationhandler_options = {
30 31
     'dryrun': False,
31 32
     'foreign_keys': True,
32 33
     'drop_if_exists': False,
33 34
 }
35
+"""
34 36
 
35 37
 em_graph_format = 'png'
36 38
 em_graph_output = '/tmp/em_%s_graph.png'

Loading…
Cancel
Save