Login | Register
My pages Projects Community openCollabNet

Discussions > commits > svn commit: r266 - trunk/current/db: . mysql pysqlite

Project highlights: Stable Version: 1.6.1, Development Version: 1.7.6

current
Discussion topic

Back to topic list

svn commit: r266 - trunk/current/db: . mysql pysqlite

Reply

Author jjneely
Full name Jack Neely
Date 2006-08-27 11:29:20 PDT
Message Author: jjneely
Date: 2006-08-27 11:29:20-0700
New Revision: 266

Modified:
   trunk/current/db/currentdb.py
   trunk/current/db/mys​ql/schema.py
   trunk/current/db/profile.py
   trunk/current/db/pys​qlite/schema.py

Log:
>From Pauline:

Attached a patch which adds NVRE to PACKAGE, and only a package_id
to INSTALLED.

You will note a bit of code duplication regarding currentdb._getPackageId()
and currentdb._insertPackage() vs profiledb/_xxx(). I'm not sure how
to handle this neatly. Except by making them public in currentdb
and using them from profile, but that would entail getting an object
for it etc etc. Not fun. Enfin, just a proof of concept, you as
the architect may make the diffcult decisions :)


Modified: trunk/current/db/currentdb.py
Url: http://current.tigri​s.org/source/browse/​current/trunk/curren​t/db/currentdb.py?vi​ew=diff&rev=266​&p1=trunk/current​/db/currentdb.py​&p2=trunk/current/db​/currentdb.py&r1​=265&r2=266
====================​====================​====================​==================
--- trunk/current/db/currentdb.py (original)
+++ trunk/current/db/currentdb.py 2006-08-27 11:29:20-0700
@@ -273,18 +273,20 @@
                                    where rpm_id = %s""",
                                 (rpm_id,))
             
- self.cursor.execute("""select count(*) from RPM where
- package_id = %s""", (package_id,))
- r = self.cursor.fetchone()
+ self.cursor.execute("""select count(*) from RPM
+ where package_id = %s
+ union all
+ select count(*) from INSTALLED
+ where package_id = %s""",
+ (package_id,package_id))
+ r = self.cursor.fetchall()
+ count = r[0][0] + r[1][0]
             log("Num of RPMs with package_id=%s: %s" % (package_id,
- str(r)), DEBUG2)
- if r[0] == 0:
- # We know there are no more refferences to this PACKAGE
+ count), DEBUG2)
+ if count == 0:
+ # We know there are no more references to this PACKAGE
                 self.cursor.execute("""delete from PACKAGE where
                                        package_id = %s""", (package_id,))
- # (PM2006) And remove the reference from INSTALLED
- self.cursor.execute("""update INSTALLED set package_id=NULL
- where package_id = %s""", (package_id,))
             
             # Now the fun part...detect possibly stale channels
             self.cursor.execute("""select distinct CHANNEL.label from
@@ -395,11 +397,9 @@
                                        epoch, str(issource)))
 
         r = resultSet(self.cursor)
- try:
- return r['package_id']
- except IndexError, e:
- # No results returned
+ if r.rowcount() == 0:
             return None
+ return r['package_id']
 
 
     def _insertPackageTable(self, header):
@@ -420,15 +420,6 @@
                                             header[RPM.SOURCEPACKAGE])
             if not package_id:
                 log("Inserted package but could not lookup package_id", VERBOSE)
-
- else:
- # (PM2006) if it's a binary rpm, check if a system has it installed
- if header[RPM.SOURCEPACKAGE] == 0:
- self.cursor.execute('''update INSTALLED set package_id = %s
- where name = %s and version = %s and INSTALLED.release = %s
- and epoch = %s''', (package_id,
- header[RPM.NAME], header[RPM.VERSION],
- header[RPM.RELEASE], header[RPM.EPOCH]))
 
         return package_id
 

Modified: trunk/current/db/mys​ql/schema.py
Url: http://current.tigri​s.org/source/browse/​current/trunk/curren​t/db/mysql/schema.py​?view=diff&rev=2​66&p1=trunk/curr​ent/db/mysql/schema.​py&p2=trunk/curr​ent/db/mysql/schema.​py&r1=265&r2​=266
====================​====================​====================​==================
--- trunk/current/db/mys​ql/schema.py (original)
+++ trunk/current/db/mys​ql/schema.py 2006-08-27 11:29:20-0700
@@ -158,12 +158,8 @@
 create table INSTALLED (
     installed_id INTEGER PRIMARY KEY auto_increment,
     profile_id int not null,
- package_id int,
+ package_id int not null,
     info int(1) not null default '0',
- name varchar(64) not null,
- version varchar(64) not null,
- release varchar(64) not null,
- epoch varchar(8) not null,
 
     index(package_id),
     index(profile_id)

Modified: trunk/current/db/profile.py
Url: http://current.tigri​s.org/source/browse/​current/trunk/curren​t/db/profile.py?view​=diff&rev=266​&p1=trunk/current/d​b/profile.py&p2=​trunk/current/db/pro​file.py&r1=265​&r2=266
====================​====================​====================​==================
--- trunk/current/db/profile.py (original)
+++ trunk/current/db/profile.py 2006-08-27 11:29:20-0700
@@ -199,14 +199,48 @@
         
         return r['channel_id']
 
+
+ def _getPackageId(self, name, version, release, epoch, issource):
+ #logfunc(locals(), TRACE)
+ self.cursor.execute(''' select package_id from PACKAGE
+ where name = %s
+ and version = %s
+ and PACKAGE.release = %s
+ and epoch = %s
+ and issource = %s''', (name, version, release,
+ epoch, issource))
+
+ r = resultSet(self.cursor)
+ if r.rowcount() == 0:
+ return None
+ return r['package_id']
+
+ def _insertPackage(self, name, version, release, epoch, issource):
+ package_id = self._getPackageId(name, version, release,
+ epoch, issource)
+ if not package_id:
+ self.cursor.execute('''insert into PACKAGE
+ (name, version, release, epoch, issource)
+ values (%s, %s, %s, %s, %s)''',
+ (name, version, release, epoch, issource))
+ # PM2006, we really should be using last_insert_id
+ # (maybe make it a general connection method even)
+ package_id = self._getPackageId(name, version, release,
+ epoch, issource)
+ if not package_id:
+ log("Inserted package but could not lookup package_id", VERBOSE)
+
+ return package_id
+
     def addInstalledPackages(self, pid, package_list):
         """Add a list of packages to the profile."""
 
         for (name,version,release,epoch) in package_list:
- q = """insert into INSTALLED (profile_id,
- name, version, release, epoch) values
- (%s, %s, %s, %s, %s)"""
- self.cursor.execute(q, (pid, name, version, release, epoch))
+ package_id = self._insertPackage(​name,version,release​,epoch,0)
+ if package_id:
+ q = """insert into INSTALLED (profile_id, package_id)
+ values (%s, %s)"""
+ self.cursor.execute(q, (pid, package_id))
 
         self._updateInstalle​dPackages(pid)
         self.conn.commit()
@@ -214,19 +248,41 @@
     def deleteInstalledPackages(self, pid, package_list):
         """Remove a list of packages from the profile."""
 
- if package_list == None:
- q = """delete from INSTALLED where profile_id = %s"""
- self.cursor.execute(q, (pid))
- else:
- for pkg in package_list:
- (name,version,release,epoch) = pkg
- q = """delete from INSTALLED where profile_id = %s and
- name = %s and version = %s and INSTALLED.release = %s
- and epoch = %s"""
- self.cursor.execute(q, (pid, name, version, release, epoch))
+ pkgs = [];
+ if not package_list:
+ self.cursor.execute('''select package_id from INSTALLED
+ where profile_id = %s''',
+ (pid,))
+ for p in self.cursor.fetchall():
+ pkgs.append(p[0])
 
- self._updateInstalle​dPackages(pid)
+ self.cursor.execute('''delete from INSTALLED where
+ profile_id = %s''', (pid,))
+ else:
+ for (name,version,release,epoch) in package_list:
+ package_id = self._getPackageId(n​ame,version,release,​epoch,0)
+ if package_id:
+ self.cursor.execute('''delete from INSTALLED where
+ profile_id = %s and package_id = %s''',
+ (pid, package_id))
+ pkgs.append(package_id)
+
+ for (pkg) in pkgs:
+ self.cursor.execute('''select count(*) from RPM
+ where package_id = %s
+ union all
+ select count(*) from INSTALLED
+ where package_id = %s''',
+ (pkg,pkg))
+ r = self.cursor.fetchall()
+ count = r[0][0] + r[1][0]
+# log("Num of RPMs with package_id=%s: %s" % (pkg, count), DEBUG2)
+ if count == 0:
+ # We know there are no more references to this PACKAGE
+ self.cursor.execute('''delete from PACKAGE where
+ package_id = %s''', (pkg,))
 
+ self._updateInstalle​dPackages(pid)
         self.conn.commit()
 
     def updateAllInstallPackages(self):
@@ -252,36 +308,6 @@
            only the nvre tuples a profile is subscribed to and the
            tuples it has installed. (appr. 2x1500 for a full install)"""
 
- # Q: do we still need to generate the package_id information?
- # It seems to me the newly added info field tells us already
- # if the package is something we have to deal with. The reference
- # to the internal package_id seems superflucios.
-# log('Starting calculations for INSTALLED.package_id',DEBUG)
-#
-# # Build a list of all INSTALLED package_id's which need to be changed
-# self.cursor.execute("""select installed_id,PACKAGE.package_id
-# from SUBSCRIPTIONS
-# inner join CHANNEL_RPM using(channel_id)
-# inner join RPM using(rpm_id)
-# inner join PACKAGE using(package_id),
-# INSTALLED
-# where SUBSCRIPTIONS.profile_id = %s and
-# PACKAGE.name = INSTALLED.name and
-# PACKAGE.version = INSTALLED.version and
-# PACKAGE.release = INSTALLED.release and
-# PACKAGE.epoch = INSTALLED.epoch and
-# INSTALLED.profile_id = SUBSCRIPTIONS.profile_id and
-# not (PACKAGE.package_id <=> INSTALLED.package_id)
-# """, (pid,))
-#
-# log('Doing the update thing',DEBUG)
-#
-# # iterate over them and change INSTALLED.package_id
-# for (id,pkg) in list(self.cursor.fetchall()):
-# log("updating %s.package to %s" % (id,pkg), DEBUG)
-# self.cursor.execute("""update INSTALLED set package_id = %s
-# where installed_id = %s""", (pkg,id))
-
         log('Starting calculations for INSTALLED.info for profile %s' % \
             pid, DEBUG)
 
@@ -298,10 +324,11 @@
         query = list(self.cursor.fetchall())
 
         # get a list of all INSTALLED packages for this profile
- self.cursor.execute('''select INSTALLED.name, INSTALLED.version,
- INSTALLED.release, INSTALLED.epoch,
- INSTALLED.installed_id
+ self.cursor.execute('''select PACKAGE.name, PACKAGE.version,
+ PACKAGE.release, PACKAGE.epoch,
+ installed_id
                                from INSTALLED
+ inner join PACKAGE using (package_id)
                                where INSTALLED.profile_id = %s''',
                             (pid,))
         query.extend(list(se​lf.cursor.fetchall()​))

Modified: trunk/current/db/pys​qlite/schema.py
Url: http://current.tigri​s.org/source/browse/​current/trunk/curren​t/db/pysqlite/schema​.py?view=diff&re​v=266&p1=trunk/c​urrent/db/pysqlite/s​chema.py&p2=trun​k/current/db/pysqlit​e/schema.py&r1=2​65&r2=266
====================​====================​====================​==================
--- trunk/current/db/pys​qlite/schema.py (original)
+++ trunk/current/db/pys​qlite/schema.py 2006-08-27 11:29:20-0700
@@ -132,12 +132,8 @@
 create table INSTALLED (
     installed_id INTEGER PRIMARY KEY,
     profile_id int not null,
- package_id int,
- info int,
- name varchar(64) not null,
- version varchar(64) not null,
- release varchar(64) not null,
- epoch varchar(8) not null
+ package_id int not null,
+ info int not null,
 );
 create index INSTALLED_PACKAGE_IDX on INSTALLED(package_id);
 create index INSTALLED_PROFILE_IDX on INSTALLED(profile_id);

« Previous message in topic | 1 of 1 | Next message in topic »

Messages

Show all messages in topic

svn commit: r266 - trunk/current/db: . mysql pysqlite jjneely Jack Neely 2006-08-27 11:29:20 PDT
Messages per page: