2
# -*- coding: iso-8859-15 -*-
3
######################################################
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published
7
# by the Free Software Foundation; version 2 only.
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.
14
######################################################
18
# Author: Alfredo Jr. <junix>
19
# Creation: 29/10/2006
23
######################################################
25
import xml.dom.minidom
30
(BOLVAL, METHOD, HOST, DISTRIBUTION, VERSION, SECTION, ARCHITECTURE, PATH, MEDIA) = range(9)
33
def node_text(self, node):
35
for child in node.childNodes:
36
if child.nodeType is child.TEXT_NODE:
40
def parse(self, file):
42
if not utils.fileExist(file):
43
self.createDefaultConfigFile(file)
45
x = xml.dom.minidom.parse(file)
46
nodes = x.documentElement
47
children1 = [node for node in nodes.childNodes if node.nodeType == x.ELEMENT_NODE]
48
for father in children1:
49
children2 = [node for node in father.childNodes if node.nodeType == x.ELEMENT_NODE]
50
for child in children2:
51
children_names.append(child.nodeName + ', ' + self.node_text(child))
52
return (children_names)
54
def createDefaultConfigFile(self, file):
55
"""Persists the server list and its folders to a xml file."""
56
util = utils.SystemInfo()
57
aFile = open(file,"w")
58
aFile.write('<?xml version="1.0" encoding="UTF-8" ?>\n')
59
aFile.write('<download version="1.0">\n')
60
aFile.write(' <settings>\n')
61
if util.distro == 'ubuntu':
62
aFile.write(' <host>archive.ubuntu.com</host>\n')
64
aFile.write(' <host>ftp.debian.org</host>\n')
65
aFile.write(' <dist>%s</dist>\n' % util.distro )
66
aFile.write(' <method>http</method>\n')
67
aFile.write(' <version>%s</version>\n' % util.codename)
68
aFile.write(' <section>main</section>\n')
69
aFile.write(' <arch>%s</arch>\n' % util.architecture)
70
aFile.write(' <path>/tmp/aptoncd</path>\n')
71
aFile.write(' <media>CD</media>\n')
72
aFile.write(' </settings>\n')
73
aFile.write('</download>\n')
76
def load_conf(self, file):
77
util = utils.SystemInfo()
78
host = 'archive.ubuntu.com'
81
version = util.codename
83
arch = util.architecture
87
node_text = self.parse(file)
88
for child in node_text:
89
if child.split(",")[0] == 'host':
90
host = string.strip(child.split(",")[1])
91
elif child.split(",")[0] == 'dist':
92
dist = string.strip(child.split(",")[1])
93
elif child.split(",")[0] == 'method':
94
method = string.strip(child.split(",")[1])
95
elif child.split(",")[0] == 'version':
96
version = string.strip(child.split(",")[1])
97
elif child.split(",")[0] == 'section':
98
section = string.strip(child.split(",")[1])
99
elif child.split(",")[0] == 'arch':
100
arch = string.strip(child.split(",")[1])
101
elif child.split(",")[0] == 'path':
102
path = string.strip(child.split(",")[1]).encode('utf8')
103
elif child.split(",")[0] == 'media':
104
media = string.strip(child.split(",")[1])
106
return [False,'','','','','','','','']
107
return [True, method, host, dist, version, section, arch, path, media]