diff options
Diffstat (limited to 'backend/tour_menuobject.py~')
-rw-r--r-- | backend/tour_menuobject.py~ | 71 |
1 files changed, 71 insertions, 0 deletions
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 |