Ejemplo n.º 1
0
    def _download_item( self, forceInstall=True ):
        status = "OK"
        finished_path = None
        try:
            if ( forceInstall ):
                self.dialog.create( self.title, _( 30052 ), _( 30053 ) )
                asset_files = []

                folders = [ self.itemInfo[ "url" ].replace(self.REPO_URL, "").replace( " ", "%20" ) ]
                while folders:
                    try:
                        htmlsource = readURL( self.REPO_URL + folders[ 0 ] )
                        if ( not htmlsource ): raise
                        items = self._parse_html_source( htmlsource )
                        if ( not items or items[ "status" ] == "fail" ): raise
                        files, dirs = self._parse_items( items )
                        for file in files:
                            asset_files.append( folders[ 0 ] + file )

                        for folder in dirs:
                            folders.append( folders[ 0 ] + folder )

                        folders = folders[ 1 : ]
                    except:
                        folders = []
                finished_path = self._get_files( asset_files )
                self.dialog.close()
        except:
            # oops print error message
            print "ERROR: %s::%s (%d) - %s" % ( self.__class__.__name__, sys.exc_info()[ 2 ].tb_frame.f_code.co_name, sys.exc_info()[ 2 ].tb_lineno, sys.exc_info()[ 1 ], )
            self.dialog.close()
            status = "ERROR"
        return status, finished_path
Ejemplo n.º 2
0
    def _download_item(self, forceInstall=True):
        status = "OK"
        finished_path = None
        try:
            if forceInstall:
                self.dialog.create(self.title, _(30052), _(30053))
                asset_files = []

                folders = [self.itemInfo["url"].replace(self.REPO_URL, "").replace(" ", "%20")]
                while folders:
                    try:
                        htmlsource = readURL(self.REPO_URL + folders[0])
                        if not htmlsource:
                            raise
                        items = self._parse_html_source(htmlsource)
                        if not items or items["status"] == "fail":
                            raise
                        files, dirs = self._parse_items(items)
                        for file in files:
                            asset_files.append(folders[0] + file)

                        for folder in dirs:
                            folders.append(folders[0] + folder)

                        folders = folders[1:]
                    except:
                        folders = []
                finished_path = self._get_files(asset_files)
                self.dialog.close()
        except:
            # oops print error message
            print "ERROR: %s::%s (%d) - %s" % (
                self.__class__.__name__,
                sys.exc_info()[2].tb_frame.f_code.co_name,
                sys.exc_info()[2].tb_lineno,
                sys.exc_info()[1],
            )
            self.dialog.close()
            status = "ERROR"
        return status, finished_path
    def _createAddonsDir ( self, repoId, cat ):
        """
        Display the addons to install for a repository
        """
        # Retrieve info from  addon.xml for the repository
        repoInfo = getInstalledAddonInfo( os.path.join( DIR_ADDON_REPO, repoId) )

        addonDic = {}

        # Retrieving addons.xml from remote repository
        xmlInfofPath = os.path.join( DIR_CACHE, repoId + ".xml")
        if fileOlderThan(xmlInfofPath, 60 * 30):
            data = readURL( repoInfo [ "repo_url" ], save=True, localPath=xmlInfofPath )

        if ( os.path.exists( xmlInfofPath ) ):
            try:
                xmlData = open( os.path.join( xmlInfofPath ), "r" )
                listAddonsXml = ListItemFromXML(xmlData)
                xmlData.close()
            except:
                print_exc()

            filter = "False"
            if cat == VALUE_LIST_ALL_ADDONS:
                filter = "item['type'] in supportedAddonList"
            elif cat in supportedAddonList:
                filter = "item['type'] == '%s'"%cat

            keepParsing = True
            while (keepParsing):
                item = listAddonsXml.getNextItem()
                if item:
                    if eval(filter):
                        endRepoChar = "/"
                        if repoInfo [ "repo_datadir" ].endswith( "/" ):
                            endRepoChar = ""

                        if repoInfo [ "repo_format" ] ==  'zip':
                            downloadUrl = (repoInfo [ "repo_datadir" ] + endRepoChar + item["id"] + '/' + item["id"]  + '-' + item["version"] + ".zip").replace(' ', '%20')
                            changelog   = (repoInfo [ "repo_datadir" ] + endRepoChar + item["id"] + '/' + "changelog" + '-' + item["version"] + ".txt").replace(' ', '%20')
                            iconimage   = (repoInfo [ "repo_datadir" ] + endRepoChar + item["id"] + '/' + "icon.png").replace(' ', '%20')
                        else:
                            downloadUrl = (repoInfo [ "repo_datadir" ] + endRepoChar + item["id"] + '/').replace(' ', '%20')
                            changelog   = (repoInfo [ "repo_datadir" ] + endRepoChar + item["id"] + '/' + "changelog" + ".txt").replace(' ', '%20')
                            iconimage   = (repoInfo [ "repo_datadir" ] + endRepoChar + item["id"] + '/' + "icon.png").replace(' ', '%20')
                        item["ImageUrl"] = iconimage
                        item["changelog"] = changelog

                        paramsAddons = {}
                        paramsAddons[PARAM_INSTALL_FROM_REPO]   = "true"
                        paramsAddons[PARAM_ADDON_ID]            = item[ "id" ]
                        paramsAddons[PARAM_ADDON_NAME]          = item['name']
                        paramsAddons[PARAM_URL]                 = downloadUrl
                        paramsAddons[PARAM_DATADIR]             = repoInfo[ "repo_datadir" ]
                        paramsAddons[PARAM_TYPE]                = repoInfo[ "repo_format" ]
                        paramsAddons[PARAM_REPO_ID]             = repoId
                        url = self.pluginMgr.create_param_url( paramsAddons )

                        if ( url ):
                            #self._addLink( item['name'], url, iconimage=iconimage)
                            item["PluginUrl"] = url
                            self.pluginMgr.addItemLink( item )
                            #addonList.append( item )
                            addonDic[ item[ "id" ]] = item
                else:
                    keepParsing = False
            # Save the list of addons
            PersistentDataCreator( addonDic, os.path.join( DIR_CACHE, repoId + ".txt" ) )
Ejemplo n.º 4
0
    def _getAddonRequiredLibs ( self, addonIdList, repoId = None):
        """
        Display the addons to install for a repository
        """
        status = "OK"

        # List of repositories we will look in order to find the required modules
        repoList = [ getInstalledAddonInfo( os.path.join( DIR_ADDON_REPO, REPO_ID_XBMC4XBOX) ) ]
        if repoId:
            repoList.extend( [ getInstalledAddonInfo( os.path.join( DIR_ADDON_REPO, repoId) ) ] )
        repoList.extend( [ getInstalledAddonInfo( os.path.join( DIR_ADDON_REPO, REPO_ID_XBMC) ) ] )

        # Check if required lib already exist - we do an additional check later for non script modules once we have the module name from the addons repo
        addonIdCheck = []
        addonIdCheck.extend(addonIdList)
        for requiredlib in addonIdCheck:
            localLibVersion = isLibInstalled( requiredlib['id'] )
            if localLibVersion:
                xbmc.log("Requested %s version %s - found version %s" % (requiredlib['id'], requiredlib["version"], localLibVersion), xbmc.LOGDEBUG)
                if versionsCmp( localLibVersion, requiredlib["version"] ) >= 0:
                    addonIdList.remove(requiredlib)

                else:
                    installPath = get_install_path( TYPE_ADDON_MODULE )
                    fileMgr().deleteDir( os.path.join( installPath, requiredlib['id'] ) )

        if len(addonIdList) == 0:
            xbmc.log("No required libs", xbmc.LOGDEBUG)
            return "OK"

        # Parse each repository in the list and try to find in it the required module
        if len(addonIdList) > 0:
            allLibsFound = False
            for repoInfo in repoList:
                # Retrieving addons.xml from remote repository
                xmlInfofPath = os.path.join( DIR_CACHE, repoInfo [ "id" ] + ".xml")
                if fileOlderThan(xmlInfofPath, 60 * 30):
                    data = readURL( repoInfo [ "repo_url" ], save=True, localPath=xmlInfofPath )

                if ( os.path.exists( xmlInfofPath ) ):
                    try:
                        xmlData = open( os.path.join( xmlInfofPath ), "r" )
                        listAddonsXml = ListItemFromXML(xmlData)
                        xmlData.close()
                    except:
                        print_exc()

                    keepParsingCurrentRepo = True
                    while (keepParsingCurrentRepo):
                        item = listAddonsXml.getNextItem()
                        if item:
                            if len(addonIdList) > 0:
                                for lib in addonIdList:
                                    if lib["id"] == item['id']:
                                        localLibVersion = isLibInstalled( item['id'], item['type'], item['name'] )
                                        if localLibVersion:
                                            xbmc.log("Requested %s version %s - found version %s" % (requiredlib['id'], requiredlib["version"], localLibVersion), xbmc.LOGDEBUG)
                                            if versionsCmp( localLibVersion, lib["version"] ) >= 0:
                                                addonIdList.remove(lib)
                                                continue
                                            else:
                                                name = item['name']
                                                if item['type'] == TYPE_ADDON_MODULE:
                                                    name = item['id']
                                                installPath = get_install_path( item['type'] )
                                                fileMgr().deleteDir( os.path.join( installPath, name ) )

                                        endRepoChar = "/"
                                        if repoInfo [ "repo_datadir" ].endswith( "/" ):
                                            endRepoChar = ""

                                        if repoInfo [ "repo_format" ] ==  'zip':
                                            downloadUrl = (repoInfo [ "repo_datadir" ] + endRepoChar + item["id"] + '/' + item["id"]  + '-' + item["version"] + ".zip").replace(' ', '%20')
                                            changelog   = (repoInfo [ "repo_datadir" ] + endRepoChar + item["id"] + '/' + "changelog" + '-' + item["version"] + ".txt").replace(' ', '%20')
                                            iconimage   = (repoInfo [ "repo_datadir" ] + endRepoChar + item["id"] + '/' + "icon.png").replace(' ', '%20')
                                        else:
                                            downloadUrl = (repoInfo [ "repo_datadir" ] + endRepoChar + item["id"] + '/').replace(' ', '%20')
                                            changelog   = (repoInfo [ "repo_datadir" ] + endRepoChar + item["id"] + '/' + "changelog" + ".txt").replace(' ', '%20')
                                            iconimage   = (repoInfo [ "repo_datadir" ] + endRepoChar + item["id"] + '/' + "icon.png").replace(' ', '%20')
                                        item["ImageUrl"] = iconimage
                                        item["changelog"] = changelog

                                        xbmc.log("Download URL: %s" % (downloadUrl), xbmc.LOGDEBUG)

                                        # Install lib
                                        installMgr = InstallMgr()
                                        status, itemName, destination, addonInstaller = installMgr.install_from_repo( item['name'].encode('utf8'), downloadUrl, repoInfo[ "repo_format" ], repoInfo[ "repo_datadir" ] )
                                        if status == "OK":
                                            status, destination = addonInstaller.installItem()
                                            if status == "OK":
                                                saveLocalAddonInfo(repoInfo[ "id" ], destination, addonInstaller)
                                            # recursively install further dependencies
                                            requiredLibs = addonInstaller.itemInfo[ "required_lib" ]
                                            if len(requiredLibs) > 0:
                                                status = self._getAddonRequiredLibs ( addonInstaller.itemInfo[ "required_lib" ], repoInfo[ "id" ] )
                                                if status != "OK":
                                                    return status
                                        else:
                                            # Notify user it is impossible to install the current kib and check if he want to continue
                                            if not xbmcgui.Dialog().yesno( item['name'].encode('utf8'), __language__( 30070 ), __language__( 30071 ), __language__( 30072 ) ):
                                                keepParsingCurrentRepo = False
                                                allLibsFound = True
                                                status = "CANCELED"
                                                xbmc.log("User cancelled due to error of a lib install", xbmc.LOGDEBUG)
                                            else:
                                                # User wants to continue
                                                status = "OK"
                                        # Module installed or already installed - Remove it for the list of libs to install
                                        addonIdList.remove(lib)
                            else:
                                # No lib to find remaining
                                keepParsingCurrentRepo = False
                                allLibsFound = True
                        else:
                            keepParsingCurrentRepo = False
                if not allLibsFound:
                    # all libs found, no need to go to parse next repo
                    continue
            if len(addonIdList) > 0:
                xbmc.log("Not all required lib has been installed", xbmc.LOGDEBUG)

                if not xbmcgui.Dialog().yesno( lib['id'], __language__( 30070 ), __language__( 30071 ), __language__( 30072 ) ):
                    xbmc.log("User cancelled due to error of a lib install", xbmc.LOGDEBUG)
                    allLibsFound = True
                    status = "CANCELED"
                else:
                    # User wants to continue

                    # Update list of module which fail to install
                    #self.addMissingModules(addonIdList)
                    addMissingModules2DB(addonIdList)

                    status = "OK"

        return status#, itemName, destination, addonInstaller
Ejemplo n.º 5
0
    def _createAddonsDir(self, repoId, cat):
        """
        Display the addons to install for a repository
        """
        # Retrieve info from  addon.xml for the repository
        repoInfo = getInstalledAddonInfo(os.path.join(DIR_ADDON_REPO, repoId))

        addonDic = {}

        # Retrieving addons.xml from remote repository
        xmlInfofPath = os.path.join(DIR_CACHE, repoId + ".xml")
        if fileOlderThan(xmlInfofPath, 60 * 30):
            data = readURL(repoInfo["repo_url"],
                           save=True,
                           localPath=xmlInfofPath)

        if (os.path.exists(xmlInfofPath)):
            try:
                xmlData = open(os.path.join(xmlInfofPath), "r")
                listAddonsXml = ListItemFromXML(xmlData)
                xmlData.close()
            except:
                print_exc()

            filter = "False"
            if cat == VALUE_LIST_ALL_ADDONS:
                filter = "item['type'] in supportedAddonList"
            elif cat in supportedAddonList:
                filter = "item['type'] == '%s'" % cat

            keepParsing = True
            while (keepParsing):
                item = listAddonsXml.getNextItem()
                if item:
                    if eval(filter):
                        endRepoChar = "/"
                        if repoInfo["repo_datadir"].endswith("/"):
                            endRepoChar = ""

                        if repoInfo["repo_format"] == 'zip':
                            downloadUrl = (repoInfo["repo_datadir"] +
                                           endRepoChar + item["id"] + '/' +
                                           item["id"] + '-' + item["version"] +
                                           ".zip").replace(' ', '%20')
                            changelog = (repoInfo["repo_datadir"] +
                                         endRepoChar + item["id"] + '/' +
                                         "changelog" + '-' + item["version"] +
                                         ".txt").replace(' ', '%20')
                            iconimage = (repoInfo["repo_datadir"] +
                                         endRepoChar + item["id"] + '/' +
                                         "icon.png").replace(' ', '%20')
                        else:
                            downloadUrl = (repoInfo["repo_datadir"] +
                                           endRepoChar + item["id"] +
                                           '/').replace(' ', '%20')
                            changelog = (repoInfo["repo_datadir"] +
                                         endRepoChar + item["id"] + '/' +
                                         "changelog" + ".txt").replace(
                                             ' ', '%20')
                            iconimage = (repoInfo["repo_datadir"] +
                                         endRepoChar + item["id"] + '/' +
                                         "icon.png").replace(' ', '%20')
                        item["ImageUrl"] = iconimage
                        item["changelog"] = changelog

                        paramsAddons = {}
                        paramsAddons[PARAM_INSTALL_FROM_REPO] = "true"
                        paramsAddons[PARAM_ADDON_ID] = item["id"]
                        paramsAddons[PARAM_ADDON_NAME] = item['name']
                        paramsAddons[PARAM_URL] = downloadUrl
                        paramsAddons[PARAM_DATADIR] = repoInfo["repo_datadir"]
                        paramsAddons[PARAM_TYPE] = repoInfo["repo_format"]
                        paramsAddons[PARAM_REPO_ID] = repoId
                        url = self.pluginMgr.create_param_url(paramsAddons)

                        if (url):
                            #self._addLink( item['name'], url, iconimage=iconimage)
                            item["PluginUrl"] = url
                            self.pluginMgr.addItemLink(item)
                            #addonList.append( item )
                            addonDic[item["id"]] = item
                else:
                    keepParsing = False
            # Save the list of addons
            PersistentDataCreator(addonDic,
                                  os.path.join(DIR_CACHE, repoId + ".txt"))