summaryrefslogtreecommitdiffstats
path: root/backend
diff options
context:
space:
mode:
authorRyan Rix <phrkonaleash@gmail.com>2009-12-04 20:17:44 -0700
committerRyan Rix <phrkonaleash@gmail.com>2009-12-04 20:17:44 -0700
commitc3a2d7f9d33d8a91229e70deb02e371d458d20b9 (patch)
tree86f947e95faa7323e8bd60a6e421d6b48f3d3409 /backend
parentdfa6a03ade3c34bfeed3b99b31ddf9c45f08fc08 (diff)
downloadfedora-tour-c3a2d7f9d33d8a91229e70deb02e371d458d20b9.tar.gz
fedora-tour-c3a2d7f9d33d8a91229e70deb02e371d458d20b9.tar.xz
fedora-tour-c3a2d7f9d33d8a91229e70deb02e371d458d20b9.zip
Working on backend XML parser
Diffstat (limited to 'backend')
l---------backend/BACKEND1
-rw-r--r--backend/tour_menuobject.py71
-rw-r--r--backend/tour_menuobject.py~71
3 files changed, 143 insertions, 0 deletions
diff --git a/backend/BACKEND b/backend/BACKEND
new file mode 120000
index 0000000..acd4bc7
--- /dev/null
+++ b/backend/BACKEND
@@ -0,0 +1 @@
+../docs/BACKEND \ No newline at end of file
diff --git a/backend/tour_menuobject.py b/backend/tour_menuobject.py
new file mode 100644
index 0000000..42d7ca6
--- /dev/null
+++ b/backend/tour_menuobject.py
@@ -0,0 +1,71 @@
+# -*- coding: utf-8 -*-
+#
+# This file is a part of Fedora-tour http://fedoraproject.org/wiki/Fedora-tour
+#
+# Copyright (c) 2009 Ryan Rix and Ankur Sinha
+#
+# Permission to use, copy, modify, and distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+#
+
+import io
+import os.path
+import xml.parsers.expat
+
+class MenuNode:
+ parent = 0
+
+class MenuObject:
+ isValid = True;
+ currenElement = False;
+ rootNode = False;
+ activeNode = False;
+
+ def __init__(self,package):
+ if not os.path.isfile(package):
+ self.isValid = False
+ return None
+
+ self.parser = xml.parsers.expat.ParserCreate()
+ self.parser.CharacterDataHandler = self.parserCharData
+ self.parser.StartElementHandler = self.parserStartElement
+ self.parser.EndElementHandler = self.parserEndElement
+
+ self.parser.ParseFile(open(package,"r"))
+
+ def addNode(self,parent):
+ node = MenuNode()
+
+ if parent != False:
+ node.parent = parent
+ parent.nodes.append(node)
+
+
+ return node
+
+ def parserCharData(self, data):
+ if self.currenElement == False:
+ pass
+
+ def parserStartElement(self, name, attrs):
+ if name == "Package":
+ self.rootNode = self.addNode(False)
+ self.currentElement = "Package"
+
+ elif name == "Page":
+ self.activeNode = self.addNode(activeNode)
+ self.currentElement = "Page"
+
+ def parserEndElement(self, name):
+ print name
+
+print MenuObject("../data/package.xml").isValid \ No newline at end of file
diff --git a/backend/tour_menuobject.py~ b/backend/tour_menuobject.py~
new file mode 100644
index 0000000..f72ffab
--- /dev/null
+++ b/backend/tour_menuobject.py~
@@ -0,0 +1,71 @@
+# -*- coding: utf-8 -*-
+#
+# This file is a part of Fedora-tour http://fedoraproject.org/wiki/Fedora-tour
+#
+# Copyright (c) 2009 Ryan Rix and Ankur Sinha
+#
+# Permission to use, copy, modify, and distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+#
+
+import io
+import os.path
+import xml.parsers.expat
+
+class MenuNode:
+ parent = 0
+
+class MenuObject:
+ isValid = True;
+ currenElement = False;
+ rootNode = False;
+ activeNode = False;
+
+ def __init__(self,package):
+ if not os.path.isfile(package):
+ self.isValid = False
+ return None
+
+ self.parser = xml.parsers.expat.ParserCreate()
+ self.parser.CharacterDataHandler = self.parserCharData
+ self.parser.StartElementHandler = self.parserStartElement
+ self.parser.EndElementHandler = self.parserEndElement
+
+ self.parser.ParseFile(open(package,"r"))
+
+ def addNode(self,parent):
+ node = MenuNode()
+
+ if parent = False:
+ node.parent = parent
+ parent.nodes.append(node)
+
+
+ return node
+
+ def parserCharData(self, data):
+ if self.currenElement == False:
+ pass
+
+ def parserStartElement(self, name, attrs):
+ if name == "Package":
+ self.rootNode = self.addNode(False)
+ self.currentElement = "Package"
+
+ elif name == "Page":
+ self.activeNode = self.addNode(activeNode)
+ self.currentElement = "Page"
+
+ def parserEndElement(self, name):
+ print name
+
+print MenuObject("../data/package.xml").isValid \ No newline at end of file