~ubuntu-branches/ubuntu/maverick/blender/maverick

« back to all changes in this revision

Viewing changes to release/scripts/bpymodules/colladaImEx/xmlUtils.py

  • Committer: Bazaar Package Importer
  • Author(s): Khashayar Naderehvandi, Khashayar Naderehvandi, Alessio Treglia
  • Date: 2009-01-22 16:53:59 UTC
  • mfrom: (14.1.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20090122165359-v0996tn7fbit64ni
Tags: 2.48a+dfsg-1ubuntu1
[ Khashayar Naderehvandi ]
* Merge from debian experimental (LP: #320045), Ubuntu remaining changes:
  - Add patch correcting header file locations.
  - Add libvorbis-dev and libgsm1-dev to Build-Depends.
  - Use avcodec_decode_audio2() in source/blender/src/hddaudio.c

[ Alessio Treglia ]
* Add missing previous changelog entries.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
from cutils import *
27
27
from xml.dom.minidom import *
28
28
 
 
29
debprn = False #--- print debug "print 'deb: ..."
 
30
 
29
31
#---XML Utils---
30
32
 
31
33
# Returns the first child of the specified type in node
52
54
def ReadAttribute(node,attributeName):
53
55
        if node != None and attributeName != None:
54
56
                attribute = node.getAttribute(attributeName)
55
 
                return attribute                
 
57
                return attribute
56
58
        return None
57
59
 
58
60
def ReadContents(node):
67
69
                return None
68
70
        return GetDateTime(ReadContents(node))
69
71
 
70
 
def RemoveWhiteSpace(parent):    
 
72
def RemoveWhiteSpace(parent):
71
73
        for child in list(parent.childNodes):
72
74
                if child.nodeType==child.TEXT_NODE and child.data.strip()=='':
73
75
                        parent.removeChild(child)
79
81
                if child.nodeType == child.TEXT_NODE and child.data.strip()=='':
80
82
                        parent.removeChild(child)
81
83
        return parent
82
 
                        
 
84
 
 
85
def RemoveComments(parent):
 
86
        for child in list(parent.childNodes):
 
87
                if child.__class__.__name__ == "Comment":
 
88
                        parent.removeChild(child)
 
89
        return parent
 
90
 
83
91
##def RemoveWhiteSpace(node):
84
92
##        removeList = []
85
93
##        for child in node.childNodes:
87
95
##                        removeList.append(child)
88
96
##                elif child.hasChildNodes():
89
97
##                        RemoveWhiteSpace(child)
90
 
##        
 
98
##
91
99
##        for node in removeList:
92
100
##                node.parentNode.removeChild(node)
93
101
 
97
105
        timestr =  vals[1]
98
106
        date = datestr.split('-')
99
107
        time = timestr.split(':')
100
 
        time[2]=time[2].rstrip('Z')    
 
108
        time[2]=time[2].rstrip('Z')
101
109
        return datetime(int(date[0]), int(date[1]), int(date[2]),int(time[0]), int(time[1]), int(float(time[2])))
102
110
 
103
111
def ToDateTime(val):
110
118
        for xmlNode in xmlNodes:
111
119
                stringvals = ReadContents(xmlNode).split( )
112
120
                for string in stringvals:
113
 
                        vals.append(string)                
 
121
                        vals.append(string)
114
122
        return vals
115
123
 
116
124
def GetListFromNodes(xmlNodes, cast=None):
117
125
        result = []
118
126
        if xmlNodes is None:
119
127
                return result
120
 
        
 
128
 
121
129
        for xmlNode in xmlNodes:
122
130
                val = ReadContents(xmlNode).split( )
123
131
                if cast == float:
127
135
                elif cast == bool:
128
136
                        val = ToBoolList(val)
129
137
                result.append(val)
130
 
        return result                    
131
 
                
 
138
        return result
 
139
 
132
140
 
133
141
def ToXml(xmlNode, indent='\t', newl='\n'):
134
142
        return '<?xml version="1.0" encoding="utf-8"?>\n%s'%(__ToXml(xmlNode, indent,newl))
135
 
        
 
143
 
136
144
def __ToXml(xmlNode, indent='\t',newl='\n',totalIndent=''):
137
145
        childs = xmlNode.childNodes
138
146
        if len(childs) > 0:
145
153
                result = '%s<%s%s>'%(totalIndent,xmlNode.localName,attrs)
146
154
                tempnewl = newl
147
155
                tempTotIndent = totalIndent
148
 
                for child in childs:                    
 
156
                for child in childs:
149
157
                        if child.nodeType == child.TEXT_NODE:
150
158
                                tempnewl = ''
151
159
                                tempTotIndent = ''
152
 
                        
 
160
 
153
161
                        result += '%s%s'%(tempnewl,__ToXml(child, indent, newl, totalIndent+indent))
154
162
                result += '%s%s</%s>'%(tempnewl,tempTotIndent,xmlNode.localName)
155
163
                return result
162
170
def AppendChilds(xmlNode, syntax, lst):
163
171
        if lst is None or syntax is None or xmlNode is None:
164
172
                return
165
 
        
 
173
 
166
174
        for i in lst:
167
175
                el = Element(syntax)
168
176
                text = Text()
169
177
                text.data = ListToString(i)
170
178
                el.appendChild(text)
171
179
                xmlNode.appendChild(el)
172
 
        
 
180
 
173
181
        return xmlNode
174
182
 
 
183