[TASK] Begin crunching the sqlite database.
This commit is contained in:
parent
89e76b6844
commit
eca9caeb62
|
@ -154,11 +154,12 @@ class ProjectView(ProtectedFormView, SingleObjectMixin):
|
||||||
path = os.path.join(settings.MEDIA_ROOT, relative_path)
|
path = os.path.join(settings.MEDIA_ROOT, relative_path)
|
||||||
print "Path: " + path
|
print "Path: " + path
|
||||||
|
|
||||||
#TODO: Use file to do things here.
|
#Now things will happen
|
||||||
from service.sqlitehelper import import_sqlite
|
from service.sqlitehelper import import_sqlite
|
||||||
import_sqlite(project_id=project_id, sqlite_file=path)
|
import_sqlite(project_id=project_id, sqlite_file=path)
|
||||||
|
|
||||||
default_storage.delete(relative_path)
|
# Maybe it is a good idea to keep the file
|
||||||
|
# default_storage.delete(relative_path)
|
||||||
|
|
||||||
return super(ProjectView, self).form_valid(form)
|
return super(ProjectView, self).form_valid(form)
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,41 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def import_sqlite(project_id, sqlite_file):
|
def import_sqlite(project_id, sqlite_file):
|
||||||
|
print "This is import_sqlite speaking!"
|
||||||
|
print project_id
|
||||||
|
print sqlite_file
|
||||||
|
print "Importing Data is still a TODO!"
|
||||||
|
|
||||||
|
from sqlalchemy import *
|
||||||
|
from sqlalchemy.schema import CreateSchema
|
||||||
|
|
||||||
|
engine = create_engine('sqlite+pysqlite:///project_import_9.ctt4', echo=True)
|
||||||
|
meta = MetaData(bind=engine)
|
||||||
|
meta.reflect()
|
||||||
|
#meta.tables['Reference']
|
||||||
|
#meta.tables['ReferenceAuthor'].select().execute().fetchall()
|
||||||
|
|
||||||
|
# Now we need to "convert" unsupported types :-/
|
||||||
|
for table in meta.sorted_tables:
|
||||||
|
table_name = str(table)
|
||||||
|
columns = table.columns.items()
|
||||||
|
for column_tuple in columns:
|
||||||
|
column_name = column_tuple[0]
|
||||||
|
actual_sqlalchemy_column = column_tuple[1]
|
||||||
|
column_type = str(vars(actual_sqlalchemy_column)['type'])
|
||||||
|
print table_name + "." + column_name + ': ' + column_type
|
||||||
|
print
|
||||||
|
print
|
||||||
|
|
||||||
|
""" TODO: since DATETIME (sqlite3) does not map onto TIMESTAMP / DATE (postgresql), some mapping/migrating is required! """
|
||||||
|
|
||||||
|
# Shove it up into postgresql's ... you know it.
|
||||||
|
psql_engine = create_engine("postgresql://citavi_mapper:foobar2000@localhost:5432/citavi_mapper")
|
||||||
|
psql_engine.execute(CreateSchema('alchemytest'))
|
||||||
|
meta.create_all(psql_engine)
|
||||||
|
|
||||||
|
|
||||||
pass
|
pass
|
Loading…
Reference in New Issue