[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[dak/master 2/4] Do no longer re-exec dak contents.



We just call DBConn().reset() in the child process now.

Signed-off-by: Torsten Werner <twerner@debian.org>
---
 dak/contents.py    |   21 +--------------------
 daklib/contents.py |   36 ++++++++++++++++++++++++++----------
 2 files changed, 27 insertions(+), 30 deletions(-)

diff --git a/dak/contents.py b/dak/contents.py
index 5c33afa..a8578ae 100755
--- a/dak/contents.py
+++ b/dak/contents.py
@@ -82,21 +82,6 @@ def write_all(cnf, suite_names = [], force = None):
 
 ################################################################################
 
-def write_helper(suite_name, argv):
-    session = DBConn().session()
-    suite = get_suite(suite_name, session)
-    architecture = get_architecture(argv[0], session)
-    debtype = get_override_type(argv[1], session)
-    if len(argv) == 3:
-        component = get_component(argv[2], session)
-    else:
-        component = None
-    session.rollback()
-    ContentsWriter(suite, architecture, debtype, component).write_file()
-    session.close()
-
-################################################################################
-
 def scan_all(cnf, limit):
     Logger = daklog.Logger(cnf.Cnf, 'contents scan')
     result = ContentsScanner.scan_all(limit)
@@ -121,7 +106,7 @@ def main():
     args = apt_pkg.ParseCommandLine(cnf.Cnf, arguments, sys.argv)
     options = cnf.SubTree('Contents::Options')
 
-    if (len(args) < 1) or options['Help']:
+    if (len(args) != 1) or options['Help']:
         usage()
 
     limit = None
@@ -140,10 +125,6 @@ def main():
         write_all(cnf, suite_names, force)
         return
 
-    if args[0] == 'generate_helper':
-        write_helper(suite_names[0], args[1:])
-        return
-
     usage()
 
 
diff --git a/daklib/contents.py b/daklib/contents.py
index 5bf94d9..99d852b 100755
--- a/daklib/contents.py
+++ b/daklib/contents.py
@@ -32,7 +32,7 @@ from multiprocessing import Pool
 
 from sqlalchemy import desc, or_
 from sqlalchemy.exc import IntegrityError
-from subprocess import Popen, PIPE, call
+from subprocess import Popen, PIPE
 
 import os.path
 
@@ -208,24 +208,40 @@ select bc.file, string_agg(o.section || '/' || b.package, ',' order by b.package
             suite_query = suite_query.filter(Suite.suite_name.in_(suite_names))
         if not force:
             suite_query = suite_query.filter_by(untouchable = False)
+        deb_id = get_override_type('deb', session).overridetype_id
+        udeb_id = get_override_type('udeb', session).overridetype_id
+        main_id = get_component('main', session).component_id
+        non_free_id = get_component('non-free', session).component_id
         pool = Pool()
         for suite in suite_query:
+            suite_id = suite.suite_id
             for architecture in suite.get_architectures(skipsrc = True, skipall = True):
+                arch_id = architecture.arch_id
                 # handle 'deb' packages
-                command = ['dak', 'contents', '-s', suite.suite_name, \
-                    'generate_helper', architecture.arch_string, 'deb']
-                pool.apply_async(call, (command, ))
+                pool.apply_async(generate_helper, (suite_id, arch_id, deb_id))
                 # handle 'udeb' packages for 'main' and 'non-free'
-                command = ['dak', 'contents', '-s', suite.suite_name, \
-                    'generate_helper', architecture.arch_string, 'udeb', 'main']
-                pool.apply_async(call, (command, ))
-                command = ['dak', 'contents', '-s', suite.suite_name, \
-                    'generate_helper', architecture.arch_string, 'udeb', 'non-free']
-                pool.apply_async(call, (command, ))
+                pool.apply_async(generate_helper, (suite_id, arch_id, udeb_id, main_id))
+                pool.apply_async(generate_helper, (suite_id, arch_id, udeb_id, non_free_id))
         pool.close()
         pool.join()
         session.close()
 
+def generate_helper(suite_id, arch_id, overridetype_id, component_id = None):
+    '''
+    This function is called in a new subprocess.
+    '''
+    DBConn().reset()
+    session = DBConn().session()
+    suite = Suite.get(suite_id, session)
+    architecture = Architecture.get(arch_id, session)
+    overridetype = OverrideType.get(overridetype_id, session)
+    if component_id is None:
+        component = None
+    else:
+        component = Component.get(component_id, session)
+    contents_writer = ContentsWriter(suite, architecture, overridetype, component)
+    contents_writer.write_file()
+
 
 class ContentsScanner(object):
     '''
-- 
1.7.2.5



Reply to: