3 """Initial setup of an archive."""
4 # Copyright (C) 2002, 2004, 2006 James Troup <james@nocrew.org>
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 ################################################################################
24 from daklib import utils
25 from daklib.dbconn import *
27 ################################################################################
31 ################################################################################
33 def usage(exit_code=0):
34 """Print a usage message and exit with 'exit_code'."""
36 print """Usage: dak init-dirs
37 Creates directories for an archive based on dak.conf configuration file.
39 -h, --help show this help and exit."""
42 ################################################################################
44 def do_dir(target, config_name):
45 """If 'target' exists, make sure it is a directory. If it doesn't, create
48 if os.path.exists(target):
49 if not os.path.isdir(target):
50 utils.fubar("%s (%s) is not a directory."
51 % (target, config_name))
53 print "Creating %s ..." % (target)
56 def process_file(config, config_name):
57 """Create directories for a config entry that's a filename."""
59 if config.has_key(config_name):
60 target = os.path.dirname(config[config_name])
61 do_dir(target, config_name)
63 def process_tree(config, tree):
64 """Create directories for a config tree."""
66 for entry in config.SubTree(tree).List():
68 config_name = "%s::%s" % (tree, entry)
69 target = config[config_name]
70 do_dir(target, config_name)
72 def process_morguesubdir(subdir):
73 """Create directories for morgue sub directories."""
75 config_name = "%s::MorgueSubDir" % (subdir)
76 if Cnf.has_key(config_name):
77 target = os.path.join(Cnf["Dir::Morgue"], Cnf[config_name])
78 do_dir(target, config_name)
80 ######################################################################
82 def create_directories():
83 """Create directories referenced in dak.conf and apt.conf."""
85 session = DBConn().session()
87 # Process directories from dak.conf
88 process_tree(Cnf, "Dir")
90 # Process queue directories
91 for queue in session.query(PolicyQueue):
92 do_dir(queue.path, '%s queue' % queue.queue_name)
94 for config_name in [ "Rm::LogFile",
95 "Import-Archive::ExportDir" ]:
96 process_file(Cnf, config_name)
98 for subdir in [ "Clean-Queues", "Clean-Suites" ]:
99 process_morguesubdir(subdir)
101 suite_suffix = "%s" % (Cnf.Find("Dinstall::SuiteSuffix"))
103 # Process pool directories
104 for component in session.query(Component):
105 directory = os.path.join( Cnf['Dir::Pool'], component.component_name )
107 do_dir(directory, '%s pool' % component.component_name)
110 # Process dists directories
111 # TODO: Store location of each suite in database
112 for suite in session.query(Suite):
113 suite_dir = os.path.join( Cnf['Dir::Root'], 'dists', "%s/%s" % (suite.suite_name, suite_suffix) )
115 # TODO: Store valid suite/component mappings in database
116 for component in session.query(Component):
117 component_name = component.component_name
119 sc_dir = os.path.join(suite_dir, component_name)
121 do_dir(sc_dir, "%s/%s" % (suite.suite_name, component_name))
123 for arch in suite.architectures:
124 if arch.arch_string == 'source':
125 arch_string = 'source'
127 arch_string = 'binary-%s' % arch.arch_string
129 suite_arch_dir = os.path.join(sc_dir, arch_string)
131 do_dir(suite_arch_dir, "%s/%s/%s" % (suite.suite_name, component_name, arch_string))
133 ################################################################################
136 """Initial setup of an archive."""
140 Cnf = utils.get_conf()
141 arguments = [('h', "help", "Init-Dirs::Options::Help")]
143 if not Cnf.has_key("Init-Dirs::Options::%s" % (i)):
144 Cnf["Init-Dirs::Options::%s" % (i)] = ""
148 arguments = apt_pkg.ParseCommandLine(Cnf, arguments, sys.argv)
150 options = Cnf.SubTree("Init-Dirs::Options")
154 utils.warn("dak init-dirs takes no arguments.")
159 ################################################################################
161 if __name__ == '__main__':