changeset 243:9d64df490248

fixed bug when there was no dbfile, and dbmanage raise an exception
author Marcin Kuzminski <marcin@python-works.com>
date Tue, 01 Jun 2010 22:06:48 +0200
parents 5da4ef115006
children 782f0692b29c
files pylons_app/lib/db_manage.py
diffstat 1 files changed, 4 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/pylons_app/lib/db_manage.py	Sun May 30 22:08:54 2010 +0200
+++ b/pylons_app/lib/db_manage.py	Tue Jun 01 22:06:48 2010 +0200
@@ -26,10 +26,12 @@
         engine = create_engine(dburi, echo=log_sql) 
         init_model(engine)
         self.sa = Session()
+        self.db_exists = False
     
     def check_for_db(self, override):
         log.info('checking for exisiting db')
         if os.path.isfile(jn(ROOT, self.dbname)):
+            self.db_exists = True
             log.info('database exisist')
             if not override:
                 raise Exception('database already exists')
@@ -41,7 +43,8 @@
         self.check_for_db(override)
         if override:
             log.info("database exisist and it's going to be destroyed")
-            os.remove(jn(ROOT, self.dbname))
+            if self.db_exists:
+                os.remove(jn(ROOT, self.dbname))
         Base.metadata.create_all(checkfirst=override)
         log.info('Created tables for %s', self.dbname)