コード例 #1
0
    def __init__(self, *args, **kwargs):
        Browser.__init__(self, *args, **kwargs)

        # Creation du configCtrl
        from CONF import configCtrl
        self.configManager = configCtrl()
        if not self.configManager.is_conf_valid: raise

        self.host = self.configManager.host
        self.user = self.configManager.user
        self.password = self.configManager.password
        self.remotedirList = self.configManager.remotedirList

        #self.localdirList       = self.configManager.localdirList
        #self.downloadTypeList   = self.configManager.downloadTypeLst

        self.racineDisplayList = [
            Item.TYPE_SKIN, Item.TYPE_SCRAPER, Item.TYPE_SCRIPT,
            Item.TYPE_PLUGIN
        ]
        self.pluginDisplayList = [
            Item.TYPE_PLUGIN_MUSIC, Item.TYPE_PLUGIN_PICTURES,
            Item.TYPE_PLUGIN_PROGRAMS, Item.TYPE_PLUGIN_VIDEO
        ]
        self.scraperDisplayList = [
            Item.TYPE_SCRAPER_MUSIC, Item.TYPE_SCRAPER_VIDEO
        ]

        self.connected = False  # status de la connection ( inutile pour le moment )
        self.index = ""
        self.rightstest = ""
        self.CACHEDIR = self.configManager.CACHEDIR

        # Connection to FTP server
        try:

            self.passionFTPCtrl = FtpDownloadCtrl(self.host, self.user,
                                                  self.password,
                                                  self.remotedirList,
                                                  self.CACHEDIR)
            self.connected = True
        except:
            print "PassionFtpBrowser::__init__: Exception durant la connection FTP"
            print "Impossible de se connecter au serveur FTP: %s" % self.host
            print_exc()

        # Creons ItemInfosManager afin de recuperer les descriptions des items
        self.itemInfosManager = ItemInfosManager(mainwin=self)
        self.infoswarehouse = self.itemInfosManager.get_info_warehouse()
コード例 #2
0
    def __init__(self, *args, **kwargs):
        Browser.__init__(self, *args, **kwargs)

        # Creation du configCtrl
        from CONF import configCtrl

        self.configManager = configCtrl()
        if not self.configManager.is_conf_valid:
            raise

        self.host = self.configManager.host
        self.user = self.configManager.user
        self.password = self.configManager.password
        self.remotedirList = self.configManager.remotedirList

        # self.localdirList       = self.configManager.localdirList
        # self.downloadTypeList   = self.configManager.downloadTypeLst

        self.racineDisplayList = [Item.TYPE_SKIN, Item.TYPE_SCRAPER, Item.TYPE_SCRIPT, Item.TYPE_PLUGIN]
        self.pluginDisplayList = [
            Item.TYPE_PLUGIN_MUSIC,
            Item.TYPE_PLUGIN_PICTURES,
            Item.TYPE_PLUGIN_PROGRAMS,
            Item.TYPE_PLUGIN_VIDEO,
        ]
        self.scraperDisplayList = [Item.TYPE_SCRAPER_MUSIC, Item.TYPE_SCRAPER_VIDEO]

        self.connected = False  # status de la connection ( inutile pour le moment )
        self.index = ""
        self.rightstest = ""
        self.CACHEDIR = self.configManager.CACHEDIR

        # Connection to FTP server
        try:

            self.passionFTPCtrl = FtpDownloadCtrl(
                self.host, self.user, self.password, self.remotedirList, self.CACHEDIR
            )
            self.connected = True
        except:
            print "PassionFtpBrowser::__init__: Exception durant la connection FTP"
            print "Impossible de se connecter au serveur FTP: %s" % self.host
            print_exc()

        # Creons ItemInfosManager afin de recuperer les descriptions des items
        self.itemInfosManager = ItemInfosManager(mainwin=self)
        self.infoswarehouse = self.itemInfosManager.get_info_warehouse()
コード例 #3
0
class PassionFtpBrowser(Browser):
    """
    Browser FTP server using FTP command and display information about item stored in the database
    """

    #    def __init__(self):
    def __init__(self, *args, **kwargs):
        Browser.__init__(self, *args, **kwargs)

        # Creation du configCtrl
        from CONF import configCtrl

        self.configManager = configCtrl()
        if not self.configManager.is_conf_valid:
            raise

        self.host = self.configManager.host
        self.user = self.configManager.user
        self.password = self.configManager.password
        self.remotedirList = self.configManager.remotedirList

        # self.localdirList       = self.configManager.localdirList
        # self.downloadTypeList   = self.configManager.downloadTypeLst

        self.racineDisplayList = [Item.TYPE_SKIN, Item.TYPE_SCRAPER, Item.TYPE_SCRIPT, Item.TYPE_PLUGIN]
        self.pluginDisplayList = [
            Item.TYPE_PLUGIN_MUSIC,
            Item.TYPE_PLUGIN_PICTURES,
            Item.TYPE_PLUGIN_PROGRAMS,
            Item.TYPE_PLUGIN_VIDEO,
        ]
        self.scraperDisplayList = [Item.TYPE_SCRAPER_MUSIC, Item.TYPE_SCRAPER_VIDEO]

        self.connected = False  # status de la connection ( inutile pour le moment )
        self.index = ""
        self.rightstest = ""
        self.CACHEDIR = self.configManager.CACHEDIR

        # Connection to FTP server
        try:

            self.passionFTPCtrl = FtpDownloadCtrl(
                self.host, self.user, self.password, self.remotedirList, self.CACHEDIR
            )
            self.connected = True
        except:
            print "PassionFtpBrowser::__init__: Exception durant la connection FTP"
            print "Impossible de se connecter au serveur FTP: %s" % self.host
            print_exc()

        # Creons ItemInfosManager afin de recuperer les descriptions des items
        self.itemInfosManager = ItemInfosManager(mainwin=self)
        self.infoswarehouse = self.itemInfosManager.get_info_warehouse()

    def reset(self):
        """
        Reset the browser (back to start page)
        """
        Browser.reset()

    def _createRootList(self):
        """
        Create and return the root list (all type available)
        Returns list and name of the list
        """
        list = []
        listTitle = _(10)

        # List the main categorie at the root level
        for cat in self.racineDisplayList:
            item = {}
            # item['id']                = ""
            item["name"] = Item.get_type_title(cat)
            # item['parent']            = self.type
            item["downloadurl"] = None
            item["type"] = "CAT"
            item["xbmc_type"] = cat
            item["previewpictureurl"] = None
            item["description"] = Item.get_type_title(cat)
            item["language"] = ""
            item["version"] = ""
            item["author"] = ""
            item["date"] = ""
            item["added"] = ""
            item["thumbnail"] = Item.get_thumb(cat)
            item["previewpicture"] = ""  # Item.get_thumb( cat )
            item[
                "image2retrieve"
            ] = (
                False
            )  # Temporary patch for reseting the flag after download (would be better in the thread in charge of the download)

            list.append(item)
            print item

        return listTitle, list

    def _createPluginList(self):
        """
        Create and return the list of plugin types
        Returns list and name of the list
        """
        list = []
        listTitle = Item.get_type_title(Item.TYPE_PLUGIN)

        # List all the type of plugins
        for cat in self.pluginDisplayList:
            item = {}
            # item['id']                = ""
            # item['parent']            = Item.TYPE_PLUGIN
            item["name"] = Item.get_type_title(cat)
            item["downloadurl"] = None
            item["type"] = "CAT"
            item["xbmc_type"] = cat
            item["previewpictureurl"] = None
            item["description"] = Item.get_type_title(cat)
            item["language"] = ""
            item["version"] = ""
            item["author"] = ""
            item["date"] = ""
            item["added"] = ""
            item["thumbnail"] = Item.get_thumb(cat)
            item["previewpicture"] = ""  # Item.get_thumb( cat )
            item[
                "image2retrieve"
            ] = (
                False
            )  # Temporary patch for reseting the flag after download (would be better in the thread in charge of the download)

            list.append(item)
            print item

        return listTitle, list

    def _createScraperList(self):
        """
        Create and return the list of scraper types
        Returns list and name of the list
        """
        list = []
        listTitle = Item.get_type_title(Item.TYPE_SCRAPER)

        # List all the type of plugins
        for cat in self.scraperDisplayList:
            item = {}
            item["name"] = Item.get_type_title(cat)
            item["downloadurl"] = None
            item["type"] = "CAT"
            item["xbmc_type"] = cat
            item["previewpictureurl"] = None
            item["description"] = Item.get_type_title(cat)
            item["language"] = ""
            item["version"] = ""
            item["author"] = ""
            item["date"] = ""
            item["added"] = ""
            item["thumbnail"] = Item.get_thumb(cat)
            item["previewpicture"] = ""  # Item.get_thumb( cat )
            item[
                "image2retrieve"
            ] = (
                False
            )  # Temporary patch for reseting the flag after download (would be better in the thread in charge of the download)

            list.append(item)
            print item

        return listTitle, list

    def _setDefaultImages(self, item):
        """
        Set the images with default value depending on the type of the item
        """
        print "_setDefaultImages"
        print item["previewpictureurl"]
        if item["previewpictureurl"] == "None":
            # No picture available -> use default one
            item["thumbnail"] = Item.get_thumb(item["xbmc_type"])  # icone
            item["previewpicture"] = ""  # Item.THUMB_NOT_AVAILABLE # preview
        else:
            # Check if picture is already downloaded and available
            downloadImage = False
            thumbnail, checkPathPic = set_cache_thumb_name(item["previewpictureurl"])
            if thumbnail and os.path.isfile(thumbnail):
                item["thumbnail"] = thumbnail
            else:
                item["thumbnail"] = Item.THUMB_NOT_AVAILABLE
                downloadImage = True

            if os.path.exists(checkPathPic):
                item["previewpicture"] = checkPathPic
            else:
                item["previewpicture"] = ""  # Item.THUMB_NOT_AVAILABLE
                downloadImage = True

            if downloadImage == True:
                # Set flag for download (separate thread)
                item["image2retrieve"] = True

    def _downloadImage(self, picname):
        """
        Download picture from the server, save it, create the thumbnail and return path of it
        """
        print "_downloadImage %s" % picname
        try:

            filetodlUrl = picname  # image path on FTP server
            print "filetodlUrl"
            print filetodlUrl
            thumbnail, localFilePath = set_cache_thumb_name(picname)
            print thumbnail
            print localFilePath

            # Retrieve image
            if not self.passionFTPCtrl.downloadImage(filetodlUrl, localFilePath):
                print "ERROR while retrieving image via FTP"
                thumbnail, localFilePath = "", ""

            # remove file if size is 0 bytes and report error if exists error
            if localFilePath and os.path.isfile(localFilePath):
                if os.path.getsize(localFilePath) <= 0:
                    os.remove(localFilePath)
                    # TODO: create a thumb for the default image?
                    # TODO: return empty and manage default image at the level of the caller
                    thumbnail = ""
                else:
                    thumb_size = int(self.thumb_size_on_load)
                    thumbnail = makeThumbnails(localFilePath, thumbnail, w_h=(thumb_size, thumb_size))
                    if thumbnail == "":
                        thumbnail = localFilePath

            #            if thumbnail and os.path.isfile( thumbnail ) and hasattr( listitem, "setThumbnailImage" ):
            #                listitem.setThumbnailImage( thumbnail )
            else:
                thumbnail, localFilePath = "", ""
        except Exception, e:
            # TODO: create a thumb for the default image?
            # TODO: return empty and manage default image at the level of the caller
            thumbnail, localFilePath = "", ""
            print "_downloadImage: Exception - Impossible to download the picture: %s" % picname
            print_exc()
        print "thumbnail = %s" % thumbnail
        print "localFilePath = %s" % localFilePath
        return thumbnail, localFilePath
コード例 #4
0
class PassionFtpBrowser(Browser):
    """
    Browser FTP server using FTP command and display information about item stored in the database
    """

    #    def __init__(self):
    def __init__(self, *args, **kwargs):
        Browser.__init__(self, *args, **kwargs)

        # Creation du configCtrl
        from CONF import configCtrl
        self.configManager = configCtrl()
        if not self.configManager.is_conf_valid: raise

        self.host = self.configManager.host
        self.user = self.configManager.user
        self.password = self.configManager.password
        self.remotedirList = self.configManager.remotedirList

        #self.localdirList       = self.configManager.localdirList
        #self.downloadTypeList   = self.configManager.downloadTypeLst

        self.racineDisplayList = [
            Item.TYPE_SKIN, Item.TYPE_SCRAPER, Item.TYPE_SCRIPT,
            Item.TYPE_PLUGIN
        ]
        self.pluginDisplayList = [
            Item.TYPE_PLUGIN_MUSIC, Item.TYPE_PLUGIN_PICTURES,
            Item.TYPE_PLUGIN_PROGRAMS, Item.TYPE_PLUGIN_VIDEO
        ]
        self.scraperDisplayList = [
            Item.TYPE_SCRAPER_MUSIC, Item.TYPE_SCRAPER_VIDEO
        ]

        self.connected = False  # status de la connection ( inutile pour le moment )
        self.index = ""
        self.rightstest = ""
        self.CACHEDIR = self.configManager.CACHEDIR

        # Connection to FTP server
        try:

            self.passionFTPCtrl = FtpDownloadCtrl(self.host, self.user,
                                                  self.password,
                                                  self.remotedirList,
                                                  self.CACHEDIR)
            self.connected = True
        except:
            print "PassionFtpBrowser::__init__: Exception durant la connection FTP"
            print "Impossible de se connecter au serveur FTP: %s" % self.host
            print_exc()

        # Creons ItemInfosManager afin de recuperer les descriptions des items
        self.itemInfosManager = ItemInfosManager(mainwin=self)
        self.infoswarehouse = self.itemInfosManager.get_info_warehouse()

    def reset(self):
        """
        Reset the browser (back to start page)
        """
        Browser.reset()

    def _createRootList(self):
        """
        Create and return the root list (all type available)
        Returns list and name of the list
        """
        list = []
        listTitle = _(10)

        # List the main categorie at the root level
        for cat in self.racineDisplayList:
            item = {}
            #item['id']                = ""
            item['name'] = Item.get_type_title(cat)
            #item['parent']            = self.type
            item['downloadurl'] = None
            item['type'] = 'CAT'
            item['xbmc_type'] = cat
            item['previewpictureurl'] = None
            item['description'] = Item.get_type_title(cat)
            item['language'] = ""
            item['version'] = ""
            item['author'] = ""
            item['date'] = ""
            item['added'] = ""
            item['thumbnail'] = Item.get_thumb(cat)
            item['previewpicture'] = ""  #Item.get_thumb( cat )
            item[
                'image2retrieve'] = False  # Temporary patch for reseting the flag after download (would be better in the thread in charge of the download)

            list.append(item)
            print item

        return listTitle, list

    def _createPluginList(self):
        """
        Create and return the list of plugin types
        Returns list and name of the list
        """
        list = []
        listTitle = Item.get_type_title(Item.TYPE_PLUGIN)

        # List all the type of plugins
        for cat in self.pluginDisplayList:
            item = {}
            #item['id']                = ""
            #item['parent']            = Item.TYPE_PLUGIN
            item['name'] = Item.get_type_title(cat)
            item['downloadurl'] = None
            item['type'] = 'CAT'
            item['xbmc_type'] = cat
            item['previewpictureurl'] = None
            item['description'] = Item.get_type_title(cat)
            item['language'] = ""
            item['version'] = ""
            item['author'] = ""
            item['date'] = ""
            item['added'] = ""
            item['thumbnail'] = Item.get_thumb(cat)
            item['previewpicture'] = ""  #Item.get_thumb( cat )
            item[
                'image2retrieve'] = False  # Temporary patch for reseting the flag after download (would be better in the thread in charge of the download)

            list.append(item)
            print item

        return listTitle, list

    def _createScraperList(self):
        """
        Create and return the list of scraper types
        Returns list and name of the list
        """
        list = []
        listTitle = Item.get_type_title(Item.TYPE_SCRAPER)

        # List all the type of plugins
        for cat in self.scraperDisplayList:
            item = {}
            item['name'] = Item.get_type_title(cat)
            item['downloadurl'] = None
            item['type'] = 'CAT'
            item['xbmc_type'] = cat
            item['previewpictureurl'] = None
            item['description'] = Item.get_type_title(cat)
            item['language'] = ""
            item['version'] = ""
            item['author'] = ""
            item['date'] = ""
            item['added'] = ""
            item['thumbnail'] = Item.get_thumb(cat)
            item['previewpicture'] = ""  #Item.get_thumb( cat )
            item[
                'image2retrieve'] = False  # Temporary patch for reseting the flag after download (would be better in the thread in charge of the download)

            list.append(item)
            print item

        return listTitle, list

    def _setDefaultImages(self, item):
        """
        Set the images with default value depending on the type of the item
        """
        print "_setDefaultImages"
        print item['previewpictureurl']
        if item['previewpictureurl'] == 'None':
            # No picture available -> use default one
            item['thumbnail'] = Item.get_thumb(item['xbmc_type'])  # icone
            item['previewpicture'] = ""  #Item.THUMB_NOT_AVAILABLE # preview
        else:
            # Check if picture is already downloaded and available
            downloadImage = False
            thumbnail, checkPathPic = set_cache_thumb_name(
                item['previewpictureurl'])
            if thumbnail and os.path.isfile(thumbnail):
                item['thumbnail'] = thumbnail
            else:
                item['thumbnail'] = Item.THUMB_NOT_AVAILABLE
                downloadImage = True

            if os.path.exists(checkPathPic):
                item['previewpicture'] = checkPathPic
            else:
                item['previewpicture'] = ""  #Item.THUMB_NOT_AVAILABLE
                downloadImage = True

            if downloadImage == True:
                # Set flag for download (separate thread)
                item['image2retrieve'] = True

    def _downloadImage(self, picname):
        """
        Download picture from the server, save it, create the thumbnail and return path of it
        """
        print "_downloadImage %s" % picname
        try:

            filetodlUrl = picname  # image path on FTP server
            print "filetodlUrl"
            print filetodlUrl
            thumbnail, localFilePath = set_cache_thumb_name(picname)
            print thumbnail
            print localFilePath

            # Retrieve image
            if not self.passionFTPCtrl.downloadImage(filetodlUrl,
                                                     localFilePath):
                print "ERROR while retrieving image via FTP"
                thumbnail, localFilePath = "", ""

            # remove file if size is 0 bytes and report error if exists error
            if localFilePath and os.path.isfile(localFilePath):
                if os.path.getsize(localFilePath) <= 0:
                    os.remove(localFilePath)
                    #TODO: create a thumb for the default image?
                    #TODO: return empty and manage default image at the level of the caller
                    thumbnail = ""
                else:
                    thumb_size = int(self.thumb_size_on_load)
                    thumbnail = makeThumbnails(localFilePath,
                                               thumbnail,
                                               w_h=(thumb_size, thumb_size))
                    if thumbnail == "": thumbnail = localFilePath

#            if thumbnail and os.path.isfile( thumbnail ) and hasattr( listitem, "setThumbnailImage" ):
#                listitem.setThumbnailImage( thumbnail )
            else:
                thumbnail, localFilePath = "", ""
        except Exception, e:
            #TODO: create a thumb for the default image?
            #TODO: return empty and manage default image at the level of the caller
            thumbnail, localFilePath = "", ""
            print "_downloadImage: Exception - Impossible to download the picture: %s" % picname
            print_exc()
        print "thumbnail = %s" % thumbnail
        print "localFilePath = %s" % localFilePath
        return thumbnail, localFilePath