~ubuntu-branches/ubuntu/saucy/aptoncd/saucy-proposed

« back to all changes in this revision

Viewing changes to xmlfile.py

  • Committer: Bazaar Package Importer
  • Author(s): Fabrice Coutadeur
  • Date: 2009-08-17 22:04:26 UTC
  • mfrom: (1.1.1 upstream) (0.1.11 jaunty)
  • Revision ID: james.westby@ubuntu.com-20090817220426-bhxr3a21ff6y8edm
Tags: 0.1.98+bzr109-0.1
* Non-maintainer upload
* New upstream release (Closes: #452205, #423480, #433915, #541047, #427003,
  #493647, #484636)
* debian/control: 
  - Changed python build dependencies to Build-Depends-Indep
  - Moved url from Description to Homepage
  - Changed Standards-Version to 3.8.2
  - Changed Maintainer to myself
  - Deleted dependency on deprecated mkisofs 
  - Deleted recommend of nautilus-cd-burner
* debian/copyright: Changed (C) to © to make lintian happy
* debian/rules: 
  - deleted deprecated dh_desktop
  - added get-orig-source target to get the latest source from lp
* data/aptoncd.desktop.in: Fixed error and deprecated values in Desktop file

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env python
2
 
# -*- coding: iso-8859-15 -*-
3
 
######################################################
4
 
##
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.
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
 
######################################################
15
 
## 
16
 
#  Project: AptOnCd
17
 
#  File: xmlfile.py
18
 
#  Author: Alfredo Jr. <junix>
19
 
#  Creation: 29/10/2006
20
 
#  Changed: 12/11/2006
21
 
#  Purpose: XML Class
22
 
##
23
 
######################################################
24
 
 
25
 
import xml.dom.minidom
26
 
import string
27
 
import tempfile
28
 
 
29
 
import utils
30
 
 
31
 
(BOLVAL, METHOD, HOST, DISTRIBUTION, VERSION, SECTION, ARCHITECTURE, PATH, MEDIA) = range(9)
32
 
 
33
 
TEMPDIR = tempfile.mkdtemp()
34
 
 
35
 
class XMLFile:
36
 
        def node_text(self, node):
37
 
                text = ''
38
 
                for child in node.childNodes:
39
 
                        if child.nodeType is child.TEXT_NODE:
40
 
                                text += child.data
41
 
                        return text
42
 
 
43
 
        def parse(self, file):
44
 
                children_names = []
45
 
                if not utils.fileExist(file):
46
 
                        self.createDefaultConfigFile(file)
47
 
                        
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)
56
 
 
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')
66
 
                else:
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')
77
 
                aFile.close()
78
 
 
79
 
        def load_conf(self, file):
80
 
                util = utils.SystemInfo()
81
 
                host = 'archive.ubuntu.com'
82
 
                dist =  util.distro
83
 
                method = 'http'
84
 
                version = util.codename
85
 
                section = 'main'
86
 
                arch = util.architecture
87
 
                path = TEMPDIR
88
 
                media = 'CD'
89
 
                try:
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])       
108
 
                except:
109
 
                        return [False,'','','','','','','','']
110
 
                return [True, method, host, dist,  version, section, arch, path, media]