]> git.decadent.org.uk Git - dak.git/blob - rose
sync
[dak.git] / rose
1 #!/usr/bin/env python
2
3 # Initial setup of an archive
4 # Copyright (C) 2002  James Troup <james@nocrew.org>
5 # $Id: rose,v 1.2 2002-11-22 04:07:10 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
35 def do_dir(target, config_name):
36     if os.path.exists(target):
37         if not os.path.isdir(target):
38             utils.fubar("%s (%s) is not a directory." % (target, config_name));
39     else:
40         print "Creating %s ..." % (target);
41         os.makedirs(target);
42
43 def process_file(config, config_name):
44     if config.has_key(config_name):
45         target = os.path.dirname(config[config_name]);
46         do_dir(target, config_name);
47
48 def process_tree(config, tree):
49     for entry in config.SubTree(tree).List():
50         entry = entry.lower();
51         if tree == "Dir":
52             if entry == "poolroot" or entry == "queue" or entry == "morguereject":
53                 continue;
54         config_name = "%s::%s" % (tree, entry);
55         target = config[config_name];
56         do_dir(target, config_name);
57
58 def process_morguesubdir(subdir):
59     config_name = "%s::MorgueSubDir" % (subdir);
60     if Cnf.has_key(config_name):
61         target = os.path.join(Cnf["Dir::Morgue"], Cnf[config_name]);
62         do_dir(target, config_name);
63
64 ######################################################################
65
66 def create_directories():
67     # Process directories from apt.conf
68     process_tree(Cnf, "Dir");
69     process_tree(Cnf, "Dir::Queue");
70     for file in [ "Dinstall::LockFile", "Melanie::LogFile", "Neve::ExportDir" ]:
71         process_file(Cnf, file);
72     for subdir in [ "Shania", "Rhona" ]:
73         process_morguesubdir(subdir);
74
75     # Process directories from apt.conf
76     process_tree(AptCnf, "Dir");
77     for tree in AptCnf.SubTree("Tree").List():
78         config_name = "Tree::%s" % (tree);
79         tree_dir = os.path.join(Cnf["Dir::Root"], tree);
80         do_dir(tree_dir, tree);
81         for file in [ "FileList", "SourceFileList" ]:
82             process_file(AptCnf, "%s::%s" % (config_name, file));
83         for component in AptCnf["%s::Sections" % (config_name)].split():
84             for architecture in AptCnf["%s::Architectures" % (config_name)].split():
85                 if architecture != "source":
86                     architecture = "binary-"+architecture;
87                 target = os.path.join(tree_dir,component,architecture);
88                 do_dir(target, "%s, %s, %s" % (tree, component, architecture));
89
90
91 ################################################################################
92
93 def main ():
94     global AptCnf, Cnf, projectB;
95
96     Cnf = utils.get_conf()
97     apt_pkg.ParseCommandLine(Cnf,[],sys.argv);
98
99     AptCnf = apt_pkg.newConfiguration();
100     apt_pkg.ReadConfigFileISC(AptCnf,utils.which_apt_conf_file());
101
102     create_directories();
103
104 ################################################################################
105
106 if __name__ == '__main__':
107     main()
108