Browse Source

Databases: get rid of old and unused code

ArnAud 9 years ago
parent
commit
6890375041

+ 0
- 1
Database/__init__.py View File

@@ -1 +0,0 @@
1
-# -*- coding: utf-8 -*- #

+ 0
- 132
Database/sqlalter.py View File

@@ -1,132 +0,0 @@
1
-# -*- coding: utf-8 -*-
2
-
3
-import os
4
-import time
5
-
6
-import sqlalchemy as sqla
7
-from sqlalchemy.ext.compiler import compiles
8
-
9
-## @file sqlalter.py
10
-# This file defines all DDL (data definition langage) for the ALTER TABLE instructions
11
-#
12
-# It uses the SqlAlchemy compilation and quoting methos to generate SQL
13
-
14
-
15
-class AddColumn(sqla.schema.DDLElement):
16
-    """ Defines the ddl for adding a column to a table """
17
-    def __init__(self, table, column):
18
-        """ Instanciate the DDL
19
-            @param table sqlalchemy.Table: A sqlalchemy table object
20
-            @param column sqlalchemy.Column: A sqlalchemy column object
21
-        """
22
-        self.col = column
23
-        self.table = table
24
-
25
-
26
-@compiles(AddColumn, 'mysql')
27
-@compiles(AddColumn, 'postgresql')
28
-@compiles(AddColumn, 'sqlite')
29
-def visit_add_column(element, ddlcompiler, **kw):
30
-    """ Compiles the AddColumn DDL for mysql, postgresql and sqlite"""
31
-    prep = ddlcompiler.sql_compiler.preparer
32
-    tname = prep.format_table(element.table)
33
-    colname = prep.format_column(element.col)
34
-    return 'ALTER TABLE %s ADD COLUMN %s %s' % (tname, colname, element.col.type)
35
-
36
-
37
-@compiles(AddColumn)
38
-def visit_add_column(element, ddlcompiler, **kw):
39
-    raise NotImplementedError('Add column not yet implemented for ' + str(ddlcompiler.dialect.name))
40
-
41
-
42
-class DropColumn(sqla.schema.DDLElement):
43
-    """ Defines the DDL for droping a column from a table """
44
-    def __init__(self, table, column):
45
-        """ Instanciate the DDL
46
-            @param table sqlalchemy.Table: A sqlalchemy table object
47
-            @param column sqlalchemy.Column: A sqlalchemy column object representing the column to drop
48
-        """
49
-        self.col = column
50
-        self.table = table
51
-
52
-
53
-@compiles(DropColumn, 'mysql')
54
-@compiles(DropColumn, 'postgresql')
55
-def visit_drop_column(element, ddlcompiler, **kw):
56
-    """ Compiles the DropColumn DDL for mysql & postgresql """
57
-    prep = ddlcompiler.sql_compiler.preparer
58
-    tname = prep.format_table(element.table)
59
-    colname = prep.format_column(element.col)
60
-    return 'ALTER TABLE %s DROP COLUMN %s' % (tname, colname)
61
-
62
-
63
-@compiles(DropColumn)
64
-##
65
-# @warning Returns more than one query @ref Database.sqlutils.ddl_execute
66
-def visit_drop_column(element, ddlcompiler, **kw):
67
-    prep = ddlcompiler.sql_compiler.preparer
68
-    tname = prep.format_table(element.table)
69
-
70
-    #Temporary table
71
-    tmpname = str(element.table) + '_copydropcol'
72
-    tmpTable = sqla.Table(tmpname, sqla.MetaData())
73
-    tmptname = prep.format_table(tmpTable)
74
-
75
-    query = 'ALTER TABLE %s RENAME TO %s; ' % (tname, tmptname)
76
-
77
-    colname = prep.format_column(element.col)
78
-
79
-    meta = sqla.MetaData()
80
-    newtable = sqla.Table(element.table, meta)
81
-    clist = element.table.columns
82
-
83
-    cols = []
84
-    for col in clist:
85
-        if col.name != element.col.name:
86
-            newtable.append_column(col.copy())
87
-            cols.append(prep.format_column(col))
88
-    cols = ', '.join(cols)
89
-
90
-    query += str(sqla.schema.CreateTable(newtable).compile(dialect=ddlcompiler.dialect)) + ';'
91
-
92
-    query += 'INSERT INTO %s ( %s ) SELECT %s FROM %s;' % (newtable, cols, cols, tmptname)
93
-
94
-    query += 'DROP TABLE %s' % (tmpname)
95
-
96
-    return query
97
-
98
-
99
-    #raise NotImplementedError('Drop column not yet implemented for '+str(ddlcompiler.dialect.name))
100
-
101
-class AlterColumn(sqla.schema.DDLElement):
102
-    """ Defines the DDL for changing the type of a column """
103
-    def __init__(self, table, column):
104
-        """ Instanciate the DDL
105
-            @param table sqlalchemy.Table: A sqlalchemy Table object
106
-            @param column sqlalchemy.Column: A sqlalchemy Column object representing the new column
107
-        """
108
-        self.col = column
109
-        self.table = table
110
-
111
-
112
-@compiles(AlterColumn, 'mysql')
113
-def visit_alter_column(element, ddlcompiler, **kw):
114
-    """ Compiles the AlterColumn DDL for mysql """
115
-    prep = ddlcompiler.sql_compiler.preparer
116
-    tname = prep.format_table(element.table)
117
-    colname = prep.format_column(element.col)
118
-    return 'ALTER TABLE %s ALTER COLUMN %s %s' % (tname, colname, element.col.type)
119
-
120
-
121
-@compiles(AlterColumn, 'postgresql')
122
-def visit_alter_column(element, ddlcompiler, **kw):
123
-    """ Compiles the AlterColumn DDL for postgresql """
124
-    prep = ddlcompiler.sql_compiler.preparer
125
-    tname = prep.format_table(element.table)
126
-    colname = prep.format_column(element.col)
127
-    return 'ALTER TABLE %s ALTER COLUMN %s TYPE %s' % (tname, colname, element.col.type)
128
-
129
-
130
-@compiles(AlterColumn)
131
-def visit_alter_column(element, ddlcompiler, **kw):
132
-    raise NotImplementedError('Alter column not yet implemented for ' + str(ddlcompiler.dialect.name))

+ 0
- 39
Database/sqlsettings.py View File

@@ -1,39 +0,0 @@
1
-# -*- coding: utf-8 -*-
2
-
3
-class SQLSettings(object):
4
-    
5
-    DEFAULT_HOSTNAME = 'localhost'
6
-        
7
-    dbms_list = {
8
-        'postgresql': {
9
-            'driver': 'psycopg2',
10
-            'encoding': 'utf8',
11
-        },
12
-        'mysql': {
13
-            'driver': 'pymysql',
14
-            'encoding': 'utf8',
15
-        },
16
-        'sqlite': {
17
-            'driver': 'pysqlite',
18
-            'encoding': 'utf8',
19
-        },
20
-    }
21
-
22
-    DB_READ_CONNECTION_NAME = 'default'
23
-    DB_WRITE_CONNECTION_NAME = 'default'
24
-    
25
-    querystrings = {
26
-        'add_column': {
27
-            'default': 'ALTER TABLE %s ADD COLUMN %s %s'
28
-        },
29
-        'alter_column': {
30
-            'postgresql': 'ALTER TABLE %s ALTER COLUMN %s TYPE %s',
31
-            'mysql': 'ALTER TABLE %s ALTER COLUMN %s %s'
32
-        },
33
-        'drop_column': {
34
-            'default': 'ALTER TABLE %s DROP COLUMN %s'
35
-        }
36
-    }
37
-    
38
-    ACTION_TYPE_WRITE = 'write'
39
-    ACTION_TYPE_READ = 'read'

+ 0
- 194
Database/sqlsetup.py View File

@@ -1,194 +0,0 @@
1
-# -*- coding: utf-8 -*-
2
-
3
-import sqlalchemy as sql
4
-import re  # Converting string to sqlalchemy types
5
-from Database import sqlutils
6
-
7
-
8
-def init_db(dbconfname='default', alchemy_logs=None, schema=None):
9
-
10
-    dbe = sqlutils.get_engine(dbconfname, alchemy_logs)
11
-    meta = sqlutils.meta(dbe)
12
-    meta.reflect()
13
-    meta.drop_all(dbe)
14
-    # refresh meta (maybe useless)
15
-    meta = sqlutils.meta(dbe)
16
-    meta.reflect()
17
-
18
-    if schema is None:
19
-        schema = get_schema()
20
-
21
-    for table in schema:
22
-        topt = table.copy()
23
-        del topt['columns']
24
-        name = topt['name']
25
-        del topt['name']
26
-        cur_table = sql.Table(name, meta, **topt)
27
-        for col in table['columns']:
28
-            cur_col = create_column(**col)
29
-            cur_table.append_column(cur_col)
30
-
31
-    meta.create_all(bind=dbe)
32
-
33
-
34
-def get_schema():
35
-    tables = []
36
-
37
-    default_columns = [
38
-        {"name": "uid", "type": "INTEGER", "extra": {"foreignkey": "uids.uid", "nullable": False, "primarykey": True}},
39
-        {"name": "name", "type": "VARCHAR(50)", "extra": {"nullable": False, "unique": True}},
40
-        {"name": "string", "type": "TEXT"},
41
-        {"name": "help", "type": "TEXT"},
42
-        {"name": "rank", "type": "INTEGER"},
43
-        {"name": "date_create", "type": "DATETIME"},
44
-        {"name": "date_update", "type": "DATETIME"},
45
-    ]
46
-
47
-    # Table listing all objects created by lodel, giving them an unique id
48
-    uids = {
49
-        "name": "uids",
50
-        "columns": [
51
-            {"name": "uid", "type": "INTEGER", "extra": {"nullable": False, "primarykey": True, 'autoincrement': True}},
52
-            {"name": "table", "type": "VARCHAR(50)"}
53
-        ]
54
-    }
55
-    tables.append(uids)
56
-
57
-    # Table listing the classes
58
-    em_class = {"name": "em_class"}
59
-    em_class['columns'] = default_columns + [
60
-        {"name": "classtype", "type": "VARCHAR(50)"},
61
-        {"name": "sortcolumn", "type": "VARCHAR(50)", "extra": {"default": "rank"}},
62
-        {"name": "icon", "type": "INTEGER"},
63
-    ]
64
-    tables.append(em_class)
65
-
66
-    # Table listing the types
67
-    em_type = {"name": "em_type"}
68
-    em_type['columns'] = default_columns + [
69
-        {"name": "class_id", "type": "INTEGER", "extra": {"foreignkey": "em_class.uid", "nullable": False}},
70
-        {"name": "sortcolumn", "type": "VARCHAR(50)", "extra": {"default": "rank"}},
71
-        {"name": "icon", "type": "INTEGER"},
72
-    ]
73
-    tables.append(em_type)
74
-
75
-    # relation between types: which type can be a child of another
76
-    em_type_hierarchy = {"name": "em_type_hierarchy"}
77
-    em_type_hierarchy['columns'] = [
78
-        {"name": "superior_id", "type": "INTEGER", "extra": {"foreignkey": "em_type.uid", "nullable": False, "primarykey": True}},
79
-        {"name": "subordinate_id", "type": "INTEGER", "extra": {"foreignkey": "em_type.uid", "nullable": False, "primarykey": True}},
80
-        {"name": "nature", "type": "VARCHAR(50)", "extra": {"primarykey": True}},
81
-    ]
82
-    tables.append(em_type_hierarchy)
83
-
84
-   # Table listing the fieldgroups of a class
85
-    em_fieldgroup = {"name": "em_fieldgroup"}
86
-    em_fieldgroup['columns'] = default_columns + [
87
-        {"name": "class_id", "type": "INTEGER", "extra": {"foreignkey": "em_class.uid", "nullable": False}},
88
-    ]
89
-    tables.append(em_fieldgroup)
90
-
91
-    # Table listing the fields of a fieldgroup
92
-    em_field = {"name": "em_field"}
93
-    em_field['columns'] = default_columns + [
94
-        {"name": "fieldtype", "type": "VARCHAR(50)", "extra": {"nullable": False}},
95
-        {"name": "fieldgroup_id", "type": "INTEGER", "extra": {"foreignkey": "em_fieldgroup.uid", "nullable": False}},
96
-        {"name": "rel_to_type_id", "type": "INTEGER", "extra": {"foreignkey": "em_type.uid", "nullable": True, "server_default": sql.text('NULL')}},  # if relational: type this field refer to
97
-        {"name": "rel_field_id", "type": "INTEGER", "extra": {"foreignkey": "em_type.uid", "nullable": True, "server_default": sql.text('NULL')}},  # if relational: field that specify the rel_to_type_id
98
-        {"name": "optional", "type": "BOOLEAN"},
99
-        {"name": "internal", "type": "BOOLEAN"},
100
-        {"name": "icon", "type": "INTEGER"},
101
-    ]
102
-    tables.append(em_field)
103
-
104
-    # selected field for each type
105
-    em_field_type = {"name": "em_field_type"}
106
-    em_field_type['columns'] = [
107
-        {"name": "type_id", "type": "INTEGER", "extra": {"foreignkey": "em_type.uid", "nullable": False, "primarykey": True}},
108
-        {"name": "field_id", "type": "INTEGER", "extra": {"foreignkey": "em_field.uid", "nullable": False, "primarykey": True}},
109
-    ]
110
-    tables.append(em_field_type)
111
-
112
-    # Table of the objects created by the user (instance of the types)
113
-    objects = {
114
-        "name": "objects",
115
-        "columns": [
116
-            {"name": "uid", "type": "INTEGER", "extra": {"foreignkey": "uids.uid", "nullable": False, "primarykey": True}},
117
-            {"name": "string", "type": "VARCHAR(50)"},
118
-            {"name": "class_id", "type": "INTEGER", "extra": {"foreignkey": "em_class.uid"}},
119
-            {"name": "type_id", "type": "INTEGER", "extra": {"foreignkey": "em_type.uid"}},
120
-            {"name": "date_create", "type": "DATETIME"},
121
-            {"name": "date_update", "type": "DATETIME"},
122
-            {"name": "history", "type": "TEXT"}
123
-        ]
124
-    }
125
-    tables.append(objects)
126
-
127
-    # Table listing all files
128
-    files = {
129
-        "name": "files",
130
-        "columns": [
131
-            {"name": "uid", "type": "INTEGER", "extra": {"foreignkey": "uids.uid", "nullable": False, "primarykey": True}},
132
-            {"name": "field1", "type": "VARCHAR(50)"}
133
-        ]
134
-    }
135
-    tables.append(files)
136
-
137
-    return tables
138
-
139
-
140
-def create_column(**kwargs):
141
-    #Converting parameters
142
-    if 'type_' not in kwargs and 'type' in kwargs:
143
-        kwargs['type_'] = string_to_sqla_type(kwargs['type'])
144
-        del kwargs['type']
145
-
146
-    if 'extra' in kwargs:
147
-        # put the extra keys in kwargs
148
-        for exname in kwargs['extra']:
149
-            kwargs[exname] = kwargs['extra'][exname]
150
-        del kwargs['extra']
151
-
152
-    if 'foreignkey' in kwargs:
153
-        # Instanciate a fk
154
-        foreignkey = sql.ForeignKey(kwargs['foreignkey'])
155
-        del kwargs['foreignkey']
156
-    else:
157
-        foreignkey = None
158
-
159
-    if 'primarykey' in kwargs:
160
-        # renaming primary_key in primarykey in kwargs
161
-        kwargs['primary_key'] = kwargs['primarykey']
162
-        del kwargs['primarykey']
163
-
164
-    col = sql.Column(**kwargs)
165
-
166
-    if foreignkey is not None:
167
-        col.append_foreign_key(foreignkey)
168
-
169
-    return col
170
-
171
-
172
-## Converts a string to an sqlAlchemy column type
173
-#
174
-# @param strtype str: string describing the type of the column
175
-# @return SqlAlchemy column type
176
-# @raise NameError
177
-def string_to_sqla_type(strtype):
178
-    if 'VARCHAR' in strtype:
179
-        return string_to_varchar(strtype)
180
-    else:
181
-        try:
182
-            return getattr(sql, strtype)
183
-        except AttributeError:
184
-            raise NameError("Unknown type '" + strtype + "'")
185
-
186
-
187
-## Converts a string like 'VARCHAR(XX)' (with XX an integer) to a SqlAlchemy varchar type
188
-#
189
-# @param vstr str: String to convert
190
-# @return SqlAlchemy.VARCHAR
191
-def string_to_varchar(vstr):
192
-    check_length = re.search(re.compile('VARCHAR\(([\d]+)\)', re.IGNORECASE), vstr)
193
-    column_length = int(check_length.groups()[0]) if check_length else None
194
-    return sql.VARCHAR(length=column_length)

+ 0
- 103
Database/sqlutils.py View File

@@ -1,103 +0,0 @@
1
-# -*- coding: utf-8 -*-
2
-import os
3
-import logging as logger
4
-
5
-import sqlalchemy as sqla
6
-from django.conf import settings
7
-
8
-import EditorialModel
9
-
10
-os.environ.setdefault("DJANGO_SETTINGS_MODULE", "Lodel.settings")
11
-
12
-ENGINES = {
13
-    'mysql': {
14
-        'driver': 'pymysql',
15
-        'encoding': 'utf8'
16
-    },
17
-    'postgresql': {
18
-        'driver': 'psycopg2',
19
-        'encoding': 'utf8',
20
-    },
21
-    'sqlite': {
22
-        'driver': 'pysqlite',
23
-        'encoding': 'utf8',
24
-    },
25
-}
26
-
27
-sql_config = settings.LODEL2SQLWRAPPER
28
-
29
-
30
-## Returns an engine given dbconf name
31
-#
32
-# @param ename str: name of an item in django.conf.settings.LODEL2SQLWRAPPER['db']
33
-# @param sqlaloggin None|bool: If None leave default value, if true activate sqlalchemy logging
34
-# @return SqlAlchemy engine
35
-def get_engine(ename='default', sqlalogging=None):
36
-    # Loading confs
37
-    cfg = sql_config['db'][ename]
38
-
39
-    edata = ENGINES[cfg['ENGINE']]  # engine infos
40
-    conn_str = ""
41
-
42
-    if cfg['ENGINE'] == 'sqlite':
43
-        #SQLite connection string
44
-        conn_str = '%s+%s:///%s' % (cfg['ENGINE'], edata['driver'], cfg['NAME'])
45
-    else:
46
-        #MySQL and PostgreSQL connection string
47
-        user = cfg['USER']
48
-        user += (':' + cfg['PASSWORD'] if 'PASSWORD' in cfg else '')
49
-
50
-        if 'HOST' not in cfg:
51
-            logger.info('Not HOST in configuration, using localhost')
52
-            host = 'localhost'
53
-        else:
54
-            host = cfg['HOST']
55
-
56
-        host += (':' + cfg['PORT'] if 'PORT' in cfg else '')
57
-        conn_str = '%s+%s://' % (cfg['ENGINE'], edata['driver'])
58
-        conn_str += '%s@%s/%s' % (user, host, cfg['NAME'])
59
-
60
-    ret = sqla.create_engine(conn_str, encoding=edata['encoding'], echo=sqlalogging)
61
-    logger.debug("Getting engine :" + str(ret))
62
-
63
-    return ret
64
-
65
-
66
-## Return a sqlalchemy.MetaData object
67
-# @param engine sqlalchemy.engine : A sqlalchemy engine
68
-# @return an sql alechemy MetaData instance bind to engine
69
-def meta(engine):
70
-    res = sqla.MetaData(bind=engine)
71
-    res.reflect(bind=engine)
72
-    return res
73
-
74
-
75
-## Return an sqlalchemy table given an EmComponent child class
76
-# @warning Except a class type not an instance
77
-# @param cls : An EmComponent child class
78
-# @return An sqlalchemy table
79
-# @throw TypeError if em_instance is an EmComponent  or not an EmComponent child class (or an instance)
80
-# @todo Move this function as an instance method ?
81
-def get_table(self):
82
-    if not issubclass(self.__class__, EditorialModel.components.EmComponent) or self.table is None:
83
-        raise TypeError("Excepting an EmComponent child class not an " + str(self.__class__))
84
-    engine = self.db_engine
85
-    return sqla.Table(self.table, meta(engine))
86
-
87
-
88
-## This function is intended to execute ddl defined in sqlalter
89
-# @warning There is a dirty workaround here, DDL should returns only one query, but DropColumn for sqlite has to return 4 queries (rename, create, insert, drop). There is a split on the compiled SQL to extract and execute one query at a time
90
-# @param ddl DDLElement: Can be an Database.sqlalter.DropColumn Database.sqlalter.AddColumn or Database.sqlalter.AlterColumn
91
-# @param db_engine: A database engine
92
-# @return True if success, else False
93
-def ddl_execute(ddl, db_engine):
94
-    conn = db_engine.connect()
95
-    req = str(ddl.compile(dialect=db_engine.dialect))
96
-    queries = req.split(';')
97
-    for query in queries:
98
-        logger.debug("Executing custom raw SQL query : '" + query + "'")
99
-        ret = conn.execute(query)
100
-        if not bool(ret):
101
-            return False
102
-    conn.close()
103
-    return True

+ 0
- 1
EditorialModel/test/test_classes.py View File

@@ -25,7 +25,6 @@ EM_TEST_OBJECT = None
25 25
 
26 26
 
27 27
 ## run once for this module
28
-# define the Database for this module (an sqlite database)
29 28
 def setUpModule():
30 29
     global EM_TEST_OBJECT
31 30
     #EM_TEST_OBJECT = Model(EmBackendJson(EM_TEST), migration_handler=DjandoMigrationHandler('LodelTestInstance'))

+ 0
- 4
EditorialModel/test/test_field.py View File

@@ -12,13 +12,9 @@ EM_TEST_OBJECT = None
12 12
 ## SetUpModule
13 13
 #
14 14
 # This function is called once for this module.
15
-# It is designed to overwrite the database configurations, and prepare objects for test_case initialization
16 15
 def setUpModule():
17 16
     global EM_TEST_OBJECT
18 17
     EM_TEST_OBJECT = Model(EmBackendJson(EM_TEST))
19
-    #initTestDb(TEST_FIELD_DBNAME)
20
-    #setDbConf(TEST_FIELD_DBNAME)
21
-    #logging.basicConfig(level=logging.CRITICAL)
22 18
 
23 19
 
24 20
 def tearDownModule():

+ 0
- 87
EditorialModel/test/utils.py View File

@@ -1,87 +0,0 @@
1
-import os
2
-import logging
3
-import shutil
4
-
5
-from django.conf import settings
6
-from Database import sqlsetup
7
-
8
-
9
-_TESTDB_DEFAULT_DIR = '/tmp/'
10
-_TESTDB_DEFAULT_NAME = 'lodel2_test_db.sqlite'
11
-_TESTDB_COPY_SUFFIX = '_bck'
12
-
13
-## Make a copy of an empty Db created by Database::SQLSetup::initDb()
14
-#
15
-# Usage example :
16
-#   #Using 'default' as dbconfname
17
-#   def setUpModule():
18
-#       dbname = 'supertestdb'
19
-#       initTestDb(dbname)
20
-#       setDbConf(dbname)
21
-#       ...
22
-#
23
-#   #Using another name as dbconfname
24
-#   def setUpModule():
25
-#       dbname = 'superdbtest'
26
-#       initTestDb(dbname)
27
-#       setDbConf(dbname, 'mytest_dbconf')
28
-#
29
-#       db_engine = sqlutils.getEngine('mytest_dbconf')
30
-#       EmComponent.dbconf = 'mytest_dbconf'
31
-#       #WARNING !!! This example as few chances to work due to the bad isolation of data sources in EmComponent... Will be solved with the EM object
32
-#
33
-def initTestDb(dbname = _TESTDB_DEFAULT_NAME, dbdir = _TESTDB_DEFAULT_DIR):
34
-
35
-    dbname = os.path.join(dbdir, dbname)
36
-    db_default = os.path.join(_TESTDB_DEFAULT_DIR, _TESTDB_DEFAULT_NAME)
37
-    db_copy = os.path.join(_TESTDB_DEFAULT_DIR, _TESTDB_DEFAULT_NAME+_TESTDB_COPY_SUFFIX)
38
-
39
-    if not os.path.isfile(db_copy):
40
-        #The 'backup' copy didn't exists yet. Create it.
41
-        settings.LODEL2SQLWRAPPER['db']['dbtest_default'] = {
42
-            'ENGINE': 'sqlite',
43
-            'NAME': db_default,
44
-        }
45
-        sqlsetup.init_db(dbconfname = 'dbtest_default')
46
-        #Make the backup copy
47
-        shutil.copyfile(db_default, db_copy)
48
-    
49
-    #Copy the Db at the wanted location
50
-    shutil.copyfile(db_copy, dbname)
51
-    return dbname
52
-
53
-def copyDb(dbname_src, dbname_dst, dbdir_src = _TESTDB_DEFAULT_DIR, dbdir_dst = _TESTDB_DEFAULT_DIR):
54
-    dbname_src = os.path.join(dbdir_src, dbname_src)
55
-    dbname_dst = os.path.join(dbdir_dst, dbname_dst)
56
-    shutil.copyfile(dbname_src, dbname_dst)
57
-    pass
58
-
59
-
60
-def saveDbState(dbname = _TESTDB_DEFAULT_NAME, dbdir = _TESTDB_DEFAULT_DIR):
61
-    dbname = os.path.join(dbdir, dbname)
62
-    shutil.copyfile(dbname, dbname+_TESTDB_COPY_SUFFIX)
63
-    pass
64
-
65
-def restoreDbState(dbname = _TESTDB_DEFAULT_NAME, dbdir = _TESTDB_DEFAULT_DIR):
66
-    dbname = os.path.join(dbdir, dbname)
67
-    shutil.copyfile(dbname+_TESTDB_COPY_SUFFIX, dbname)
68
-    pass
69
-
70
-def cleanDb(dbname = _TESTDB_DEFAULT_NAME, dbdir = _TESTDB_DEFAULT_DIR):
71
-    dbname = os.path.join(dbdir, dbname)
72
-    try: os.unlink(dbname)
73
-    except:pass
74
-    try: os.unlink(dbname+_TESTDB_COPY_SUFFIX)
75
-    except:pass
76
-    pass
77
-
78
-
79
-def setDbConf(dbname, dbconfname = 'default', dbdir = _TESTDB_DEFAULT_DIR):
80
-    
81
-    settings.LODEL2SQLWRAPPER['db'][dbconfname] = {
82
-        'ENGINE': 'sqlite',
83
-        'NAME': os.path.join(_TESTDB_DEFAULT_DIR, dbname)
84
-    }
85
-    pass
86
- 
87
-    

+ 0
- 3
EditorialModel/types.py View File

@@ -1,8 +1,5 @@
1 1
 #-*- coding: utf-8 -*-
2 2
 
3
-# from Database import sqlutils
4
-# import sqlalchemy as sql
5
-
6 3
 import EditorialModel
7 4
 from EditorialModel.components import EmComponent
8 5
 from EditorialModel.fields import EmField

Loading…
Cancel
Save