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