diff options
author | 2015-08-05 01:55:16 -0400 | |
---|---|---|
committer | 2015-08-05 01:58:59 -0400 | |
commit | daafd7d31457b018797407d97188a4829839172e (patch) | |
tree | b42e1a7d006c0bb4e15142f793bd45796a1a1ff9 /layman | |
parent | update.py: Adds functionality to ensure proper sqlite migration (diff) | |
download | layman-daafd7d31457b018797407d97188a4829839172e.tar.gz layman-daafd7d31457b018797407d97188a4829839172e.tar.bz2 layman-daafd7d31457b018797407d97188a4829839172e.zip |
Adds remove function for overlay removal from databases
sqlite_db.py: Also changes the way in which feeds are gathered in
read_db(), this shows the nature of feeds being an unrequired attribute
of the overlay.
Diffstat (limited to 'layman')
-rw-r--r-- | layman/db.py | 2 | ||||
-rw-r--r-- | layman/db_modules/json_db/__init__.py | 3 | ||||
-rw-r--r-- | layman/db_modules/json_db/json_db.py | 8 | ||||
-rw-r--r-- | layman/db_modules/sqlite_db/__init__.py | 5 | ||||
-rw-r--r-- | layman/db_modules/sqlite_db/sqlite_db.py | 23 | ||||
-rw-r--r-- | layman/db_modules/xml_db/__init__.py | 3 | ||||
-rw-r--r-- | layman/db_modules/xml_db/xml_db.py | 8 | ||||
-rw-r--r-- | layman/dbbase.py | 13 |
8 files changed, 53 insertions, 12 deletions
diff --git a/layman/db.py b/layman/db.py index ba7399c..673e6bf 100644 --- a/layman/db.py +++ b/layman/db.py @@ -148,7 +148,7 @@ class DB(DbBase): if overlay.name in self.overlays.keys(): overlay.delete(self.config['storage']) repo_ok = self.repo_conf.delete(overlay) - del self.overlays[overlay.name] + self.remove(overlay, self.path) self.write(self.path) else: self.output.error('No local overlay named "' + overlay.name + '"!') diff --git a/layman/db_modules/json_db/__init__.py b/layman/db_modules/json_db/__init__.py index 1502b9d..ac4daa7 100644 --- a/layman/db_modules/json_db/__init__.py +++ b/layman/db_modules/json_db/__init__.py @@ -13,10 +13,11 @@ module_spec = { 'name': 'json_db', 'class': 'DBHandler', 'description': __doc__, - 'functions': ['add_new', 'read_db', 'write'], + 'functions': ['add_new', 'read_db', 'remove', 'write'], 'func_desc': { 'add_new': 'Adds overlay(s) from provided database text', 'read_db': 'Reads the list of overlays from database file', + 'remove' : 'Removes overlay from installed overlays list', 'write' : 'Writes the list of overlays to database file', }, } diff --git a/layman/db_modules/json_db/json_db.py b/layman/db_modules/json_db/json_db.py index 47413c6..d466385 100644 --- a/layman/db_modules/json_db/json_db.py +++ b/layman/db_modules/json_db/json_db.py @@ -104,6 +104,14 @@ class DBHandler(object): return True + def remove(self, overlay, path): + ''' + Removes an overlay from installed overlays list. + ''' + if overlay.name in self.overlays: + del self.overlays[overlay.name] + + def write(self, path): ''' Write the list of overlays to a file. diff --git a/layman/db_modules/sqlite_db/__init__.py b/layman/db_modules/sqlite_db/__init__.py index 7d2fba4..536fc2d 100644 --- a/layman/db_modules/sqlite_db/__init__.py +++ b/layman/db_modules/sqlite_db/__init__.py @@ -13,10 +13,11 @@ module_spec = { 'name': 'sqlite_db', 'class': 'DBHandler', 'description': __doc__, - 'functions': ['add_new', 'read_db', 'write'], + 'functions': ['add_new', 'read_db', 'remove', 'write'], 'func_desc': { - 'add_new': 'Adds overlay(s) from provided database text', + 'add_new': 'Adds overlay(s) from provided database file', 'read_db': 'Reads the list of overlays from database file', + 'remove' : 'Removes overlay from provided database file', 'write' : 'Writes the list of overlays to database file', }, } diff --git a/layman/db_modules/sqlite_db/sqlite_db.py b/layman/db_modules/sqlite_db/sqlite_db.py index 1d079a3..aef9661 100644 --- a/layman/db_modules/sqlite_db/sqlite_db.py +++ b/layman/db_modules/sqlite_db/sqlite_db.py @@ -103,8 +103,8 @@ class DBHandler(object): cursor.execute('''CREATE TABLE IF NOT EXISTS Overlay ( Overlay_ID INTEGER PRIMARY KEY AUTOINCREMENT, Name TEXT, Priority TEXT, Status TEXT, Quality TEXT, Homepage - TEXT, IRC TEXT, License TEXT, UNIQUE (Name, Homepage, License) - ON CONFLICT IGNORE )''') + TEXT, IRC TEXT, License TEXT, UNIQUE (Name) ON CONFLICT IGNORE ) + ''') cursor.execute('''CREATE TABLE IF NOT EXISTS Owner ( Owner_ID INTEGER PRIMARY KEY AUTOINCREMENT, Owner_Name TEXT, Owner_Email TEXT, UNIQUE (Owner_Name, Owner_Email) ON @@ -180,15 +180,17 @@ class DBHandler(object): cursor.execute('''SELECT Description FROM Description JOIN Overlay USING (Overlay_ID) WHERE Overlay_ID = ?''', (overlay_id,)) - overlay['description'] = cursor.fetchall() - - if len(overlay['description']): - overlay['description'] = overlay['description'][0] + overlay['description'] = cursor.fetchall()[0] overlay['status'] = overlay_info[3] overlay['quality'] = overlay_info[4] overlay['priority'] = overlay_info[2] - overlay['license'] = overlay_info[7] + + if overlay_info[7]: + overlay['license'] = overlay_info[7] + else: + overlay['license'] = None + overlay['homepage'] = overlay_info[5] overlay['IRC'] = overlay_info[6] @@ -196,9 +198,13 @@ class DBHandler(object): (Overlay_ID) WHERE Overlay_ID = ?''', (overlay_id,)) overlay['feed'] = cursor.fetchall() + if len(overlay['feed']): + overlay['feed'] = overlay['feed'][0] + self.overlays[overlay_info[1]] = Overlay(self.config, ovl_dict=overlay, ignore=self.ignore) + connection.close() def add_new(self, document=None, origin=None): @@ -316,6 +322,9 @@ class DBHandler(object): connection.commit() + if overlay.name in self.overlays: + del self.overlays[overlay.name] + def write(self, path): ''' diff --git a/layman/db_modules/xml_db/__init__.py b/layman/db_modules/xml_db/__init__.py index 3a3abd1..c8a5bf9 100644 --- a/layman/db_modules/xml_db/__init__.py +++ b/layman/db_modules/xml_db/__init__.py @@ -13,10 +13,11 @@ module_spec = { 'name': 'xml_db', 'class': 'DBHandler', 'description': __doc__, - 'functions': ['add_new', 'read_db', 'write'], + 'functions': ['add_new', 'read_db', 'remove', 'write'], 'func_desc': { 'add_new': 'Adds overlay(s) from provided database text', 'read_db': 'Reads the list of overlays from database file', + 'remove' : 'Removes overlay from installed overlays list', 'write' : 'Writes the list of overlays to database file', }, } diff --git a/layman/db_modules/xml_db/xml_db.py b/layman/db_modules/xml_db/xml_db.py index 38a19d2..316d8f9 100644 --- a/layman/db_modules/xml_db/xml_db.py +++ b/layman/db_modules/xml_db/xml_db.py @@ -149,6 +149,14 @@ class DBHandler(object): return True + def remove(self, overlay, path): + ''' + Removes an overlay from list of installed overlays. + ''' + if overlay.name in self.overlays: + del self.overlays[overlay.name] + + def write(self, path): ''' Write the list of overlays to a file. diff --git a/layman/dbbase.py b/layman/dbbase.py index 7832565..cecbf5c 100644 --- a/layman/dbbase.py +++ b/layman/dbbase.py @@ -215,6 +215,19 @@ class DbBase(object): db_ctl.write(path) + def remove(self, overlay, path): + ''' + Remove an overlay from the database. + ''' + db_ctl = self.mod_ctl.get_class(self.db_type)(self.config, + self.overlays, + self.paths, + self.ignore, + self.ignore_init_read_errors) + + db_ctl.remove(overlay, path) + + def select(self, overlay): ''' Select an overlay from the list. |