+# 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
+remove_pending_contents_cruft_q = """DELETE FROM pending_content_associations"""
+
+# delete any filenames we are storing which have no binary associated with them
+remove_filename_cruft_q = """DELETE FROM content_file_names
+ WHERE id IN (SELECT cfn.id FROM content_file_names cfn
+ LEFT JOIN content_associations ca
+ ON ca.filename=cfn.id
+ WHERE ca.id IS NULL)"""
+
+# delete any paths we are storing which have no binary associated with them
+remove_filepath_cruft_q = """DELETE FROM content_file_paths
+ WHERE id IN (SELECT cfn.id FROM content_file_paths cfn
+ LEFT JOIN content_associations ca
+ ON ca.filepath=cfn.id
+ WHERE ca.id IS NULL)"""
+
+class EndOfContents(object):
+ pass
+
+class GzippedContentWriter(object):
+ def __init__(self, suite, arch):
+ self.queue = Queue.Queue()
+ self.current_file = None
+ self.first_package = True
+ self.output = self.open_file("dists/%s/Contents-%s.gz" % (suite, arch))
+ self.thread = threading.Thread(target=self.write_thread,
+ name='Contents-%s writer'%arch)
+
+ self.thread.start()
+
+ def open_file(self, filename):
+ filepath = Config()["Contents::Root"] + filename
+ filedir = os.path.dirname(filepath)
+ if not os.path.isdir(filedir):
+ os.makedirs(filedir)
+ return gzip.open(filepath, "w")
+
+ def write(self, filename, section, package):
+ self.queue.put((file,section,package))
+
+
+ def write_thread(self):
+ while True:
+ print("hi, i'm a thread" );
+ next = self.queue.get()
+ print("GOT SOMEHTING FROM THE QUEUE" );
+ if isinstance(next, EndOfContents):
+ self.output.write('\n')
+ self.output.close()
+ break
+
+ (filename,section,package)=next
+ if next != current_file:
+ # this is the first file, so write the header first
+ if not current_file:
+ self.output.write(self._getHeader)
+
+ self.output.write('\n%s\t' % filename)
+ self.first_package = True
+ if not first_package:
+ self.output.write(',')
+ else:
+ self.first_package=False
+ self.output.write('%s/%s' % (section,package))