Example #1
0
File: tree.py Project: cClaude/xppr
    def _upload_picture(self):
        """Upload photos to Picasa."""
        tree = Tree()
        userid = tree.userid
        token = tree.token
        client = tree.client
        
        # here user already logged in because action can run only from within
        if token == NOLOGIN:
            return Response(Response.ERROR, self.get_str(30409))

        # select photo to upload
        photo = self.get_user_input('picture', self.get_str(30304), True)
        if photo is None:
            return Response(Response.SUCCESS)

        self.log(self.__class__, "selected path: " + repr(photo))

        # get list of own albums
        result = tree.list_directory(AlbumsOfUser(userid))
        if result.status == Response.ERROR:
            return result
        
        # select album to upload to, or create new
        albums = [n for n in result.nodes if n.get_type() == 'album']
        album_names = ["<%s>" % self.get_str(30500),] + [a.title for a in albums]

        index = self.get_user_input('select', self.get_str(30302), album_names)
        if index == -1:
            return Response(Response.SUCCESS)                
        elif index == 0:
            new = self.get_user_input('string', self.get_str(30303))
            if new is None:
                return Response(Response.SUCCESS)

            try:
                url = NodeUrl(userid=userid)
                album = client.create_album(url.get_url(), new, token=token)
                albumid = album.gphoto_id
            except picasaclient.RequestError, err:
                return Response(Response.ERROR, str(err))
Example #2
0
File: tree.py Project: cClaude/xppr
            try:
                url = NodeUrl(userid=userid)
                album = client.create_album(url.get_url(), new, token=token)
                albumid = album.gphoto_id
            except picasaclient.RequestError, err:
                return Response(Response.ERROR, str(err))
        else:
            albumid = albums[index-1].gid

        # upload photo
        try:
            self.start_progress(self.get_str(30412))
            for i, p in enumerate(photo):
                self.update_progress(int(100.0*i/len(photo)), p)
                url = NodeUrl(userid=userid, albumid=albumid)
                client.insert_photo(url.get_url(), p, token)
        except picasaclient.RequestError, err:
            self.close_progress()
            return Response(Response.ERROR, str(err))

        self.update_progress(100)
        self.close_progress()
        
        return Response(Response.SUCCESS, self.get_str(30408))

    #----------------------------------------------------------------------
    def _show_map(self, n_url):
        """"""
        lat, lon = n_url.get_query('pos').split()
        
        m_source = self.get_option('map_source')