diff options
author | Priit Laes <plaes@plaes.org> | 2010-07-01 14:57:16 +0300 |
---|---|---|
committer | Priit Laes <plaes@plaes.org> | 2010-07-01 23:50:39 +0300 |
commit | 98b85bef575a7861c7d4310c5ec5ec98692fe1ad (patch) | |
tree | c1fd402f401199be336368adeddcd4966d12adce | |
parent | Added Setting class/table to data model (diff) | |
download | gsoc2010-grumpy-98b85bef575a7861c7d4310c5ec5ec98692fe1ad.tar.gz gsoc2010-grumpy-98b85bef575a7861c7d4310c5ec5ec98692fe1ad.tar.bz2 gsoc2010-grumpy-98b85bef575a7861c7d4310c5ec5ec98692fe1ad.zip |
Move session and db engine code into grumpy.database
-rw-r--r-- | grumpy/database.py | 3 | ||||
-rwxr-xr-x | utils/grumpy_sync.py | 10 |
2 files changed, 5 insertions, 8 deletions
diff --git a/grumpy/database.py b/grumpy/database.py index 2125859..bbc5802 100644 --- a/grumpy/database.py +++ b/grumpy/database.py @@ -18,9 +18,12 @@ engine = create_engine('postgresql://grumpy:grumpy@localhost/grumpy') session = scoped_session(sessionmaker(autocommit=False, autoflush=False, bind=engine)) +Base.query = session.query_property() def init_db(): + """Initialize database schema""" Base.metadata.create_all(bind=engine) def drop_db(): + """Drop all database data and schema""" Base.metadata.drop_all(bind=engine) diff --git a/utils/grumpy_sync.py b/utils/grumpy_sync.py index 7da95c8..20c4674 100755 --- a/utils/grumpy_sync.py +++ b/utils/grumpy_sync.py @@ -10,7 +10,6 @@ from pkgcore.ebuild import repository from sqlalchemy import create_engine from sqlalchemy.orm import scoped_session, sessionmaker -from sqlalchemy.orm.exc import NoResultFound from snakeoil.fileutils import iter_read_bash @@ -18,16 +17,11 @@ path = os.path.join(os.path.dirname(__file__), os.path.pardir) sys.path.insert(0, path) del path -from grumpy.models import (Base, Category, Developer, Ebuild, Herd, +from grumpy.database import session +from grumpy.models import (Base, Category, Developer, Ebuild, Herd, \ Package, Setting) def main(path): - engine = create_engine('postgresql://grumpy:grumpy@localhost/grumpy') - session = scoped_session(sessionmaker(autocommit=False, - autoflush=False, - bind=engine)) - Base.query = session.query_property() - # pkgcore part to fetch all the ebuild information conf = load_config() eclass_cache = conf.eclass_cache['eclass stack'] |