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
26 ################################################################################
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():
69 if entry in [ "poolroot", "queue" , "morguereject" ]:
71 config_name = "%s::%s" % (tree, entry)
72 target = config[config_name]
73 do_dir(target, config_name)
75 def process_morguesubdir(subdir):
76 """Create directories for morgue sub directories."""
78 config_name = "%s::MorgueSubDir" % (subdir)
79 if Cnf.has_key(config_name):
80 target = os.path.join(Cnf["Dir::Morgue"], Cnf[config_name])
81 do_dir(target, config_name)
83 ######################################################################
85 def create_directories():
86 """Create directories referenced in dak.conf and apt.conf."""
88 # Process directories from dak.conf
89 process_tree(Cnf, "Dir")
90 process_tree(Cnf, "Dir::Queue")
91 for config_name in [ "Dinstall::LockFile", "Rm::LogFile",
92 "Import-Archive::ExportDir" ]:
93 process_file(Cnf, config_name)
94 for subdir in [ "Clean-Queues", "Clean-Suites" ]:
95 process_morguesubdir(subdir)
97 # Process directories from apt.conf
98 process_tree(AptCnf, "Dir")
99 for tree in AptCnf.SubTree("Tree").List():
100 config_name = "Tree::%s" % (tree)
101 tree_dir = os.path.join(Cnf["Dir::Root"], tree)
102 do_dir(tree_dir, tree)
103 for filename in [ "FileList", "SourceFileList" ]:
104 process_file(AptCnf, "%s::%s" % (config_name, filename))
105 for component in AptCnf["%s::Sections" % (config_name)].split():
106 for architecture in AptCnf["%s::Architectures" \
107 % (config_name)].split():
108 if architecture != "source":
109 architecture = "binary-"+architecture
110 target = os.path.join(tree_dir, component, architecture)
111 do_dir(target, "%s, %s, %s" % (tree, component, architecture))
114 ################################################################################
117 """Initial setup of an archive."""
121 Cnf = utils.get_conf()
122 arguments = [('h', "help", "Init-Dirs::Options::Help")]
124 if not Cnf.has_key("Init-Dirs::Options::%s" % (i)):
125 Cnf["Init-Dirs::Options::%s" % (i)] = ""
127 arguments = apt_pkg.ParseCommandLine(Cnf, arguments, sys.argv)
129 options = Cnf.SubTree("Init-Dirs::Options")
133 utils.warn("dak init-dirs takes no arguments.")
136 AptCnf = apt_pkg.newConfiguration()
137 apt_pkg.ReadConfigFileISC(AptCnf, utils.which_apt_conf_file())
141 ################################################################################
143 if __name__ == '__main__':