def convert(self): cur = self.db.urls.find({"link_type": 2, "info.title": {"$exists": 1}}) for row in cur: if not os.path.exists(row["long_url"]): continue filename = os.path.basename(row["info"]["title"]) print "%s: %s->%s" % (row["short_code"], row["long_url"], filename) with open(row["long_url"], "r") as fh: uf = UploadedFile( None, stream=fh, mimetype=row["mime_type"], filename=filename) uf._update_filenames() if uf.get_filename() == row["long_url"]: print "\tskipping new format" continue uf.save() row["long_url"] = uf.get_filename() self.db.urls.update({"short_code": row["short_code"]}, row)
def convert(self): cur = self.db.urls.find({'link_type': 2}) for row in cur: if not os.path.exists(row['long_url']): continue filename = os.path.basename(row["info"]["title"]) print '%s: thumbnailing %s' % (row['short_code'], filename) with open(row["long_url"], "r") as fh: uf = UploadedFile( None, stream=fh, mimetype=row["mime_type"], filename=filename) uf._update_filenames() if os.path.exists(uf.thumb_filename) and \ os.path.exists(uf.tiny_thumb_filename): print '\tskipping existing thumb' continue uf._create_thumbnail()