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
 
41
 
42
 
42
 
43
 ## @brief Modify a MySQL database given editorial model changes
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
     ## @brief Construct a MysqlMigrationHandler
46
     ## @brief Construct a MysqlMigrationHandler
47
     # @param module : sql module
47
     # @param module : sql module
48
     # @param conn_args dict : A dict containing connection options
48
     # @param conn_args dict : A dict containing connection options
49
     # @param db_engine str : Name of a MySQL db engine (default is InnoDB, don't change it ! ;) ) 
49
     # @param db_engine str : Name of a MySQL db engine (default is InnoDB, don't change it ! ;) ) 
50
     # @param **kwargs : arguement given to the module.connect() method
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
         # Database connection
52
         # Database connection
53
         self._dbmodule = module
53
         self._dbmodule = module
54
         if conn_args is None:
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
             self._dbmodule = conn_args['module']
56
             self._dbmodule = conn_args['module']
57
             del conn_args['module']
57
             del conn_args['module']
58
         self.db_conn = self._dbmodule.connect(**conn_args)
58
         self.db_conn = self._dbmodule.connect(**conn_args)
59
         # Fetch options
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
         self.db_engine = db_engine
76
         self.db_engine = db_engine
66
         #Create default tables
77
         #Create default tables
67
         self._create_default_tables(self.drop_if_exists)
78
         self._create_default_tables(self.drop_if_exists)

+ 3
- 3
EditorialModel/model.py View File

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

+ 1
- 1
Lodel/settings_format.py View File

11
     'dynamic_code_file',
11
     'dynamic_code_file',
12
     'ds_package',
12
     'ds_package',
13
     'datasource_options',
13
     'datasource_options',
14
-    'migration_options',
14
+    'migrationhandler_options',
15
     'base_path',
15
     'base_path',
16
     'plugins',
16
     'plugins',
17
     'logging',
17
     'logging',

+ 6
- 2
install/instance_settings.py View File

14
 dynamic_code_file = 'dynleapi.py'
14
 dynamic_code_file = 'dynleapi.py'
15
 
15
 
16
 ds_package = 'MySQL'
16
 ds_package = 'MySQL'
17
-mh_classname = 'MysqlMigrationHandler'
18
-datasource = {
17
+datasource_options = {
19
     'default': {
18
     'default': {
20
         'module': pymysql,
19
         'module': pymysql,
21
         'host': '127.0.0.1',
20
         'host': '127.0.0.1',
24
         'db': 'DBNAME'
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
 if os.path.isfile(Settings.dynamic_code_file):
19
 if os.path.isfile(Settings.dynamic_code_file):
20
     from dynleapi import *
20
     from dynleapi import *
21
 
21
 
22
+""" # useless ?
22
 # Import wanted datasource objects
23
 # Import wanted datasource objects
23
 for db_modname in ['leapidatasource', 'migrationhandler']:
24
 for db_modname in ['leapidatasource', 'migrationhandler']:
24
     mod = importlib.import_module("DataSource.{pkg_name}.{mod_name}".format(
25
     mod = importlib.import_module("DataSource.{pkg_name}.{mod_name}".format(
28
     )
29
     )
29
     # Expose the module in globals
30
     # Expose the module in globals
30
     globals()[db_modname] = mod
31
     globals()[db_modname] = mod
32
+"""
33
+
31
 
34
 
32
 if __name__ == '__main__':
35
 if __name__ == '__main__':
33
     import code
36
     import code

+ 3
- 3
install/utils.py View File

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

+ 6
- 4
settings.py View File

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

Loading…
Cancel
Save