def get_avatar(self, username): """ username: `username` field in db.rcontact""" if not self._use_avt: return None username = ensure_bin_str(username) filename = md5(username) dir1, dir2 = filename[:2], filename[2:4] filename = os.path.join(dir1, dir2, "user_{}.png".format(filename)) try: try: if self.avt_use_db: pos, size = self.query_index(filename) return self.read_img(pos, size) else: img_file = os.path.join(self.avt_dir, filename) if os.path.exists(img_file): return Image.open(img_file) else: return None except TypeError: logger.warn("Avatar for {} not found in avatar database.".format(username)) return None except Exception as e: raise print e logger.warn("Failed to retrieve avatar!") return None
def get_avatar(self, username): """ username: `username` field in db.rcontact""" username = ensure_bin_str(username) filename = md5(username) dir1, dir2 = filename[:2], filename[2:4] filename = os.path.join(dir1, dir2, "user_{}.png.bm".format(filename)) index_avatar = self.query_index(filename) if index_avatar == -1: logger.warn("Avatar not found for {}".format(username)) return None else: img = self.read_bm_block(index_avatar) return img
def get_avatar(self, username): """ username: `username` field in db.rcontact""" username = ensure_bin_str(username) filename = md5(username) dir1, dir2 = filename[:2], filename[2:4] filename = os.path.join(dir1, dir2, "user_{}.png".format(filename)) try: try: pos, size = self.query_index(filename) except TypeError: logger.warn("Avatar for {} not found in avatar database.".format(username)) return None return self.read_img(pos, size) except Exception as e: raise print e logger.warn("Failed to retrieve avatar!") return None
def get_avatar(self, username): """ username: `username` field in db.rcontact""" username = ensure_bin_str(username) filename = md5(username) dir1, dir2 = filename[:2], filename[2:4] filename = os.path.join(dir1, dir2, "user_{}.png".format(filename)) try: try: pos, size = self.query_index(filename) except TypeError: logger.warn( "Avatar for {} not found in avatar database.".format( username)) return None return self.read_img(pos, size) except Exception as e: raise print e logger.warn("Failed to retrieve avatar!") return None