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 ################################################################################
26 ################################################################################
31 ################################################################################
33 def usage(exit_code=0):
34 print """Usage: dak init-dirs
35 Creates directories for an archive based on dak.conf configuration file.
37 -h, --help show this help and exit."""
40 ################################################################################
42 def do_dir(target, config_name):
43 if os.path.exists(target):
44 if not os.path.isdir(target):
45 dak.lib.utils.fubar("%s (%s) is not a directory." % (target, config_name))
47 print "Creating %s ..." % (target)
50 def process_file(config, config_name):
51 if config.has_key(config_name):
52 target = os.path.dirname(config[config_name])
53 do_dir(target, config_name)
55 def process_tree(config, tree):
56 for entry in config.SubTree(tree).List():
59 if entry in [ "poolroot", "queue" , "morguereject" ]:
61 config_name = "%s::%s" % (tree, entry)
62 target = config[config_name]
63 do_dir(target, config_name)
65 def process_morguesubdir(subdir):
66 config_name = "%s::MorgueSubDir" % (subdir)
67 if Cnf.has_key(config_name):
68 target = os.path.join(Cnf["Dir::Morgue"], Cnf[config_name])
69 do_dir(target, config_name)
71 ######################################################################
73 def create_directories():
74 # Process directories from apt.conf
75 process_tree(Cnf, "Dir")
76 process_tree(Cnf, "Dir::Queue")
77 for file in [ "Dinstall::LockFile", "Rm::LogFile", "Import-Archive::ExportDir" ]:
78 process_file(Cnf, file)
79 for subdir in [ "Clean-Queues", "Clean-Suites" ]:
80 process_morguesubdir(subdir)
82 # Process directories from apt.conf
83 process_tree(AptCnf, "Dir")
84 for tree in AptCnf.SubTree("Tree").List():
85 config_name = "Tree::%s" % (tree)
86 tree_dir = os.path.join(Cnf["Dir::Root"], tree)
87 do_dir(tree_dir, tree)
88 for file in [ "FileList", "SourceFileList" ]:
89 process_file(AptCnf, "%s::%s" % (config_name, file))
90 for component in AptCnf["%s::Sections" % (config_name)].split():
91 for architecture in AptCnf["%s::Architectures" % (config_name)].split():
92 if architecture != "source":
93 architecture = "binary-"+architecture
94 target = os.path.join(tree_dir,component,architecture)
95 do_dir(target, "%s, %s, %s" % (tree, component, architecture))
98 ################################################################################
101 global AptCnf, Cnf, projectB
103 Cnf = dak.lib.utils.get_conf()
104 Arguments = [('h',"help","Init-Dirs::Options::Help")]
106 if not Cnf.has_key("Init-Dirs::Options::%s" % (i)):
107 Cnf["Init-Dirs::Options::%s" % (i)] = ""
109 apt_pkg.ParseCommandLine(Cnf, Arguments, sys.argv)
111 Options = Cnf.SubTree("Init-Dirs::Options")
115 AptCnf = apt_pkg.newConfiguration()
116 apt_pkg.ReadConfigFileISC(AptCnf,dak.lib.utils.which_apt_conf_file())
120 ################################################################################
122 if __name__ == '__main__':