- cursor = DBConn().cursor();
- cursor.execute( "BEGIN WORK" )
- cursor.execute( remove_pending_contents_cruft_q )
- cursor.execute( remove_filename_cruft_q )
- cursor.execute( remove_filepath_cruft_q )
- cursor.execute( "COMMIT" )
+ s = DBConn().session()
+
+ # clear out all of the temporarily stored content associations
+ # this should be run only after p-a has run. after a p-a
+ # run we should have either accepted or rejected every package
+ # so there should no longer be anything in the queue
+ s.query(PendingContentAssociation).delete()
+
+ # delete any filenames we are storing which have no binary associated
+ # with them
+ cafq = s.query(ContentAssociation.filename_id).distinct()
+ cfq = s.query(ContentFilename)
+ cfq = cfq.filter(~ContentFilename.cafilename_id.in_(cafq))
+ cfq.delete()
+
+ # delete any paths we are storing which have no binary associated with
+ # them
+ capq = s.query(ContentAssociation.filepath_id).distinct()
+ cpq = s.query(ContentFilepath)
+ cpq = cpq.filter(~ContentFilepath.cafilepath_id.in_(capq))
+ cpq.delete()
+
+ s.commit()
+
+
+ def bootstrap_bin(self):
+ """
+ scan the existing debs in the pool to populate the bin_contents table
+ """
+ pooldir = Config()[ 'Dir::Pool' ]
+
+ s = DBConn().session()
+
+ for binary in s.query(DBBinary).yield_per(100):
+ print( "binary: %s" % binary.package )
+ filename = binary.poolfile.filename
+ # Check for existing contents
+ existingq = s.execute( "select 1 from bin_contents where binary_id=:id", {'id':binary.binary_id} );
+ if existingq.fetchone():
+ log.debug( "already imported: %s" % (filename))
+ else:
+ # We don't have existing contents so import them
+ log.debug( "scanning: %s" % (filename) )
+
+ debfile = os.path.join(pooldir, filename)
+ if os.path.exists(debfile):
+ Binary(debfile, self.reject).scan_package(binary.binary_id, True)
+ else:
+ log.error("missing .deb: %s" % filename)
+