diff options
author | 2015-04-19 16:37:00 +0200 | |
---|---|---|
committer | 2015-04-19 16:37:00 +0200 | |
commit | f162ae0de0f71391c56957389cc3c8babc8022e1 (patch) | |
tree | c85c8117da6e20fe49f91c933d8c7e57eb808cb8 /pyload/database/Backend.py | |
parent | Merge pull request #8 from ardi69/0.4.10 (diff) | |
download | pyload-f162ae0de0f71391c56957389cc3c8babc8022e1.tar.xz |
Use with statement
Diffstat (limited to 'pyload/database/Backend.py')
-rw-r--r-- | pyload/database/Backend.py | 34 |
1 files changed, 16 insertions, 18 deletions
diff --git a/pyload/database/Backend.py b/pyload/database/Backend.py index b0e94711e..b105723cc 100644 --- a/pyload/database/Backend.py +++ b/pyload/database/Backend.py @@ -1,6 +1,8 @@ # -*- coding: utf-8 -*- # @author: RaNaN, mkaay +from __future__ import with_statement + from threading import Event, Thread from os import remove from os.path import exists @@ -167,26 +169,22 @@ class DatabaseBackend(Thread): def _checkVersion(self): """ check db version and delete it if needed""" if not exists("files.version"): - f = open("files.version", "wb") - f.write(str(DB_VERSION)) - f.close() + with open("files.version", "wb") as f: + f.write(str(DB_VERSION)) return - f = open("files.version", "rb") - v = int(f.read().strip()) - f.close() - if v < DB_VERSION: - if v < 2: - try: - self.manager.core.log.warning(_("Filedatabase was deleted due to incompatible version.")) - except Exception: - print "Filedatabase was deleted due to incompatible version." - remove("files.version") - move("files.db", "files.backup.db") - f = open("files.version", "wb") - f.write(str(DB_VERSION)) - f.close() - return v + with open("files.version", "wb+") as f: + v = int(f.read().strip()) + if v < DB_VERSION: + if v < 2: + try: + self.manager.core.log.warning(_("Filedatabase was deleted due to incompatible version.")) + except Exception: + print "Filedatabase was deleted due to incompatible version." + remove("files.version") + move("files.db", "files.backup.db") + f.write(str(DB_VERSION)) + return v def _convertDB(self, v): |