]> git.decadent.org.uk Git - dak.git/blobdiff - dak/init_dirs.py
Remove files that are (no longer) generated
[dak.git] / dak / init_dirs.py
index f92515e251d71a21e872dd5382fd47a7e2160407..347945a3e8c037ac6a0d428b5a798592e8e69a7b 100755 (executable)
 
 import os, sys
 import apt_pkg
-import daklib.utils as utils
+from daklib import utils
+from daklib.dbconn import *
 
 ################################################################################
 
 Cnf = None
-AptCnf = None
 
 ################################################################################
 
@@ -63,11 +63,8 @@ def process_file(config, config_name):
 def process_tree(config, tree):
     """Create directories for a config tree."""
 
-    for entry in config.SubTree(tree).List():
+    for entry in config.subtree(tree).list():
         entry = entry.lower()
-        if tree == "Dir":
-            if entry in [ "poolroot", "queue" , "morguereject" ]:
-                continue
         config_name = "%s::%s" % (tree, entry)
         target = config[config_name]
         do_dir(target, config_name)
@@ -80,43 +77,99 @@ def process_morguesubdir(subdir):
         target = os.path.join(Cnf["Dir::Morgue"], Cnf[config_name])
         do_dir(target, config_name)
 
+def process_keyring(fullpath, secret=False):
+    """Create empty keyring if necessary."""
+
+    if os.path.exists(fullpath):
+        return
+
+    keydir = os.path.dirname(fullpath)
+
+    if not os.path.isdir(keydir):
+        print "Creating %s ..." % (keydir)
+        os.makedirs(keydir)
+        if secret:
+            # Make sure secret keyring directories are 0700
+            os.chmod(keydir, 0o700)
+
+    # Touch the file
+    print "Creating %s ..." % (fullpath)
+    file(fullpath, 'w')
+    if secret:
+        os.chmod(fullpath, 0o600)
+    else:
+        os.chmod(fullpath, 0o644)
+
 ######################################################################
 
 def create_directories():
-    """Create directories referenced in dak.conf and apt.conf."""
+    """Create directories referenced in dak.conf."""
+
+    session = DBConn().session()
 
     # Process directories from dak.conf
     process_tree(Cnf, "Dir")
-    process_tree(Cnf, "Dir::Queue")
-    for config_name in [ "Dinstall::LockFile", "Rm::LogFile",
+
+    # Hardcode creation of the unchecked directory
+    if Cnf.has_key("Dir::Base"):
+        do_dir(os.path.join(Cnf["Dir::Base"], "queue", "unchecked"), 'unchecked directory')
+
+    # Process queue directories
+    for queue in session.query(PolicyQueue):
+        do_dir(queue.path, '%s queue' % queue.queue_name)
+        # If we're doing the NEW queue, make sure it has a COMMENTS directory
+        if queue.queue_name == 'new':
+            do_dir(os.path.join(queue.path, "COMMENTS"), '%s queue comments' % queue.queue_name)
+
+    for config_name in [ "Rm::LogFile",
                          "Import-Archive::ExportDir" ]:
         process_file(Cnf, config_name)
+
     for subdir in [ "Clean-Queues", "Clean-Suites" ]:
         process_morguesubdir(subdir)
 
-    # Process directories from apt.conf
-    process_tree(AptCnf, "Dir")
-    for tree in AptCnf.SubTree("Tree").List():
-        config_name = "Tree::%s" % (tree)
-        tree_dir = os.path.join(Cnf["Dir::Root"], tree)
-        do_dir(tree_dir, tree)
-        for filename in [ "FileList", "SourceFileList" ]:
-            process_file(AptCnf, "%s::%s" % (config_name, filename))
-        for component in AptCnf["%s::Sections" % (config_name)].split():
-            for architecture in AptCnf["%s::Architectures" \
-                                       % (config_name)].split():
-                if architecture != "source":
-                    architecture = "binary-"+architecture
-                target = os.path.join(tree_dir, component, architecture)
-                do_dir(target, "%s, %s, %s" % (tree, component, architecture))
+    suite_suffix = "%s" % (Cnf.find("Dinstall::SuiteSuffix"))
 
+    # Process secret keyrings
+    if Cnf.has_key('Dinstall::SigningKeyring'):
+        process_keyring(Cnf['Dinstall::SigningKeyring'], secret=True)
+
+    if Cnf.has_key('Dinstall::SigningPubKeyring'):
+        process_keyring(Cnf['Dinstall::SigningPubKeyring'], secret=True)
+
+    # Process public keyrings
+    for keyring in session.query(Keyring).filter_by(active=True):
+        process_keyring(keyring.keyring_name)
+
+    # Process dists directories
+    # TODO: Store location of each suite in database
+    for suite in session.query(Suite):
+        suite_dir = os.path.join(suite.archive.path, 'dists', suite.suite_name, suite_suffix)
+
+        # TODO: Store valid suite/component mappings in database
+        for component in session.query(Component):
+            component_name = component.component_name
+
+            sc_dir = os.path.join(suite_dir, component_name)
+
+            do_dir(sc_dir, "%s/%s" % (suite.suite_name, component_name))
+
+            for arch in suite.architectures:
+                if arch.arch_string == 'source':
+                    arch_string = 'source'
+                else:
+                    arch_string = 'binary-%s' % arch.arch_string
+
+                suite_arch_dir = os.path.join(sc_dir, arch_string)
+
+                do_dir(suite_arch_dir, "%s/%s/%s" % (suite.suite_name, component_name, arch_string))
 
 ################################################################################
 
 def main ():
     """Initial setup of an archive."""
 
-    global AptCnf, Cnf
+    global Cnf
 
     Cnf = utils.get_conf()
     arguments = [('h', "help", "Init-Dirs::Options::Help")]
@@ -124,18 +177,17 @@ def main ():
         if not Cnf.has_key("Init-Dirs::Options::%s" % (i)):
             Cnf["Init-Dirs::Options::%s" % (i)] = ""
 
-    arguments = apt_pkg.ParseCommandLine(Cnf, arguments, sys.argv)
+    d = DBConn()
 
-    options = Cnf.SubTree("Init-Dirs::Options")
+    arguments = apt_pkg.parse_commandline(Cnf, arguments, sys.argv)
+
+    options = Cnf.subtree("Init-Dirs::Options")
     if options["Help"]:
         usage()
     elif arguments:
         utils.warn("dak init-dirs takes no arguments.")
         usage(exit_code=1)
 
-    AptCnf = apt_pkg.newConfiguration()
-    apt_pkg.ReadConfigFileISC(AptCnf, utils.which_apt_conf_file())
-
     create_directories()
 
 ################################################################################