Loading installsystems/database.py +13 −0 Original line number Diff line number Diff line Loading @@ -47,10 +47,23 @@ class Database(object): raise Exception("Database not exists") self.conn = sqlite3.connect(self.path, isolation_level=None) self.conn.execute("PRAGMA foreign_keys = ON") # get database version try: r = self.ask("SELECT value FROM misc WHERE key = 'version'").fetchone() if r is None: raise TypeError() self.version = r[0] except: self.version = u"1" # we only support database v1 if self.version != u"1": debug("Invalid database format: %s" % self.version) raise Exception("Invalid database format") # we make a query to be sure format is valid try: self.ask("SELECT * FROM image") except: debug("Invalid database format: %s" % self.version) raise Exception("Invalid database format") def begin(self): Loading installsystems/repository.py +7 −2 Original line number Diff line number Diff line Loading @@ -66,7 +66,6 @@ class Repository(object): def __init__(self, config): self.config = config self.version = 1 self.local = istools.isfile(self.config.path) if not self.config.offline: try: Loading @@ -76,7 +75,6 @@ class Repository(object): if self.config.offline: debug("Repository %s is offline" % config.name) def __getattribute__(self, name): ''' Raise an error if repository is unavailable Loading @@ -92,6 +90,13 @@ class Repository(object): raise Exception("Repository %s is offline" % config.name) return object.__getattribute__(self, name) @property def version(self): ''' Return repository version ''' return self.db.version def init(self): ''' Initialize an empty base repository Loading Loading
installsystems/database.py +13 −0 Original line number Diff line number Diff line Loading @@ -47,10 +47,23 @@ class Database(object): raise Exception("Database not exists") self.conn = sqlite3.connect(self.path, isolation_level=None) self.conn.execute("PRAGMA foreign_keys = ON") # get database version try: r = self.ask("SELECT value FROM misc WHERE key = 'version'").fetchone() if r is None: raise TypeError() self.version = r[0] except: self.version = u"1" # we only support database v1 if self.version != u"1": debug("Invalid database format: %s" % self.version) raise Exception("Invalid database format") # we make a query to be sure format is valid try: self.ask("SELECT * FROM image") except: debug("Invalid database format: %s" % self.version) raise Exception("Invalid database format") def begin(self): Loading
installsystems/repository.py +7 −2 Original line number Diff line number Diff line Loading @@ -66,7 +66,6 @@ class Repository(object): def __init__(self, config): self.config = config self.version = 1 self.local = istools.isfile(self.config.path) if not self.config.offline: try: Loading @@ -76,7 +75,6 @@ class Repository(object): if self.config.offline: debug("Repository %s is offline" % config.name) def __getattribute__(self, name): ''' Raise an error if repository is unavailable Loading @@ -92,6 +90,13 @@ class Repository(object): raise Exception("Repository %s is offline" % config.name) return object.__getattribute__(self, name) @property def version(self): ''' Return repository version ''' return self.db.version def init(self): ''' Initialize an empty base repository Loading