comparison pylons_app/lib/db_manage.py @ 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 7c4fa2a66195
children bad9ccac26b7
comparison
equal deleted inserted replaced
242:5da4ef115006 243:9d64df490248
24 self.dbname = 'hg_app.db' 24 self.dbname = 'hg_app.db'
25 dburi = 'sqlite:////%s' % jn(ROOT, self.dbname) 25 dburi = 'sqlite:////%s' % jn(ROOT, self.dbname)
26 engine = create_engine(dburi, echo=log_sql) 26 engine = create_engine(dburi, echo=log_sql)
27 init_model(engine) 27 init_model(engine)
28 self.sa = Session() 28 self.sa = Session()
29 self.db_exists = False
29 30
30 def check_for_db(self, override): 31 def check_for_db(self, override):
31 log.info('checking for exisiting db') 32 log.info('checking for exisiting db')
32 if os.path.isfile(jn(ROOT, self.dbname)): 33 if os.path.isfile(jn(ROOT, self.dbname)):
34 self.db_exists = True
33 log.info('database exisist') 35 log.info('database exisist')
34 if not override: 36 if not override:
35 raise Exception('database already exists') 37 raise Exception('database already exists')
36 38
37 def create_tables(self, override=False): 39 def create_tables(self, override=False):
39 Create a auth database 41 Create a auth database
40 """ 42 """
41 self.check_for_db(override) 43 self.check_for_db(override)
42 if override: 44 if override:
43 log.info("database exisist and it's going to be destroyed") 45 log.info("database exisist and it's going to be destroyed")
44 os.remove(jn(ROOT, self.dbname)) 46 if self.db_exists:
47 os.remove(jn(ROOT, self.dbname))
45 Base.metadata.create_all(checkfirst=override) 48 Base.metadata.create_all(checkfirst=override)
46 log.info('Created tables for %s', self.dbname) 49 log.info('Created tables for %s', self.dbname)
47 50
48 def admin_prompt(self): 51 def admin_prompt(self):
49 import getpass 52 import getpass