summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDevan Franchini <twitch153@gentoo.org>2015-08-27 20:36:37 -0400
committerDevan Franchini <twitch153@gentoo.org>2015-08-27 20:36:40 -0400
commit03f39c1a46149d472797e4adb6654705579c412c (patch)
treeb2336e1711886a28d707a15eef7725b8a5080ebf
parentoverlay.py: Improves to_json() setting of descriptions (diff)
downloadlayman-03f39c1a46149d472797e4adb6654705579c412c.tar.gz
layman-03f39c1a46149d472797e4adb6654705579c412c.tar.bz2
layman-03f39c1a46149d472797e4adb6654705579c412c.zip
Adds multiple owner support to layman overlays
-rw-r--r--layman/db_modules/sqlite_db/sqlite_db.py69
-rwxr-xr-xlayman/overlays/overlay.py164
2 files changed, 137 insertions, 96 deletions
diff --git a/layman/db_modules/sqlite_db/sqlite_db.py b/layman/db_modules/sqlite_db/sqlite_db.py
index 22ae5f3..a3305a7 100644
--- a/layman/db_modules/sqlite_db/sqlite_db.py
+++ b/layman/db_modules/sqlite_db/sqlite_db.py
@@ -172,12 +172,21 @@ class DBHandler(object):
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()[0]
-
- overlay['owner_email'] = owner_info[0]
-
- if len(owner_info) > 1:
- overlay['owner_name'] = owner_info[1]
+ owner_info = cursor.fetchall()
+ overlay['owner'] = []
+
+ for _owner in owner_info:
+ owner = {}
+ if _owner[0]:
+ owner['email'] = _owner[0]
+ else:
+ owner['email'] = None
+ if len(_owner) > 1:
+ if _owner[1]:
+ owner['name'] = _owner[1]
+ else:
+ owner['name'] = None
+ overlay['owner'].append(owner)
cursor.execute('''SELECT Description FROM Description JOIN
Overlay USING (Overlay_ID) WHERE Overlay_ID = ?''',
@@ -225,7 +234,7 @@ class DBHandler(object):
'''
overlay_id = None
owner_id = None
- source_ids = []
+ source_id = None
cursor = None
cursor = connection.cursor()
@@ -239,22 +248,37 @@ class DBHandler(object):
(overlay.name,))
overlay_id = cursor.fetchone()[0]
- cursor.execute('''INSERT INTO Owner ( Owner_Name, Owner_Email )
- VALUES ( ?, ? )''', (overlay.owner_name, overlay.owner_email,))
- connection.commit()
+ for owner in overlay.owners:
+ _name = owner['name']
+ _email = owner['email']
+
+ cursor.execute('''INSERT INTO Owner ( Owner_Name, Owner_Email )
+ VALUES ( ?, ? )''', (owner['name'], owner['email'],))
+ connection.commit()
+
+ if _name != None:
+ cursor.execute('''SELECT Owner_ID from Owner WHERE
+ Owner_Email = ? AND Owner_Name = ?''', (_email, _name,))
+ else:
+ cursor.execute('''SELECT Owner_ID from Owner WHERE
+ Owner_Email = ?''', (_email,))
+ owner_id = cursor.fetchone()[0]
- cursor.execute('''SELECT Owner_ID from Owner WHERE Owner_Email = ?;''',
- (overlay.owner_email,))
- owner_id = cursor.fetchone()[0]
+ cursor.execute('''INSERT INTO Overlay_Owner ( Overlay_ID,
+ Owner_ID ) VALUES ( ?, ? )''', (overlay_id, owner_id,))
for source in overlay.sources:
cursor.execute('''INSERT INTO Source ( Type, Branch, URL )
VALUES ( ?, ?, ? )''', (source.type_key, source.branch,
source.src,))
connection.commit()
+
cursor.execute('''SELECT Source_ID FROM Source WHERE URL = ?;''',
(source.src,))
- source_ids.append(cursor.fetchone()[0])
+ source_id = cursor.fetchone()[0]
+
+ cursor.execute('''INSERT INTO Overlay_Source ( Overlay_ID,
+ Source_ID ) VALUES ( ?, ? )''', (overlay_id, source_id, ))
for description in overlay.descriptions:
cursor.execute('''INSERT INTO Description ( Overlay_ID,
@@ -264,13 +288,6 @@ class DBHandler(object):
cursor.execute('''INSERT INTO Feed ( Overlay_ID, Feed ) VALUES ( ?,
? )''', (overlay_id, feed,))
- cursor.execute('''INSERT INTO Overlay_Owner ( Overlay_ID, Owner_ID )
- VALUES ( ?, ? )''', (overlay_id, owner_id,))
-
- for source_id in source_ids:
- cursor.execute('''INSERT INTO Overlay_Source ( Overlay_ID,
- Source_ID ) VALUES ( ?, ? )''', (overlay_id, source_id,))
-
connection.commit()
@@ -280,7 +297,7 @@ class DBHandler(object):
'''
cursor = None
overlay_id = 0
- owner_id = 0
+ owner_ids = []
source_ids = []
if overlay.name in self.overlays:
@@ -295,7 +312,7 @@ class DBHandler(object):
cursor.execute('''SELECT Owner_ID FROM Overlay_Owner WHERE
Overlay_ID = ?''', (overlay_id,))
- owner_id = cursor.fetchone()[0]
+ owner_ids = cursor.fetchall()[0]
cursor.execute('''SELECT Source_ID FROM Overlay_Source WHERE
Overlay_ID = ?''', (overlay_id,))
@@ -314,8 +331,10 @@ class DBHandler(object):
cursor.execute('''DELETE FROM Source WHERE Source_ID = ?''',
(source_id,))
- cursor.execute('''DELETE FROM Owner WHERE Owner_ID = ?''',
- (owner_id,))
+ for owner_id in owner_ids:
+ cursor.execute('''DELETE FROM Owner WHERE Owner_ID = ?''',
+ (owner_id,))
+
cursor.execute('''DELETE FROM Overlay WHERE Overlay_ID = ?''',
(overlay_id,))
diff --git a/layman/overlays/overlay.py b/layman/overlays/overlay.py
index defa4e3..11536d4 100755
--- a/layman/overlays/overlay.py
+++ b/layman/overlays/overlay.py
@@ -191,23 +191,28 @@ class Overlay(object):
self.sources = [create_dict_overlay_source(e) for e in _sources]
- if 'owner_name' in overlay:
- _owner = overlay['owner_name']
- self.owner_name = encode(_owner)
- else:
- self.owner_name = None
-
- if 'owner_email' in overlay:
- _email = overlay['owner_email']
- self.owner_email = encode(_email)
- else:
- self.owner_email = None
- msg = 'Overlay from_dict(), "%(name)s" is missing an "owner.email"'\
- ' entry!' % {'name': self.name}
- if not ignore:
- raise Exception(msg)
- elif ignore == 1:
- self.output.warn(msg, 4)
+ self.owners = []
+
+ if 'owner' in overlay:
+ for _owner in overlay['owner']:
+ owner = {}
+ if 'name' in _owner and _owner['name']:
+ owner['name'] = encode(_owner['name'])
+ else:
+ owner['name'] = None
+
+ if 'email' in _owner:
+ owner['email'] = encode(_owner['email'])
+ else:
+ owner['email'] = None
+ msg = 'Overlay from_dict(), "%(name)s" is missing an '\
+ '"owner.email" entry!' % {'name': self.name}
+ if not ignore:
+ raise Exception(msg)
+ elif ignore == 1:
+ self.output.warn(msg, 4)
+
+ self.owners.append(owner)
if 'description' in overlay:
self.descriptions = []
@@ -313,21 +318,26 @@ class Overlay(object):
self.sources = [create_json_overlay_source(e) for e in _sources]
- if 'name' in json['owner']:
- self.owner_name = encode(json['owner']['name'])
- else:
- self.owner_name = None
+ _owners = json['owner']
+ self.owners = []
- if 'email' in json['owner']:
- self.owner_email = encode(json['owner']['email'])
- else:
- self.owner_email = None
- msg = 'Overlay from_json(), "%(name)s" is missing an "owner.email"'\
- 'entry!' % {'name': self.name}
- if not ignore:
- raise Exception(msg)
- elif ignore == 1:
- self.output.warn(msg, 4)
+ for _owner in _owners:
+ owner = {}
+ if 'name' in _owner:
+ owner['name'] = encode(_owner['name'])
+ else:
+ owner['name'] = None
+ if 'email' in _owner:
+ owner['email'] = encode(_owner['email'])
+ else:
+ owner['email'] = None
+ msg = 'Overlay from_json(), "%(name)s" is missing an '\
+ '"owner.email" entry!' % {'name': self.name}
+ if not ignore:
+ raise Exception(msg)
+ elif ignore == 1:
+ self.output.warn(msg, 4)
+ self.owners.append(owner)
if 'description' in json:
self.descriptions = []
@@ -441,32 +451,35 @@ class Overlay(object):
self.sources = [create_overlay_source(e) for e in _sources]
- _owner = xml.find('owner')
+ _owners = xml.findall('owner')
+ self.owners = []
- if _owner == None:
- _email = None
- else:
- _email = _owner.find('email')
+ for _owner in _owners:
+ owner = {}
- if _owner != None and _email != None:
- self.owner_email = encode(strip_text(_email))
+ _email = _owner.find('email')
_name = _owner.find('name')
+
if _name != None:
- self.owner_name = encode(strip_text(_name))
+ owner['name'] = encode(strip_text(_name))
else:
- self.owner_name = None
- elif 'contact' in xml.attrib:
- self.owner_email = encode(xml.attrib['contact'])
- self.owner_name = None
- else:
- self.owner_email = ''
- self.owner_name = None
- msg = 'Overlay from_xml(), "%(name)s" is mising an '\
- '"owner.email" entry!' % {'name': self.name}
- if not ignore:
- raise Exception(msg)
- elif ignore == 1:
- self.output.warn(msg, 4)
+ owner['name'] = None
+ if _email != None:
+ owner['email'] = encode(strip_text(_email))
+ else:
+ owner['email'] = None
+ msg = 'Overlay from_xml(), "%(name)s" is missing an '\
+ '"owner.email" entry!' % {'name': self.name}
+ if not ignore:
+ raise Exception(msg)
+ elif ignore == 1:
+ self.output.warn(msg, 4)
+
+ # For backwards compatibility with older Overlay XML formats.
+ if not _email and not _name and 'contact' in xml.attrib:
+ owner['email'] = encode(xml.attrib['contact'])
+ owner['name'] = None
+ self.owners.append(owner)
_desc = xml.findall('description')
if _desc != None:
@@ -536,16 +549,27 @@ class Overlay(object):
if len(self.sources) == 1:
result += '\nSource : ' + self.sources[0].src
else:
- result += '\nSources:'
+ result += '\nSources : '
for i, v in enumerate(self.sources):
result += '\n %d. %s' % (i + 1, v.src)
result += '\n'
- if self.owner_name != None:
- result += '\nContact : %s <%s>' \
- % (self.owner_name, self.owner_email)
- else:
- result += '\nContact : ' + self.owner_email
+ if len(self.owners) == 1:
+ if 'name' in self.owners[0] and self.owners[0]['name'] != None:
+ result += '\nContact : %s <%s>' \
+ % (self.owners[0]['name'], self.owners[0]['email'])
+ else:
+ result += '\nContact : ' + self.owners[0]['email']
+ else:
+ result += '\nContacts: '
+ for i, v in enumerate(self.owners):
+ result += '\n %d. ' % (i + 1)
+ if 'name' in v and v['name'] != None:
+ result += '%s <%s>' % (v['name'], v['email'])
+ else:
+ result += v['email']
+ result += '\n'
+
if len(self.sources) == 1:
result += '\nType : ' + self.sources[0].type
else:
@@ -666,10 +690,7 @@ class Overlay(object):
repo['homepage'] = self.homepage
if self.irc != None:
repo['irc'] = self.irc
- repo['owner'] = {}
- repo['owner']['email'] = self.owner_email
- if self.owner_name != None:
- repo['owner']['name'] = self.owner_name
+ repo['owner'] = [i for i in self.owners]
repo['source'] = []
for i in self.sources:
source = {'@type': i.__class__.type_key}
@@ -712,15 +733,16 @@ class Overlay(object):
irc = ET.Element('irc')
irc.text = self.irc
repo.append(irc)
- owner = ET.Element('owner')
- repo.append(owner)
- owner_email = ET.Element('email')
- owner_email.text = self.owner_email
- owner.append(owner_email)
- if self.owner_name != None:
- owner_name = ET.Element('name')
- owner_name.text = self.owner_name
- owner.append(owner_name)
+ for _owner in self.owners:
+ owner = ET.Element('owner')
+ owner_email = ET.Element('email')
+ owner_email.text = _owner['email']
+ owner.append(owner_email)
+ if 'name' in _owner and _owner['name']:
+ owner_name = ET.Element('name')
+ owner_name.text = _owner['name']
+ owner.append(owner_name)
+ repo.append(owner)
for i in self.sources:
if not i.branch:
source = ET.Element('source', type=i.__class__.type_key)