From b3d9560c2d2fb267c3eef90658b0438c31b7e18d Mon Sep 17 00:00:00 2001 From: lilydjwg Date: Mon, 11 Feb 2013 21:28:09 +0800 Subject: [PATCH] check database version before use --- scripts/common.py => dbutil.py | 0 repomon.py | 6 ++++++ scripts/upgrade_from_0.1.py | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-) rename scripts/common.py => dbutil.py (100%) diff --git a/scripts/common.py b/dbutil.py similarity index 100% rename from scripts/common.py rename to dbutil.py diff --git a/repomon.py b/repomon.py index 18340de..d5743bc 100755 --- a/repomon.py +++ b/repomon.py @@ -21,6 +21,7 @@ import tornado.process import archpkg import pkgreader +import dbutil logger = logging.getLogger(__name__) @@ -190,7 +191,12 @@ class EventHandler(pyinotify.ProcessEvent): base = config.get('path') dbname = config.get('info-db', os.path.join(base, 'pkginfo.db')) + new_db = not os.path.exists(dbname) self._db = sqlite3.connect(dbname, isolation_level=None) # isolation_level=None means autocommit + if new_db: + dbutil.setver(self._db, '0.2') + else: + assert dbutil.getver(self._db) == '0.2', 'wrong database version, please upgrade (see scripts directory)' self._db.execute('''create table if not exists pkginfo (filename text unique, pkgname text, diff --git a/scripts/upgrade_from_0.1.py b/scripts/upgrade_from_0.1.py index c3f3304..2548f4d 100755 --- a/scripts/upgrade_from_0.1.py +++ b/scripts/upgrade_from_0.1.py @@ -10,7 +10,7 @@ top_dir = os.path.normpath(os.path.join(__file__, '../..')) sys.path.append(top_dir) import pkgreader -from common import * +from dbutil import * def main(conffile): config = configparser.ConfigParser()