[gentoo-commits] proj/layman:master commit in: layman/db_modules/xml_db/, layman/db_modules/sqlite_db/, layman/, ...

2016-02-28 Thread Devan Franchini
commit: f8eb545aa0b268cfd08644b0996a6681359dc0bc
Author: Devan Franchini  gentoo  org>
AuthorDate: Mon Feb 29 06:09:27 2016 +
Commit: Devan Franchini  gentoo  org>
CommitDate: Mon Feb 29 06:09:29 2016 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=f8eb545a

Adds error reporting for db read failures

If the database back-end fails to be read then layman will properly
report it and exit without causing an ugly traceback.

 layman/db_modules/json_db/json_db.py |   7 +-
 layman/db_modules/sqlite_db/sqlite_db.py | 121 +--
 layman/db_modules/xml_db/xml_db.py   |  21 --
 layman/dbbase.py |  12 ++-
 4 files changed, 95 insertions(+), 66 deletions(-)

diff --git a/layman/db_modules/json_db/json_db.py 
b/layman/db_modules/json_db/json_db.py
index 70e41d5..bf88593 100644
--- a/layman/db_modules/json_db/json_db.py
+++ b/layman/db_modules/json_db/json_db.py
@@ -75,6 +75,10 @@ class DBHandler(object):
 try:
 with fileopen(path, 'r') as df:
 document = df.read()
+except ValueError as error:
+msg = 'JSON DBHanlder - ValueError: %(err)s' % {'err': error}
+self.output.error(msg)
+return False
 except Exception as error:
 if not self.ignore_init_read_errors:
 msg = 'JSON DBHandler - Failed to read the overlay list 
at'\
@@ -82,7 +86,8 @@ class DBHandler(object):
 self.output.error(msg)
 raise error
 
-self.add_new(document, origin=path)
+success = self.add_new(document, origin=path)
+return success
 
 
 def add_new(self, document=None, origin=None):

diff --git a/layman/db_modules/sqlite_db/sqlite_db.py 
b/layman/db_modules/sqlite_db/sqlite_db.py
index a3305a7..3585c4a 100644
--- a/layman/db_modules/sqlite_db/sqlite_db.py
+++ b/layman/db_modules/sqlite_db/sqlite_db.py
@@ -136,6 +136,8 @@ class DBHandler(object):
 CONFLICT IGNORE )''')
 
 connection.commit()
+except sqlite3.DatabaseError as err:
+raise err
 except Exception as err:
 msg = 'SQLite DBHandler error; failed to create database.\n'\
   'Error was: %(msg)s' % {'msg': err}
@@ -152,64 +154,71 @@ class DBHandler(object):
 overlay_id = None
 overlay = {}
 
-with self.__connect__(path) as connection:
-cursor = connection.cursor()
-cursor.execute('''SELECT Overlay_ID, Name, Priority, Status, 
-Quality, Homepage, IRC, License FROM Overlay''')
-overlays_info = cursor.fetchall()
-connection.commit()
+try:
+connection = self.__connect__(path)
+except sqlite3.DatabaseError as err:
+msg = 'SQLite DBHandler DatabaseError: %(err)s' % {'err': err}
+self.output.error(msg)
+return False
 
-for overlay_info in overlays_info:
-overlay = {}
-overlay_id = overlay_info[0]
-overlay['name'] = overlay_info[1]
-
-cursor.execute('''SELECT URL, Type, Branch FROM Overlay_Source 
-JOIN Overlay USING (Overlay_ID) JOIN Source USING (Source_ID) 
-WHERE Overlay_ID = ?''', (overlay_id,))
-overlay['source'] = cursor.fetchall()
-
-cursor.execute('''SELECT Owner_Email, Owner_Name FROM 
-Overlay_Owner JOIN Overlay USING (Overlay_ID) JOIN Owner USING 
-(Owner_ID) WHERE Overlay_ID = ?''', (overlay_id,))
-owner_info = cursor.fetchall()
-overlay['owner'] = []
-
-for _owner in owner_info:
-owner = {}
-if _owner[0]:
-owner['email'] = _owner[0]
+cursor = connection.cursor()
+cursor.execute('''SELECT Overlay_ID, Name, Priority, Status,
+Quality, Homepage, IRC, License FROM Overlay''')
+overlays_info = cursor.fetchall()
+connection.commit()
+
+for overlay_info in overlays_info:
+overlay = {}
+overlay_id = overlay_info[0]
+overlay['name'] = overlay_info[1]
+
+cursor.execute('''SELECT URL, Type, Branch FROM Overlay_Source
+JOIN Overlay USING (Overlay_ID) JOIN Source USING (Source_ID)
+WHERE Overlay_ID = ?''', (overlay_id,))
+overlay['source'] = cursor.fetchall()
+
+cursor.execute('''SELECT Owner_Email, Owner_Name FROM Overlay_Owner
+JOIN Overlay USING (Overlay_ID) JOIN Owner USING (Owner_ID)
+WHERE Overlay_ID = ?''', (overlay_id,))
+owner_info = cursor.fetchall()
+overlay['owner'] = []
+for _owner in owner_info:
+owner = {}
+if _owner[0]:

[gentoo-commits] proj/layman:master commit in: layman/db_modules/xml_db/, layman/db_modules/sqlite_db/, layman/, ...

2015-08-05 Thread Devan Franchini
commit: daafd7d31457b018797407d97188a4829839172e
Author: Devan Franchini twitch153 AT gentoo DOT org
AuthorDate: Wed Aug  5 05:55:16 2015 +
Commit: Devan Franchini twitch153 AT gentoo DOT org
CommitDate: Wed Aug  5 05:58:59 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=daafd7d3

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.

 layman/db.py |  2 +-
 layman/db_modules/json_db/__init__.py|  3 ++-
 layman/db_modules/json_db/json_db.py |  8 
 layman/db_modules/sqlite_db/__init__.py  |  5 +++--
 layman/db_modules/sqlite_db/sqlite_db.py | 23 ---
 layman/db_modules/xml_db/__init__.py |  3 ++-
 layman/db_modules/xml_db/xml_db.py   |  8 
 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) 

[gentoo-commits] proj/layman:master commit in: layman/db_modules/xml_db/

2015-07-13 Thread Devan Franchini
commit: 4c08c57f337abba1f6f4fe678bfa2a0cab569b7a
Author: Devan Franchini twitch153 AT gentoo DOT org
AuthorDate: Mon Jul 13 13:33:00 2015 +
Commit: Devan Franchini twitch153 AT gentoo DOT org
CommitDate: Mon Jul 13 13:33:02 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=4c08c57f

xml_db.py: Removes unnecessary __eq__ and __ne__ functions

These functions are in the DbBase class and will continue to be used
in that class. As such there's no need for any DBHandler class to
include them in their code.

 layman/db_modules/xml_db/xml_db.py | 11 ---
 1 file changed, 11 deletions(-)

diff --git a/layman/db_modules/xml_db/xml_db.py 
b/layman/db_modules/xml_db/xml_db.py
index 6348162..38a19d2 100644
--- a/layman/db_modules/xml_db/xml_db.py
+++ b/layman/db_modules/xml_db/xml_db.py
@@ -86,17 +86,6 @@ class DBHandler(object):
 self.output.debug('Initializing XML overlay list handler', 8)
 
 
-def __eq__(self, other):
-for key in set(self.overlays.keys()) | set(other.overlays.keys()):
-if self.overlays[key] != other.overlays[key]:
-return False
-return True
-
-
-def __ne__(self, other):
-return not self.__eq__(other)
-
-
 def _broken_catalog_hint(self):
 this_function_name = sys._getframe().f_code.co_name
 



[gentoo-commits] proj/layman:master commit in: layman/db_modules/xml_db/

2015-07-13 Thread Devan Franchini
commit: 0bd7450c52401be9b0c9c9ad8fb2e9eff5760e1b
Author: Devan Franchini twitch153 AT gentoo DOT org
AuthorDate: Mon Jul 13 18:48:41 2015 +
Commit: Devan Franchini twitch153 AT gentoo DOT org
CommitDate: Mon Jul 13 18:48:41 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=0bd7450c

xml_db/__init__.py: Modifies function descriptions

 layman/db_modules/xml_db/__init__.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/layman/db_modules/xml_db/__init__.py 
b/layman/db_modules/xml_db/__init__.py
index ad6506c..3a3abd1 100644
--- a/layman/db_modules/xml_db/__init__.py
+++ b/layman/db_modules/xml_db/__init__.py
@@ -15,9 +15,9 @@ module_spec = {
 'description': __doc__,
 'functions': ['add_new', 'read_db', 'write'],
 'func_desc': {
-'add_new': 'Adds new overlay(s) to database',
-'read_db': 'Reads the list of registered overlays from config',
-'write'  : 'Writes the list of registered overlay to config',
+'add_new': 'Adds overlay(s) from provided database text',
+'read_db': 'Reads the list of overlays from database file',
+'write'  : 'Writes the list of overlays to database file',
 },
 }
 }



[gentoo-commits] proj/layman:master commit in: layman/db_modules/xml_db/, etc/, layman/db_modules/xml/, layman/tests/, layman/

2015-07-10 Thread Devan Franchini
commit: b32d76e2e155d2298555c9a2941517bc007ea55b
Author: Devan Franchini twitch153 AT gentoo DOT org
AuthorDate: Fri Jul 10 13:46:49 2015 +
Commit: Devan Franchini twitch153 AT gentoo DOT org
CommitDate: Fri Jul 10 13:46:53 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=b32d76e2

Renames db module xml to xml_db

This prevents namespace collisions with the required xml class.

 etc/layman.cfg |  2 +-
 layman/config.py   |  2 +-
 layman/db_modules/{xml = xml_db}/__init__.py  |  4 ++--
 layman/db_modules/{xml/xml.py = xml_db/xml_db.py} |  4 ++--
 layman/tests/external.py   | 10 +-
 5 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/etc/layman.cfg b/etc/layman.cfg
index 76f5f46..45fe3fc 100644
--- a/etc/layman.cfg
+++ b/etc/layman.cfg
@@ -69,7 +69,7 @@ conf_type : repos.conf
 #---
 # Database types used by layman
 # For now, only xml.
-#db_type : xml
+#db_type : xml_db
 
 #---
 

diff --git a/layman/config.py b/layman/config.py
index 853e22f..0ad975b 100644
--- a/layman/config.py
+++ b/layman/config.py
@@ -100,7 +100,7 @@ class BareConfig(object):
 'auto_sync': 'No',
 'check_official': 'Yes',
 'conf_type': 'repos.conf',
-'db_type': 'xml',
+'db_type': 'xml_db',
 'require_repoconfig': 'Yes',
 'clean_archive': 'yes',
 'make_conf' : '%(storage)s/make.conf',

diff --git a/layman/db_modules/xml/__init__.py 
b/layman/db_modules/xml_db/__init__.py
similarity index 92%
rename from layman/db_modules/xml/__init__.py
rename to layman/db_modules/xml_db/__init__.py
index 96861d7..ad6506c 100644
--- a/layman/db_modules/xml/__init__.py
+++ b/layman/db_modules/xml_db/__init__.py
@@ -6,11 +6,11 @@ XML database plug-in module for layman.
 '''
 
 module_spec = {
-'name': 'xml',
+'name': 'xml_db',
 'description': __doc__,
 'provides':{
 'xml-module': {
-'name': 'xml',
+'name': 'xml_db',
 'class': 'DBHandler',
 'description': __doc__,
 'functions': ['add_new', 'read_db', 'write'],

diff --git a/layman/db_modules/xml/xml.py b/layman/db_modules/xml_db/xml_db.py
similarity index 98%
rename from layman/db_modules/xml/xml.py
rename to layman/db_modules/xml_db/xml_db.py
index c444fc3..6348162 100644
--- a/layman/db_modules/xml/xml.py
+++ b/layman/db_modules/xml_db/xml_db.py
@@ -3,7 +3,7 @@
 
#
 # LAYMAN XML DB
 
#
-# File:   xml.py
+# File:   xml_db.py
 #
 # Access XML overlay database(s).
 #
@@ -18,7 +18,7 @@
 
 from __future__ import unicode_literals
 
-__version__ = $Id: xml.py 273 2015-07-07 10:30:30Z twitch153 $
+__version__ = $Id: xml_db.py 273 2015-07-07 10:30:30Z twitch153 $
 
 
#===
 #

diff --git a/layman/tests/external.py b/layman/tests/external.py
index e2a44b0..0dad278 100755
--- a/layman/tests/external.py
+++ b/layman/tests/external.py
@@ -637,7 +637,7 @@ class ReadWriteSelectListDbBase(unittest.TestCase):
 output = Message()
 config = {
   'output': output,
-  'db_type': 'xml',
+  'db_type': 'xml_db',
   'svn_command': '/usr/bin/svn',
   'rsync_command':'/usr/bin/rsync'
  }
@@ -672,7 +672,7 @@ class ReadWriteSelectListDbBase(unittest.TestCase):
 def read_db(self):
 output = Message()
 config = {'output': output,
-  'db_type': 'xml',}
+  'db_type': 'xml_db',}
 db = DbBase(config, [HERE + '/testfiles/global-overlays.xml', ])
 keys = sorted(db.overlays)
 self.assertEqual(keys, ['wrobel', 'wrobel-stable'])
@@ -684,7 +684,7 @@ class ReadWriteSelectListDbBase(unittest.TestCase):
 def select_db(self):
 output = Message()
 config = {'output': output,
-  'db_type': 'xml',}
+  'db_type': 'xml_db',}
 db = DbBase(config, [HERE + '/testfiles/global-overlays.xml', ])
 url = ['rsync://gunnarwrobel.de/wrobel-stable']
 self.assertEqual(list(db.select('wrobel-stable').source_uris()), url)
@@ -696,12 +696,12 @@ class ReadWriteSelectListDbBase(unittest.TestCase):
 config = BareConfig()
 
 a = DbBase(config, [HERE + '/testfiles/global-overlays.xml', ])
-b = DbBase({'output': Message(), 'db_type': 'xml'}, [test_xml,])
+b = DbBase({'output': Message(), 'db_type': 'xml_db'}, [test_xml,])
 
 b.overlays['wrobel-stable'] = a.overlays['wrobel-stable']