summaryrefslogtreecommitdiffstats
path: root/src/lib/Server/Snapshots/__init__.py
diff options
context:
space:
mode:
authorNarayan Desai <desai@mcs.anl.gov>2009-03-02 04:05:06 +0000
committerNarayan Desai <desai@mcs.anl.gov>2009-03-02 04:05:06 +0000
commit1e3f8604797459a1cb45db617958256557cde9d8 (patch)
treefcfb160553e87f92ab7e62758961e436023424cb /src/lib/Server/Snapshots/__init__.py
parent795301a3646637aa3a8a1cd8a46863d76422e2ee (diff)
downloadbcfg2-1e3f8604797459a1cb45db617958256557cde9d8.tar.gz
bcfg2-1e3f8604797459a1cb45db617958256557cde9d8.tar.bz2
bcfg2-1e3f8604797459a1cb45db617958256557cde9d8.zip
Snapshots update - storage of packages works from clients (old-style statistics)
git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@5092 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src/lib/Server/Snapshots/__init__.py')
-rw-r--r--src/lib/Server/Snapshots/__init__.py22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/lib/Server/Snapshots/__init__.py b/src/lib/Server/Snapshots/__init__.py
index 74a3894d7..b94511ebd 100644
--- a/src/lib/Server/Snapshots/__init__.py
+++ b/src/lib/Server/Snapshots/__init__.py
@@ -1 +1,21 @@
-__all__ = ['models']
+__all__ = ['models', 'db_from_config', 'setup_session']
+
+import sqlalchemy, sqlalchemy.orm, ConfigParser
+
+def db_from_config(fname='/etc/bcfg2.conf'):
+ cp = ConfigParser.ConfigParser()
+ cp.read([fname])
+ driver = cp.get('snapshots', 'driver')
+ if driver == 'sqlite':
+ path = cp.get('snapshots', 'database')
+ return 'sqlite:///%s' % path
+ else:
+ raise Exception, "not done yet"
+
+
+def setup_session(debug=False):
+ engine = sqlalchemy.create_engine(db_from_config(),
+ echo=debug)
+ Session = sqlalchemy.orm.sessionmaker()
+ Session.configure(bind=engine)
+ return Session()