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
31
(BOLVAL, METHOD, HOST, DISTRIBUTION, VERSION, SECTION, ARCHITECTURE, PATH, MEDIA) = range(9)
33
TEMPDIR = tempfile.mkdtemp()
36
def node_text(self, node):
38
for child in node.childNodes:
39
if child.nodeType is child.TEXT_NODE:
43
def parse(self, file):
45
if not utils.fileExist(file):
46
self.createDefaultConfigFile(file)
48
x = xml.dom.minidom.parse(file)
49
nodes = x.documentElement
50
children1 = [node for node in nodes.childNodes if node.nodeType == x.ELEMENT_NODE]
51
for father in children1:
52
children2 = [node for node in father.childNodes if node.nodeType == x.ELEMENT_NODE]
53
for child in children2:
54
children_names.append(child.nodeName + ', ' + self.node_text(child))
55
return (children_names)
57
def createDefaultConfigFile(self, file):
58
"""Persists the server list and its folders to a xml file."""
59
util = utils.SystemInfo()
60
aFile = open(file,"w")
61
aFile.write('<?xml version="1.0" encoding="UTF-8" ?>\n')
62
aFile.write('<download version="1.0">\n')
63
aFile.write(' <settings>\n')
64
if util.distro == 'ubuntu':
65
aFile.write(' <host>archive.ubuntu.com</host>\n')
67
aFile.write(' <host>ftp.debian.org</host>\n')
68
aFile.write(' <dist>%s</dist>\n' % util.distro )
69
aFile.write(' <method>http</method>\n')
70
aFile.write(' <version>%s</version>\n' % util.codename)
71
aFile.write(' <section>main</section>\n')
72
aFile.write(' <arch>%s</arch>\n' % util.architecture)
73
aFile.write(' <path>%s</path>\n' % TEMPDIR)
74
aFile.write(' <media>CD</media>\n')
75
aFile.write(' </settings>\n')
76
aFile.write('</download>\n')
79
def load_conf(self, file):
80
util = utils.SystemInfo()
81
host = 'archive.ubuntu.com'
84
version = util.codename
86
arch = util.architecture
90
node_text = self.parse(file)
91
for child in node_text:
92
if child.split(",")[0] == 'host':
93
host = string.strip(child.split(",")[1])
94
elif child.split(",")[0] == 'dist':
95
dist = string.strip(child.split(",")[1])
96
elif child.split(",")[0] == 'method':
97
method = string.strip(child.split(",")[1])
98
elif child.split(",")[0] == 'version':
99
version = string.strip(child.split(",")[1])
100
elif child.split(",")[0] == 'section':
101
section = string.strip(child.split(",")[1])
102
elif child.split(",")[0] == 'arch':
103
arch = string.strip(child.split(",")[1])
104
elif child.split(",")[0] == 'path':
105
path = string.strip(child.split(",")[1]).encode('utf8')
106
elif child.split(",")[0] == 'media':
107
media = string.strip(child.split(",")[1])
109
return [False,'','','','','','','','']
110
return [True, method, host, dist, version, section, arch, path, media]