]> git.decadent.org.uk Git - dak.git/blob - dak/init_dirs.py
Globally remove trailing semi-colon damage.
[dak.git] / dak / init_dirs.py
1 #!/usr/bin/env python
2
3 # Initial setup of an archive
4 # Copyright (C) 2002, 2004  James Troup <james@nocrew.org>
5 # $Id: rose,v 1.4 2004-03-11 00:20:51 troup Exp $
6
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
11
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20
21 ################################################################################
22
23 import os, sys
24 import utils
25 import apt_pkg
26
27 ################################################################################
28
29 Cnf = None
30 AptCnf = None
31
32 ################################################################################
33
34 def usage(exit_code=0):
35     print """Usage: rose
36 Creates directories for an archive based on katie.conf configuration file.
37
38   -h, --help                show this help and exit."""
39     sys.exit(exit_code)
40
41 ################################################################################
42
43 def do_dir(target, config_name):
44     if os.path.exists(target):
45         if not os.path.isdir(target):
46             utils.fubar("%s (%s) is not a directory." % (target, config_name))
47     else:
48         print "Creating %s ..." % (target)
49         os.makedirs(target)
50
51 def process_file(config, config_name):
52     if config.has_key(config_name):
53         target = os.path.dirname(config[config_name])
54         do_dir(target, config_name)
55
56 def process_tree(config, tree):
57     for entry in config.SubTree(tree).List():
58         entry = entry.lower()
59         if tree == "Dir":
60             if entry in [ "poolroot", "queue" , "morguereject" ]:
61                 continue
62         config_name = "%s::%s" % (tree, entry)
63         target = config[config_name]
64         do_dir(target, config_name)
65
66 def process_morguesubdir(subdir):
67     config_name = "%s::MorgueSubDir" % (subdir)
68     if Cnf.has_key(config_name):
69         target = os.path.join(Cnf["Dir::Morgue"], Cnf[config_name])
70         do_dir(target, config_name)
71
72 ######################################################################
73
74 def create_directories():
75     # Process directories from apt.conf
76     process_tree(Cnf, "Dir")
77     process_tree(Cnf, "Dir::Queue")
78     for file in [ "Dinstall::LockFile", "Melanie::LogFile", "Neve::ExportDir" ]:
79         process_file(Cnf, file)
80     for subdir in [ "Shania", "Rhona" ]:
81         process_morguesubdir(subdir)
82
83     # Process directories from apt.conf
84     process_tree(AptCnf, "Dir")
85     for tree in AptCnf.SubTree("Tree").List():
86         config_name = "Tree::%s" % (tree)
87         tree_dir = os.path.join(Cnf["Dir::Root"], tree)
88         do_dir(tree_dir, tree)
89         for file in [ "FileList", "SourceFileList" ]:
90             process_file(AptCnf, "%s::%s" % (config_name, file))
91         for component in AptCnf["%s::Sections" % (config_name)].split():
92             for architecture in AptCnf["%s::Architectures" % (config_name)].split():
93                 if architecture != "source":
94                     architecture = "binary-"+architecture
95                 target = os.path.join(tree_dir,component,architecture)
96                 do_dir(target, "%s, %s, %s" % (tree, component, architecture))
97
98
99 ################################################################################
100
101 def main ():
102     global AptCnf, Cnf, projectB
103
104     Cnf = utils.get_conf()
105     Arguments = [('h',"help","Rose::Options::Help")]
106     for i in [ "help" ]:
107         if not Cnf.has_key("Rose::Options::%s" % (i)):
108             Cnf["Rose::Options::%s" % (i)] = ""
109
110     apt_pkg.ParseCommandLine(Cnf, Arguments, sys.argv)
111
112     Options = Cnf.SubTree("Rose::Options")
113     if Options["Help"]:
114         usage()
115
116     AptCnf = apt_pkg.newConfiguration()
117     apt_pkg.ReadConfigFileISC(AptCnf,utils.which_apt_conf_file())
118
119     create_directories()
120
121 ################################################################################
122
123 if __name__ == '__main__':
124     main()
125