- for suite in s.query(Suite).all():
- for arch in get_suite_architectures(suite.suite_name, skipsrc=True, skipall=True, session=s):
- q = s.query(BinAssociation).join(Suite)
- q = q.join(Suite).filter_by(suite_name=suite.suite_name)
- q = q.join(DBBinary).join(Architecture).filter_by(arch.arch_string)
- for ba in q:
- filename = ba.binary.poolfile.filename
- # Check for existing contents
- existingq = s.query(ContentAssociations).filter_by(binary_pkg=ba.binary_id).limit(1)
- if existingq.count() > 0:
- 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(ba.binary_id, True)
- else:
- log.error("missing .deb: %s" % filename)
+ 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)
+
+
+
+ def bootstrap(self):
+ """
+ scan the existing debs in the pool to populate the contents database tables
+ """
+ s = DBConn().session()
+
+
+ # get a mapping of all the override types we care about (right now .deb an .udeb)
+ override_type_map = {};
+ for override_type in s.query(OverrideType).all():
+ if override_type.overridetype.endswith('deb' ):
+ override_type_map[override_type.overridetype_id] = override_type.overridetype;
+
+ for override in s.query(Override).yield_per(100):
+ if not override_type_map.has_key(override.overridetype_id):
+ #this isn't an override we care about
+ continue
+
+ binaries = s.execute("""SELECT b.id, b.architecture
+ FROM binaries b
+ JOIN bin_associations ba ON ba.bin=b.id
+ WHERE ba.suite=:suite
+ AND b.package=:package""", {'suite':override.suite_id, 'package':override.package})
+ while True:
+ binary = binaries.fetchone()
+ if not binary:
+ break
+
+ exists = s.execute("SELECT 1 FROM %s_contents WHERE binary_id=:id limit 1" % override_type_map[override.overridetype_id], {'id':binary.id})
+
+
+ if exists.fetchone():
+ print '.',
+ continue
+ else:
+ print '+',
+
+ s.execute( """INSERT INTO %s_contents (filename,section,package,binary_id,arch,suite)
+ SELECT file, :section, :package, :binary_id, :arch, :suite
+ FROM bin_contents
+ WHERE binary_id=:binary_id;""" % override_type_map[override.overridetype_id],
+ { 'section' : override.section_id,
+ 'package' : override.package,
+ 'binary_id' : binary.id,
+ 'arch' : binary.architecture,
+ 'suite' : override.suite_id } )
+ s.commit()
+
+ def generate(self):
+ """
+ Generate contents files for both deb and udeb
+ """
+ self.deb_generate()
+ self.udeb_generate()
+
+ def deb_generate(self):
+ """
+ Generate Contents-$arch.gz files for every available arch in each given suite.
+ """
+ session = DBConn().session()
+ debtype_id = get_override_type("deb", session)
+ suites = self._suites()
+
+ inputtoquery = OneAtATime()
+ querytoingest = OneAtATime()
+ ingesttosort = OneAtATime()
+ sorttooutput = OneAtATime()
+ outputtogzip = OneAtATime()
+
+ qt = QueryThread(inputtoquery,querytoingest)
+ it = IngestThread(querytoingest,ingesttosort)
+ st = SortThread(ingesttosort,sorttooutput)
+ ot = OutputThread(sorttooutput,outputtogzip)
+ gt = GzipThread(outputtogzip, None)
+
+ qt.start()
+ it.start()
+ st.start()
+ ot.start()
+ gt.start()
+
+ # Get our suites, and the architectures
+ for suite in [i.lower() for i in suites]:
+ suite_id = get_suite(suite, session).suite_id
+ print( "got suite_id: %s for suite: %s" % (suite_id, suite ) )
+ arch_list = self._arches(suite_id, session)
+
+ for (arch_id,arch_str) in arch_list:
+ print( "suite: %s, arch: %s time: %s" %(suite_id, arch_id, datetime.datetime.now().isoformat()) )
+
+ filename = "dists/%s/Contents-%s" % (suite, arch_str)
+ cf = DebContentFile(filename, suite, suite_id, arch_str, arch_id)
+ inputtoquery.enqueue( cf )
+
+ inputtoquery.enqueue( EndOfContents() )
+ gt.join()
+
+ def udeb_generate(self):
+ """
+ Generate Contents-$arch.gz files for every available arch in each given suite.
+ """
+ session = DBConn().session()
+ udebtype_id=DBConn().get_override_type_id("udeb")
+ suites = self._suites()
+
+ inputtoquery = OneAtATime()
+ querytoingest = OneAtATime()
+ ingesttosort = OneAtATime()
+ sorttooutput = OneAtATime()
+ outputtogzip = OneAtATime()
+
+ qt = QueryThread(inputtoquery,querytoingest)
+ it = IngestThread(querytoingest,ingesttosort)
+ st = SortThread(ingesttosort,sorttooutput)
+ ot = OutputThread(sorttooutput,outputtogzip)
+ gt = GzipThread(outputtogzip, None)
+
+ qt.start()
+ it.start()
+ st.start()
+ ot.start()
+ gt.start()