Reviewers: vvanderleun.cloudsuite,
Please review this at http://codereview.tryton.org/33001/
Affected files:
M trytond/protocols/dispatcher.py
M trytond/protocols/webdav.py
M trytond/server.py
Index: trytond/protocols/dispatcher.py
===================================================================
--- a/trytond/protocols/dispatcher.py
+++ b/trytond/protocols/dispatcher.py
@@ -33,6 +33,7 @@
try:
database = Database(database_name).connect()
cursor = database.cursor()
+ cursor.close()
except Exception:
return False
res = security.login(database_name, user, session)
@@ -80,8 +81,10 @@
database = Database().connect()
try:
cursor = database.cursor()
- res = database.list(cursor)
- cursor.close(close=True)
+ try:
+ res = database.list(cursor)
+ finally:
+ cursor.close(close=True)
except Exception:
res = []
return res
Index: trytond/protocols/webdav.py
===================================================================
--- a/trytond/protocols/webdav.py
+++ b/trytond/protocols/webdav.py
@@ -170,12 +170,11 @@
dbname, dburi = self._get_dburi(uri)
if not dbname:
database = Database().connect()
+ cursor = database.cursor()
try:
- try:
- cursor = database.cursor()
- lists = database.list(cursor)
- except Exception:
- lists = []
+ lists = database.list(cursor)
+ except Exception:
+ lists = []
finally:
cursor.close()
for dbname in lists:
Index: trytond/server.py
===================================================================
--- a/trytond/server.py
+++ b/trytond/server.py
@@ -87,26 +87,30 @@
database = Database(db_name).connect()
cursor = database.cursor()
- if CONFIG['init']:
- if not cursor.test():
- self.logger.info("init db")
- Database.init(cursor)
- init[db_name] = True
- cursor.commit()
+ try:
+ if CONFIG['init']:
+ if not cursor.test():
+ self.logger.info("init db")
+ Database.init(cursor)
+ init[db_name] = True
+ cursor.commit()
+ elif not cursor.test():
+ raise Exception("'%s' is not a Tryton database!" %
db_name)
+ finally:
cursor.close()
- elif not cursor.test():
- raise Exception("'%s' is not a Tryton database!" % db_name)
Pool.start()
for db_name in CONFIG["db_name"]:
cursor = Database(db_name).connect().cursor()
- if not cursor.test():
- raise Exception("'%s' is not a Tryton database!" % db_name)
- cursor.execute('SELECT code FROM ir_lang ' \
- 'WHERE translatable')
- lang = [x[0] for x in cursor.fetchall()]
- cursor.close()
+ try:
+ if not cursor.test():
+ raise Exception("'%s' is not a Tryton database!" %
db_name)
+ cursor.execute('SELECT code FROM ir_lang ' \
+ 'WHERE translatable')
+ lang = [x[0] for x in cursor.fetchall()]
+ finally:
+ cursor.close()
update = bool(CONFIG['init'] or CONFIG['update'])
Pool(db_name).init(update=update, lang=lang)
@@ -129,17 +133,20 @@
database = Database(db_name).connect()
cursor = database.cursor()
- salt = ''.join(random.sample(string.letters +
string.digits, 8))
- password += salt
- if hashlib:
- password = hashlib.sha1(password).hexdigest()
- else:
- password = sha.new(password).hexdigest()
- cursor.execute('UPDATE res_user ' \
- 'SET password = %s, salt = %s ' \
- 'WHERE login = \'admin\'', (password, salt))
- cursor.commit()
- cursor.close()
+ try:
+ salt = ''.join(random.sample(
+ string.letters + string.digits, 8))
+ password += salt
+ if hashlib:
+ password = hashlib.sha1(password).hexdigest()
+ else:
+ password = sha.new(password).hexdigest()
+ cursor.execute('UPDATE res_user ' \
+ 'SET password = %s, salt = %s ' \
+ 'WHERE login = \'admin\'', (password, salt))
+ cursor.commit()
+ finally:
+ cursor.close()
if update:
self.logger.info('Update/Init succeed!')
--
[email protected] mailing list