Ejemplo n.º 1
0
    def _createXML(self):
        path = config.temp_folder
        deviceroot = XmlData("devices")
        devicelist = "devicelist.xml"

        if not os.path.exists(path):
            os.makedirs(path)
        
        # iterate thru all devices
        for device in self._devices:
            client = device.get_client()

            child = XmlData("device")
            child.addAttribute( Attribute("type", device.get_type() ) )
            child.addAttribute( Attribute("id", device.get_uid()) )
            child.addAttribute( Attribute("name", client.device.get_friendly_name()) )
            
            deviceroot.addChild(child)
        


        # write the list to xml
        XmlGenerator.xmlToFile(deviceroot, path+devicelist)

        # notify the UI that our xml data has changed
        self._handler.handleEvent( 
            Event( "ReturnUiData", "UpnpBackend", "DeviceListChanged", path+devicelist ) )
Ejemplo n.º 2
0
def _createElement(document, XmlData):
    el = document.createElement(XmlData.name)
    
    # attributes
    for att in XmlData.getAttributeList():
        el.setAttribute(att.getName(),att.getValue())
    
    # children
    for child in XmlData.getChildren():
        el.appendChild(_createElement(document,child))
        
    return el
def createInstance(source, input):
    try:
        sources = {"Json": JsonData(input), "Xml": XmlData(input)}
        return sources[source]
    except:
        print(source + " Data not supported, we are supporting json and xml")
        return False
Ejemplo n.º 4
0
def _parseElement(element):
    xmlData = XmlData(element.nodeName)
    
    # attributes
    if element.hasAttributes():
        indexlist = range(element.attributes.length)
        indexlist.reverse()     # order has to be reversed (for some reason)
        for index in indexlist:
            att = element.attributes.item(index)
            xmlData.addAttribute(Attribute(att.name, att.value))
        
    # children
    if element.hasChildNodes():
        for child in element.childNodes:
            if child.nodeType == 1: # 1 is the symbolic equivalent of element node.
                xmlData.addChild(_parseElement(child))
    
    return xmlData
Ejemplo n.º 5
0
    def _createXMLfilelist(self):	
#        path = "/tmp/mymeego/data/"
        path = config.temp_folder
	fileroot = XmlData("transferfiles")
	filelist = "filelist.xml"

	# write local files to xml
	device = self._localdevice

        # albums
    	albumroot = XmlData("albums")

    	for album in device.get_albums():
	    child = XmlData("album")
	    child.addAttribute( Attribute("id", album.get_id() ))
	    child.addAttribute( Attribute("title", album.get_name() ))
	    child.addAttribute( Attribute("cover", album.get_cover() ))
	    child.addAttribute( Attribute("URL", album.get_uri() ))

	    songroot = XmlData("songs")

	    for song in album._songs:
	        songchild = XmlData("song")
	        songchild.addAttribute( Attribute("number", song.get_number() ))
	        songchild.addAttribute( Attribute("filename", song.get_filename() ))
		
	        songroot.addChild(songchild)

            child.addChild(songroot)
	    albumroot.addChild(child)
	
	fileroot.addChild(albumroot)

        # pictures
        pictureroot = XmlData("pictures")

        for picture in device.get_pictures():
            child = XmlData("picture")
            child.addAttribute( Attribute("id", picture.get_id()))
            child.addAttribute( Attribute("thumbnail", picture.get_thumbnail()))
            child.addAttribute( Attribute("URL", picture.get_uri()))

            pictureroot.addChild(child)

        fileroot.addChild(pictureroot)

        # movies 
        movieroot = XmlData("movies")

        for movie in device.get_movies():
            child = XmlData("movie")
            child.addAttribute( Attribute("id", movie.get_id()))
            child.addAttribute( Attribute("cover", movie.get_cover()))
            child.addAttribute( Attribute("name", movie.get_name()))
            child.addAttribute( Attribute("URL", movie.get_uri()))

            movieroot.addChild(child)

        fileroot.addChild(movieroot)

	XmlGenerator.xmlToFile(fileroot, path+filelist)
Ejemplo n.º 6
0
    def _createXMLfilelist(self):
        #        path = "/tmp/mymeego/data/"
        path = config.temp_folder
        fileroot = XmlData("transferfiles")
        filelist = "filelist.xml"

        # write local files to xml
        device = self._localdevice

        # albums
        albumroot = XmlData("albums")

        for album in device.get_albums():
            child = XmlData("album")
            child.addAttribute(Attribute("id", album.get_id()))
            child.addAttribute(Attribute("title", album.get_name()))
            child.addAttribute(Attribute("cover", album.get_cover()))
            child.addAttribute(Attribute("URL", album.get_uri()))

            songroot = XmlData("songs")

            for song in album._songs:
                songchild = XmlData("song")
                songchild.addAttribute(Attribute("number", song.get_number()))
                songchild.addAttribute(
                    Attribute("filename", song.get_filename()))

                songroot.addChild(songchild)

            child.addChild(songroot)
            albumroot.addChild(child)

        fileroot.addChild(albumroot)

        # pictures
        pictureroot = XmlData("pictures")

        for picture in device.get_pictures():
            child = XmlData("picture")
            child.addAttribute(Attribute("id", picture.get_id()))
            child.addAttribute(Attribute("thumbnail", picture.get_thumbnail()))
            child.addAttribute(Attribute("URL", picture.get_uri()))

            pictureroot.addChild(child)

        fileroot.addChild(pictureroot)

        # movies
        movieroot = XmlData("movies")

        for movie in device.get_movies():
            child = XmlData("movie")
            child.addAttribute(Attribute("id", movie.get_id()))
            child.addAttribute(Attribute("cover", movie.get_cover()))
            child.addAttribute(Attribute("name", movie.get_name()))
            child.addAttribute(Attribute("URL", movie.get_uri()))

            movieroot.addChild(child)

        fileroot.addChild(movieroot)

        XmlGenerator.xmlToFile(fileroot, path + filelist)
Ejemplo n.º 7
0
    def _createXML(self):
        path = config.temp_folder
        deviceroot = XmlData("devices")
        devicelist = "devicelist.xml"

        if not os.path.exists(path):
            os.makedirs(path)

        # iterate thru all devices
        for device in self._devices:
            client = device.get_client()

            child = XmlData("device")
            child.addAttribute(Attribute("type", device.get_type()))
            child.addAttribute(Attribute("id", device.get_uid()))
            child.addAttribute(
                Attribute("name", client.device.get_friendly_name()))

            deviceroot.addChild(child)

        # write the list to xml
        XmlGenerator.xmlToFile(deviceroot, path + devicelist)

        # notify the UI that our xml data has changed
        self._handler.handleEvent(
            Event("ReturnUiData", "UpnpBackend", "DeviceListChanged",
                  path + devicelist))
Ejemplo n.º 8
0
def xmlTest():
    print "xml test set"
    print "create xml data"
    root = XmlData("root")
    child1 = XmlData("child1")
    child1.addAttribute(Attribute("name","gettomaster"))
    child1.addAttribute(Attribute("vip","34"))
    child11 = XmlData("child11")
    child1.addChild(child11)
    root.addChild(child1)
    child2 = XmlData("child2")
    root.addChild(child2)
    print "xml created"
    
    print "create file"
    xmlToFile(root,"data/asdad.xml")
    
    print "read xml from file"
    rootxml = fileToXml("data/asdad.xml")
    print "loaded root node: ",rootxml.name
        
    print "Test get child & attribute functions"
    c1 = rootxml.getChild("child1")
    c1.getAttribute("name")
    try:
        rootxml.getChild("xxx")
        rootxml.getAttribute("yyy")
    except:
        pass
    else:
        print "ERROR: no exception raised."
        
    print "compare results"
    _compareXmlData(root,rootxml)
    print "results compared"