Beispiel #1
0
 def get_avatar(self, jid, sha1hash=None, raw=False):
     jid_md5 = crypto.get_md5(jid)        
     if sha1hash:
         path = os.path.join(self.avatar_dir, "%s_%s" % (jid_md5, sha1hash))            
         if os.path.exists(path):
             if raw:
                 return path
             else:
                 return path_to_uri(path)
         return self.default_avatar
     else:    
         avatar_files = os.listdir(self.avatar_dir)
         for f in avatar_files:
             if f.startswith(jid_md5):
                 path = os.path.join(self.avatar_dir, f)
                 if raw:
                     return path
                 else:
                     return path_to_uri(path)
         return self.default_avatar
Beispiel #2
0
 def get_avatar(self, jid, sha1hash=None, raw=False):
     jid_md5 = crypto.get_md5(jid)
     if sha1hash:
         path = os.path.join(self.avatar_dir, "%s_%s" % (jid_md5, sha1hash))
         if os.path.exists(path):
             if raw:
                 return path
             else:
                 return path_to_uri(path)
         return self.default_avatar
     else:
         avatar_files = os.listdir(self.avatar_dir)
         for f in avatar_files:
             if f.startswith(jid_md5):
                 path = os.path.join(self.avatar_dir, f)
                 if raw:
                     return path
                 else:
                     return path_to_uri(path)
         return self.default_avatar
Beispiel #3
0
    def save_avatar(self, jid, image_data):
        before_avatar = self.get_avatar(jid, raw=True)
        if before_avatar != self.default_avatar:
            try:
                os.remove(before_avatar)
            except Exception:    
                logger.warning("Remove {0} file error".format(before_avatar))

        path = self.avatar_filepath(jid, image_data, need_hash=True)
        if os.path.exists(path):
            return 
        with open(path, 'wb') as fp:
            fp.write(image_data)
        logger.debug("{0} avatar have saved".format(jid))    
        path = path_to_uri(path)
        avatar_saved.send(sender=self, jid=jid, path=path)    
Beispiel #4
0
    def save_avatar(self, jid, image_data):
        before_avatar = self.get_avatar(jid, raw=True)
        if before_avatar != self.default_avatar:
            try:
                os.remove(before_avatar)
            except Exception:
                logger.warning("Remove {0} file error".format(before_avatar))

        path = self.avatar_filepath(jid, image_data, need_hash=True)
        if os.path.exists(path):
            return
        with open(path, 'wb') as fp:
            fp.write(image_data)
        logger.debug("{0} avatar have saved".format(jid))
        path = path_to_uri(path)
        avatar_saved.send(sender=self, jid=jid, path=path)