def _upload_or_replace_flickr(self,directory,fn,_tags=None,_megapixels=None,resize_request=None):
<EOL>db=self._loadDB(directory)<EOL>status=False<EOL>replaced=False<EOL>if not _megapixels:<EOL><INDENT>mpstring="<STR_LIT>"<EOL><DEDENT>else:<EOL><INDENT>mpstring=("<STR_LIT>"%(_megapixels))<EOL><DEDENT>if _megapixels:<EOL><INDENT>fp = tempfile.NamedTemporaryFile()<EOL>fullfile_resized=fp.name<EOL>logger.debug("<STR_LIT>"%(fp.name))<EOL><DEDENT>fullfile=os.path.join(directory,fn)<EOL>ext=os.path.splitext(fullfile)[<NUM_LIT:1>].lower()<EOL>if ext=='<STR_LIT>':<EOL><INDENT>isJPG=True<EOL><DEDENT>else:<EOL><INDENT>isJPG=False<EOL><DEDENT>if fn not in db:<EOL><INDENT>if _megapixels and isJPG:<EOL><INDENT>if pusher_utils.resize_image(fullfile,fullfile_resized,_megapixels):<EOL><INDENT>logger.debug("<STR_LIT>"%(fullfile,fullfile_resized))<EOL>fullfile=fullfile_resized<EOL><DEDENT>else:<EOL><INDENT>logger.warning("<STR_LIT>"%(fullfile))<EOL><DEDENT><DEDENT>logger.debug("<STR_LIT>",fn,_tags)<EOL>print(("<STR_LIT>"%(fn,_tags,mpstring)))<EOL>uplxml=self.flickr.upload(filename=fullfile,<EOL>tags=_tags,format='<STR_LIT>')<EOL>if uplxml.attrib['<STR_LIT>']!='<STR_LIT>':<EOL><INDENT>print(("<STR_LIT>",fn,uplxml.attrib['<STR_LIT>']));<EOL>status=False<EOL>replaced=False<EOL>return status,replaced<EOL><DEDENT>pid=uplxml.find('<STR_LIT>').text<EOL>db[fn]={}<EOL>db[fn]['<STR_LIT>']=pid<EOL>logger.debug("<STR_LIT>",fn,pid);<EOL>status=True<EOL>replaced=False<EOL><DEDENT>else:<EOL><INDENT>pid=db[fn]['<STR_LIT>']<EOL>if resize_request and isJPG:<EOL><INDENT>if self._already_resized_on_flickr(fullfile,pid,_megapixels):<EOL><INDENT>status=True<EOL>replaced=True<EOL>logger.info('<STR_LIT>'%(fn))<EOL>return status,replaced<EOL><DEDENT><DEDENT>if _megapixels and isJPG:<EOL><INDENT>if pusher_utils.resize_image(fullfile,fullfile_resized,_megapixels):<EOL><INDENT>logger.debug("<STR_LIT>"%(fullfile,fullfile_resized))<EOL>fullfile=fullfile_resized<EOL><DEDENT>else:<EOL><INDENT>logger.warning("<STR_LIT>"%(fullfile))<EOL><DEDENT><DEDENT>logger.info("<STR_LIT>",fn,pid)<EOL>uplxml=self.flickr.replace(filename=fullfile,photo_id=pid)<EOL>if uplxml.attrib['<STR_LIT>']!='<STR_LIT>':<EOL><INDENT>print(("<STR_LIT>",uplxml.attrib['<STR_LIT>']));<EOL>status=False<EOL>replaced=False<EOL>return status,replaced<EOL><DEDENT>else:<EOL><INDENT>replaced=True<EOL>status=True<EOL><DEDENT><DEDENT>self._saveDB(directory,db)<EOL>return status,replaced<EOL>
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)