/[partial-mirror]/branches/rewrite/src/Config.py
ViewVC logotype

Contents of /branches/rewrite/src/Config.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 97 - (show annotations) (download) (as text)
Tue Jun 29 18:20:17 2004 UTC (8 years, 10 months ago) by otavio
Original Path: trunk/src/Config.py
File MIME type: text/x-python
File size: 5392 byte(s)
Move to parent directory.
1 # debpartial-mirror - partial debian mirror package tool
2 # (c) 2004 Otavio Salvador <otavio@debian.org>, Henrique Vilela <jacare@ucpel.tche.br>
3 #
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 # $Id$
18
19 import ConfigParser
20
21 # Process the configuration options
22 class Config:
23 # Initialize these vars
24 __mirror = {}
25 __dists = {}
26 __exclude = {}
27
28 __suggests = ""
29 __recomends = ""
30 __provides = ""
31
32 def __init__(self, filename):
33 cnf = ConfigParser.ConfigParser()
34 cnf.read(filename)
35 for section in cnf.sections():
36 for option in cnf.options(section):
37 if section == "mirror":
38 if option == "archs" or option == "files":
39 self.__mirror[option] = cnf.get(section, option).split(" ")
40 else:
41 self.__mirror[option] = cnf.get(section, option)
42 else:
43 if not self.__dists.has_key(section):
44 self.__dists[section] = {}
45 self.__exclude[section] = []
46
47
48 if option == "filter" or option == "packages":
49 filters = cnf.get(section, option).split(" ")
50
51 for rule in filters:
52 rule = rule.split(":")
53
54 if not self.__dists[section].has_key(rule[0]):
55 self.__dists[section][rule[0]] = []
56
57 if option == "filter":
58 self.__dists[section][rule[0]].append({"section": rule[1], "priority": rule[2], "package": "*"})
59 else:
60 self.__dists[section][rule[0]].append({"section": "*", "priority": "*", "package": rule[1]})
61 elif option == "exclude":
62 filters = cnf.get(section, option).split(" ")
63
64 for rule in filters:
65 self.__exclude[section].append(rule)
66 elif option == 'include-task' or option == 'exclude-task':
67 self.__dists[section][option] = cnf.get(section, option)
68 else:
69 raise IOError, option + ' is unknowdow, please check your configuration file.'
70
71 def getValue(self, section, option):
72 if self.__options.has_key(section):
73 if self.__option[section].has_key(option):
74 return self.__option[section][option]
75 return ""
76
77 def getMirror(self):
78 return self.__mirror
79
80 def __getMirrorOption(self, option):
81 if self.__mirror.has_key(option):
82 return self.__mirror[option]
83 return ""
84
85 def getServer(self):
86 return self.__getMirrorOption("server");
87
88 def getArchs(self):
89 return self.__getMirrorOption("archs");
90
91 def getFiles(self):
92 return self.__getMirrorOption("files");
93
94 def getLocalDirectory(self):
95 return self.__getMirrorOption("local_directory");
96
97 def getDists(self):
98 return self.__dists
99
100 def getSuggests(self):
101 if self.__getMirrorOption('get_suggests') == 'true':
102 return True
103 else:
104 return False
105
106 def getRecomends(self):
107 if self.__getMirrorOption('get_recomends') == 'true':
108 return True
109 else:
110 return False
111
112 def getProvides(self):
113 if self.__getMirrorOption('get_provides') == 'true':
114 return True
115 else:
116 return False
117
118 def getSections(self, dist_name):
119 if self.__dists.has_key(dist_name):
120 dists = {}
121 for d in self.__dists[dist_name].keys():
122 if d != 'include-task' and d != 'exclude-task':
123 dists[d] = self.__dists[dist_name][d]
124 return dists
125 return ""
126
127 def getFilters(self, dist_name, section_name):
128 if self.__dists.has_key(dist_name):
129 if self.__dists[dist_name].has_key(section_name):
130 return self.__dists[dist_name][section_name]
131 return ""
132
133 def getIncludeTask(self, dist_name):
134 if self.__dists.has_key(dist_name):
135 if self.__dists[dist_name].has_key('include-task'):
136 return self.__dists[dist_name]['include-task']
137 return ''
138
139 def getExcludeTask(self, dist_name):
140 if self.__dists.has_key(dist_name):
141 if self.__dists[dist_name].has_key('exclude-task'):
142 return self.__dists[dist_name]['exclude-task']
143 return ''
144
145 def getExcludes(self, dist_name):
146 if self.__exclude.has_key(dist_name):
147 return self.__exclude[dist_name]
148 return []

  ViewVC Help
Powered by ViewVC 1.1.5