Does the actual upload to flickr.
        if resize_request, will resize picture only if
        it already exists and the geometry on flickr doesn't match
        what we want,
        returns (status,replaced)

def _upload_or_replace_flickr(self,directory,fn,_tags=None,\
            _megapixels=None,resize_request=None):
        """Does the actual upload to flickr.
        if resize_request, will resize picture only if
        it already exists and the geometry on flickr doesn't match
        what we want,
        returns (status,replaced)"""
        # We should check here if 
        db=self._loadDB(directory)

        status=False
        replaced=False

        if not _megapixels:
            mpstring="original"
        else:
            mpstring=("%0.1f MP"%(_megapixels))

        # If resize request, make tempfile and
        # resize.
        if _megapixels:
            fp = tempfile.NamedTemporaryFile()
            fullfile_resized=fp.name
            logger.debug("tempfile for resized is %s"%(fp.name))

        fullfile=os.path.join(directory,fn)

        ext=os.path.splitext(fullfile)[1].lower()
        # If JPEG, then resize
        if ext=='.jpg':
            isJPG=True
        else:
            isJPG=False
            

        # Possibly scale before uploading
        if fn not in db:
            # Do we have to resize?
            if _megapixels and isJPG:
                if pusher_utils.resize_image(fullfile,fullfile_resized,_megapixels):
                    logger.debug("%s resized to %s successfully"\
                            %(fullfile,fullfile_resized))
                    fullfile=fullfile_resized
                else:
                    logger.warning("%s couldn't resize, uploading original"\
                            %(fullfile))

            logger.debug("Upload %s to flickr, tags=%s",fn,_tags)

            print("%s - Uploading to flickr, tags[%s] size=%s"\
                    %(fn,_tags,mpstring))

            # Do the actual upload
            uplxml=self.flickr.upload(filename=fullfile,\
                    #title=_title,\
                    tags=_tags,\
                    format='etree')

            if uplxml.attrib['stat']!='ok':
                print("%s - flickr: upload failed with status: %s",\
                        fn,uplxml.attrib['stat']);
                status=False
                replaced=False
                return status,replaced

            pid=uplxml.find('photoid').text
            db[fn]={}
            db[fn]['photoid']=pid
            logger.debug("%s - flickr: uploaded with photoid %s",fn,pid);
            status=True
            replaced=False
        else:
            # File already exists, let's replace it.
            pid=db[fn]['photoid']
            # If this is an actual resize request,
            # go check geometry on flickr and resize
            # if it hasn't been already
            if resize_request and isJPG:
                if self._already_resized_on_flickr(fullfile,pid,_megapixels):
                    status=True
                    replaced=True
                    logger.info(\
                            '%s - flickr: already correct size - skipping'\
                            %(fn))
                    # File already resized, skip it.
                    return status,replaced

            # If megapixels given, will resize image
            if _megapixels and isJPG:
                if pusher_utils.resize_image(fullfile,fullfile_resized,_megapixels):
                    logger.debug("%s resized to %s successfully"\
                            %(fullfile,fullfile_resized))
                    fullfile=fullfile_resized
                else:
                    logger.warning("%s couldn't resize, uploading original"\
                            %(fullfile))
                    
            logger.info("%s - Replace on flickr pid=%s",fn,pid)
            uplxml=self.flickr.replace(filename=fullfile,photo_id=pid)
            if uplxml.attrib['stat']!='ok':
                print("%s - flickr: replace failed with status: %s",\
                        uplxml.attrib['stat']);
                status=False
                replaced=False
                return status,replaced
            else:
                replaced=True
                status=True

        # We should check here if 
        self._saveDB(directory,db)
        return status,replaced