Example #1
0
    def getInstalledAddInfo( self, addonpath ):
        #TODO: move to InstallMgr?
        """
        Get metadata from addon.xml of an installed addon
        """
        itemInfo = {}

        # Open addon.xml
        xbmc.log("Addon path: %s"%addonpath, xbmc.LOGDEBUG)
        xmlInfofPath = os.path.join( addonpath, "addon.xml")
        if os.path.exists( xmlInfofPath ):
            try:
                xmlData = open( os.path.join( xmlInfofPath ), "r" )
                statusGetInfo = parseAddonXml( xmlData, itemInfo )
                xmlData.close()
            except:
                print_exc()
            if statusGetInfo == "OK":
                iconPath = os.path.join( xmlInfofPath, "icon.png")
                if os.path.exists( iconPath ):
                    itemInfo [ "icon" ] = iconPath
                else:
                    #TODO: move default image selection in the caller code????
                    itemInfo [ "icon" ]="DefaultFolder.png"
        return itemInfo
Example #2
0
def getInstalledAddonInfo(addonpath):
    """
    Get metadata from addon.xml of an installed addon
    """
    itemInfo = {}

    # Open addon.xml
    xbmc.log("getInstalledAddonInfo: Addon path: %s" % addonpath,
             xbmc.LOGDEBUG)
    xmlInfofPath = os.path.join(addonpath, "addon.xml")
    if os.path.exists(xmlInfofPath):
        try:
            xmlData = open(os.path.join(xmlInfofPath), "r")
            statusGetInfo = parseAddonXml(xmlData, itemInfo)
            xmlData.close()
        except:
            print_exc()
        if statusGetInfo == "OK":
            iconPath = os.path.join(xmlInfofPath, "icon.png")
            if os.path.exists(iconPath):
                itemInfo["icon"] = iconPath
            else:
                #TODO: move default image selection in the caller code????
                itemInfo["icon"] = "DefaultFolder.png"
    return itemInfo
Example #3
0
    def setItemInfo( self, itemName=None ):
        """
        Get Type, name

         id
         name
         type
         version
         author
         disclaimer
         summary
         description
         icon
         fanart
         changelog
         library: path of python script
         raw_item_sys_type: file | archive | dir
         raw_item_path
         install_path
         temp_item_path
         provides
         required_lib
        """


        status = 'OK'
        if self.status != "INVALIDNAME":
            itemExtractedPath = self.itemInfo [ "temp_item_path" ]

            try:
                # Retrieve info from addon.xml
                xmlInfofPath = os.path.join( itemExtractedPath, "addon.xml")
                if ( os.path.exists( xmlInfofPath ) ):
                    xmlData = open( os.path.join( xmlInfofPath ), "r" )
                    statusGetInfo = parseAddonXml( xmlData, self.itemInfo )
                    xmlData.close()
                    sleep(3)
                else:
                    xbmc.log("setItemInfo - addon.xml not found", xbmc.LOGNOTICE)
                    status = 'ERROR'

                # Renaming addon's internal files
                if statusGetInfo == "OK":
                    status = self._prepareItem4xbox( self.itemInfo )
                elif statusGetInfo == "NOT_SUPPORTED":
                    xbmc.log("setItemInfo - Addon not supported", xbmc.LOGDEBUG)
                    status = 'NOT_SUPPORTED'
                else:
                    xbmc.log("setItemInfo - Error parsing addon.xml", xbmc.LOGNOTICE)
                    status = 'ERROR'

            except:
                print_exc()
                status = 'ERROR'

        if status in ["OK", "UNCHANGED"]:
            typeInstallPath = get_install_path( self.itemInfo [ "type" ] )
            status = 'OK'

            # Rename directory
            if  self.itemInfo[ "type" ] not in [TYPE_ADDON_MODULE, TYPE_ADDON_REPO]:
                if itemName:
                    newItemPath = self.itemInfo[ "temp_item_path" ].replace(os.path.basename( self.itemInfo[ "temp_item_path" ] ) , itemName )
                else:
                    newItemPath = self.itemInfo[ "temp_item_path" ].replace(os.path.basename( self.itemInfo[ "temp_item_path" ] ) , self.itemInfo[ "name" ] )

                status = self._renameItem4xbox(self.itemInfo, self.itemInfo[ "temp_item_path" ], newItemPath)
                if status == "OK":
                    if itemName:
                        # Overwriting name with the one given by the user
                        self.itemInfo[ "name" ] = itemName
                    self.itemInfo[ "temp_item_path" ] = newItemPath
                    self.itemInfo[ "install_path" ]   = os.path.join( typeInstallPath, self.itemInfo [ "name" ] )
                else:
                    # Rename failed
                    xbmc.log("Rename failed", xbmc.LOGNOTICE)
                    self.itemInfo [ "install_path" ] = os.path.join( typeInstallPath, os.path.basename( self.itemInfo [ "temp_item_path" ] ) )
            else:
                # We don't rename modules and repos
                #self.itemInfo [ "install_path" ] = os.path.join( typeInstallPath, os.path.basename( self.itemInfo [ "id" ] ) )
                self.itemInfo [ "install_path" ] = os.path.join( typeInstallPath, os.path.basename( self.itemInfo [ "id" ][:42] ) ) # xbox filename limitation
        xbmc.log("setItemInfo - status: %s"%status, xbmc.LOGDEBUG)
        return status
Example #4
0
    def setItemInfo(self, itemName=None):
        """
        Get Type, name

         id
         name
         type
         version
         author
         disclaimer
         summary
         description
         icon
         fanart
         changelog
         library: path of python script
         raw_item_sys_type: file | archive | dir
         raw_item_path
         install_path
         temp_item_path
         provides
         required_lib
        """

        status = 'OK'
        if self.status != "INVALIDNAME":
            itemExtractedPath = self.itemInfo["temp_item_path"]

            try:
                # Retrieve info from addon.xml
                xmlInfofPath = os.path.join(itemExtractedPath, "addon.xml")
                if (os.path.exists(xmlInfofPath)):
                    xmlData = open(os.path.join(xmlInfofPath), "r")
                    statusGetInfo = parseAddonXml(xmlData, self.itemInfo)
                    xmlData.close()
                    sleep(3)
                else:
                    xbmc.log("setItemInfo - addon.xml not found",
                             xbmc.LOGNOTICE)
                    status = 'ERROR'

                # Renaming addon's internal files
                if statusGetInfo == "OK":
                    status = self._prepareItem4xbox(self.itemInfo)
                elif statusGetInfo == "NOT_SUPPORTED":
                    xbmc.log("setItemInfo - Addon not supported",
                             xbmc.LOGDEBUG)
                    status = 'NOT_SUPPORTED'
                else:
                    xbmc.log("setItemInfo - Error parsing addon.xml",
                             xbmc.LOGNOTICE)
                    status = 'ERROR'

            except:
                print_exc()
                status = 'ERROR'

        if status in ["OK", "UNCHANGED"]:
            typeInstallPath = get_install_path(self.itemInfo["type"])
            status = 'OK'

            # Rename directory
            if self.itemInfo["type"] not in [
                    TYPE_ADDON_MODULE, TYPE_ADDON_REPO
            ]:
                if itemName:
                    newItemPath = self.itemInfo["temp_item_path"].replace(
                        os.path.basename(self.itemInfo["temp_item_path"]),
                        itemName)
                else:
                    newItemPath = self.itemInfo["temp_item_path"].replace(
                        os.path.basename(self.itemInfo["temp_item_path"]),
                        self.itemInfo["name"])

                status = self._renameItem4xbox(self.itemInfo,
                                               self.itemInfo["temp_item_path"],
                                               newItemPath)
                if status == "OK":
                    if itemName:
                        # Overwriting name with the one given by the user
                        self.itemInfo["name"] = itemName
                    self.itemInfo["temp_item_path"] = newItemPath
                    self.itemInfo["install_path"] = os.path.join(
                        typeInstallPath, self.itemInfo["name"])
                else:
                    # Rename failed
                    xbmc.log("Rename failed", xbmc.LOGNOTICE)
                    self.itemInfo["install_path"] = os.path.join(
                        typeInstallPath,
                        os.path.basename(self.itemInfo["temp_item_path"]))
            else:
                # We don't rename modules and repos
                #self.itemInfo [ "install_path" ] = os.path.join( typeInstallPath, os.path.basename( self.itemInfo [ "id" ] ) )
                self.itemInfo["install_path"] = os.path.join(
                    typeInstallPath, os.path.basename(
                        self.itemInfo["id"][:42]))  # xbox filename limitation
        xbmc.log("setItemInfo - status: %s" % status, xbmc.LOGDEBUG)
        return status