]> git.decadent.org.uk Git - dak.git/blobdiff - dak/generate_filelist.py
show-new: reduce number of open DB sessions
[dak.git] / dak / generate_filelist.py
index 50a0949a9040712f64bb1f5007cdc887aaf36149..e6a2ba57c3b53e21b8e83c90c8ad74e3c46a4b06 100755 (executable)
@@ -22,8 +22,22 @@ Generate file lists for apt-ftparchive.
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
+################################################################################
+
+# Ganneff> Please go and try to lock mhy now. After than try to lock NEW.
+# twerner> !lock mhy
+# dak> twerner: You suck, this is already locked by Ganneff
+# Ganneff> now try with NEW
+# twerner> !lock NEW
+# dak> twerner: also locked NEW
+# mhy> Ganneff: oy, stop using me for locks and highlighting me you tall muppet
+# Ganneff> hehe :)
+
+################################################################################
+
 from daklib.dbconn import *
 from daklib.config import Config
+from daklib.threadpool import ThreadPool
 from daklib import utils
 import apt_pkg, os, sys
 
@@ -104,13 +118,17 @@ def listPath(suite, component, architecture = None, type = None):
     pathname = os.path.join(Config()["Dir::Lists"], filename)
     return utils.open_file(pathname, "w")
 
-def writeSourceList(suite, component, session):
+def writeSourceList(args):
+    (suite, component) = args
     file = listPath(suite, component)
+    session = DBConn().session()
     for filename in getSources(suite, component, session):
         file.write(filename + '\n')
+    session.close()
     file.close()
 
-def writeBinaryList(suite, component, architecture, type):
+def writeBinaryList(args):
+    (suite, component, architecture, type) = args
     file = listPath(suite, component, architecture, type)
     session = DBConn().session()
     for filename in getBinaries(suite, component, architecture, type, session):
@@ -156,6 +174,7 @@ def main():
         usage()
     session = DBConn().session()
     suite_arch = session.query(SuiteArchitecture)
+    threadpool = ThreadPool()
     for suite_name in utils.split_args(Options['Suite']):
         suite = query_suites.filter_by(suite_name = suite_name).one()
         join = suite_arch.filter_by(suite_id = suite.suite_id)
@@ -168,12 +187,15 @@ def main():
                 try:
                     join.filter_by(arch_id = architecture.arch_id).one()
                     if architecture_name == 'source':
-                        writeSourceList(suite, component, session)
+                        threadpool.queueTask(writeSourceList, (suite, component))
                     elif architecture_name != 'all':
-                        writeBinaryList(suite, component, architecture, 'deb')
-                        writeBinaryList(suite, component, architecture, 'udeb')
+                        threadpool.queueTask(writeBinaryList,
+                            (suite, component, architecture, 'deb'))
+                        threadpool.queueTask(writeBinaryList,
+                            (suite, component, architecture, 'udeb'))
                 except:
                     pass
+    threadpool.joinAll()
     # this script doesn't change the database
     session.close()