* [gentoo-commits] proj/layman:master commit in: layman/db_modules/sqlite_db/
@ 2015-08-05 6:24 Devan Franchini
0 siblings, 0 replies; 2+ messages in thread
From: Devan Franchini @ 2015-08-05 6:24 UTC (permalink / raw
To: gentoo-commits
commit: 59ce97acb46ddef1b564ab4032c145ed70c92427
Author: Devan Franchini <twitch153 <AT> gentoo <DOT> org>
AuthorDate: Wed Aug 5 06:22:24 2015 +0000
Commit: Devan Franchini <twitch153 <AT> gentoo <DOT> org>
CommitDate: Wed Aug 5 06:22:31 2015 +0000
URL: https://gitweb.gentoo.org/proj/layman.git/commit/?id=59ce97ac
sqlite_db.py: read_db() connects to database with "with" command
layman/db_modules/sqlite_db/sqlite_db.py | 107 ++++++++++++++++---------------
1 file changed, 54 insertions(+), 53 deletions(-)
diff --git a/layman/db_modules/sqlite_db/sqlite_db.py b/layman/db_modules/sqlite_db/sqlite_db.py
index aef9661..14bfa25 100644
--- a/layman/db_modules/sqlite_db/sqlite_db.py
+++ b/layman/db_modules/sqlite_db/sqlite_db.py
@@ -148,63 +148,64 @@ class DBHandler(object):
'''
Read the overlay definitions from the database and generate overlays.
'''
- connection = self.__connect__(path)
- cursor = connection.cursor()
+ cursor = None
overlay_id = None
overlay = {}
- cursor.execute('''SELECT Overlay_ID, Name, Priority, Status, Quality,
- Homepage, IRC, License FROM Overlay''')
- overlays_info = cursor.fetchall()
- connection.commit()
+ 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()
- 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_Name, Owner_Email FROM
- Overlay_Owner JOIN Overlay USING (Overlay_ID) JOIN Owner USING
- (Owner_ID) WHERE Overlay_ID = ?''', (overlay_id,))
- owner_info = cursor.fetchall()
-
- if len(owner_info):
- owner_info = owner_info[0]
- overlay['owner_name'] = owner_info[0]
- overlay['owner_email'] = owner_info[1]
-
- cursor.execute('''SELECT Description FROM Description JOIN Overlay
- USING (Overlay_ID) WHERE Overlay_ID = ?''', (overlay_id,))
- overlay['description'] = cursor.fetchall()[0]
-
- overlay['status'] = overlay_info[3]
- overlay['quality'] = overlay_info[4]
- overlay['priority'] = overlay_info[2]
-
- if overlay_info[7]:
- overlay['license'] = overlay_info[7]
- else:
- overlay['license'] = None
-
- overlay['homepage'] = overlay_info[5]
- overlay['IRC'] = overlay_info[6]
-
- cursor.execute('''SELECT Feed FROM Feed JOIN Overlay USING
- (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()
+ 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_Name, Owner_Email FROM
+ Overlay_Owner JOIN Overlay USING (Overlay_ID) JOIN Owner USING
+ (Owner_ID) WHERE Overlay_ID = ?''', (overlay_id,))
+ owner_info = cursor.fetchall()
+
+ if len(owner_info):
+ owner_info = owner_info[0]
+ overlay['owner_name'] = owner_info[0]
+ overlay['owner_email'] = owner_info[1]
+
+ cursor.execute('''SELECT Description FROM Description JOIN
+ Overlay USING (Overlay_ID) WHERE Overlay_ID = ?''',
+ (overlay_id,))
+ overlay['description'] = cursor.fetchall()[0]
+
+ overlay['status'] = overlay_info[3]
+ overlay['quality'] = overlay_info[4]
+ overlay['priority'] = overlay_info[2]
+
+ if overlay_info[7]:
+ overlay['license'] = overlay_info[7]
+ else:
+ overlay['license'] = None
+
+ overlay['homepage'] = overlay_info[5]
+ overlay['IRC'] = overlay_info[6]
+
+ cursor.execute('''SELECT Feed FROM Feed JOIN Overlay USING
+ (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)
def add_new(self, document=None, origin=None):
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [gentoo-commits] proj/layman:master commit in: layman/db_modules/sqlite_db/
@ 2015-08-13 7:07 Devan Franchini
0 siblings, 0 replies; 2+ messages in thread
From: Devan Franchini @ 2015-08-13 7:07 UTC (permalink / raw
To: gentoo-commits
commit: 3e582a86a5389c5013fd0b8c5a6cc964d3252a2c
Author: Devan Franchini <twitch153 <AT> gentoo <DOT> org>
AuthorDate: Thu Aug 13 07:04:40 2015 +0000
Commit: Devan Franchini <twitch153 <AT> gentoo <DOT> org>
CommitDate: Thu Aug 13 07:04:44 2015 +0000
URL: https://gitweb.gentoo.org/proj/layman.git/commit/?id=3e582a86
sqlite_db.py: Modifies owner information gathering method
Due to the fact that including the owner name isn't necessary layman
needed to modify the way it gathered owner information to prevent
run-time errors.
layman/db_modules/sqlite_db/sqlite_db.py | 23 +++++++++--------------
1 file changed, 9 insertions(+), 14 deletions(-)
diff --git a/layman/db_modules/sqlite_db/sqlite_db.py b/layman/db_modules/sqlite_db/sqlite_db.py
index 14bfa25..6619699 100644
--- a/layman/db_modules/sqlite_db/sqlite_db.py
+++ b/layman/db_modules/sqlite_db/sqlite_db.py
@@ -169,15 +169,15 @@ class DBHandler(object):
WHERE Overlay_ID = ?''', (overlay_id,))
overlay['source'] = cursor.fetchall()
- cursor.execute('''SELECT Owner_Name, Owner_Email FROM
+ 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()
+ owner_info = cursor.fetchall()[0]
- if len(owner_info):
- owner_info = owner_info[0]
- overlay['owner_name'] = owner_info[0]
- overlay['owner_email'] = owner_info[1]
+ overlay['owner_email'] = owner_info[0]
+
+ if len(owner_info) > 1:
+ overlay['owner_name'] = owner_info[1]
cursor.execute('''SELECT Description FROM Description JOIN
Overlay USING (Overlay_ID) WHERE Overlay_ID = ?''',
@@ -187,12 +187,7 @@ class DBHandler(object):
overlay['status'] = overlay_info[3]
overlay['quality'] = overlay_info[4]
overlay['priority'] = overlay_info[2]
-
- if overlay_info[7]:
- overlay['license'] = overlay_info[7]
- else:
- overlay['license'] = None
-
+ overlay['license'] = overlay_info[7]
overlay['homepage'] = overlay_info[5]
overlay['IRC'] = overlay_info[6]
@@ -248,8 +243,8 @@ class DBHandler(object):
VALUES ( ?, ? )''', (overlay.owner_name, overlay.owner_email,))
connection.commit()
- cursor.execute('''SELECT Owner_ID from Owner WHERE Owner_Name = ?;''',
- (overlay.owner_name,))
+ cursor.execute('''SELECT Owner_ID from Owner WHERE Owner_Email = ?;''',
+ (overlay.owner_email,))
owner_id = cursor.fetchone()[0]
for source in overlay.sources:
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-08-13 7:07 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-08-05 6:24 [gentoo-commits] proj/layman:master commit in: layman/db_modules/sqlite_db/ Devan Franchini
-- strict thread matches above, loose matches on Subject: below --
2015-08-13 7:07 Devan Franchini
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox