def calc_checksum(theme_id, **kw): """For migration 596.""" lfs = LocalFileStorage() theme = Persona.objects.get(id=theme_id) header = theme.header_path footer = theme.footer_path # Delete invalid themes that are not images (e.g. PDF, EXE). try: Image.open(header) Image.open(footer) except IOError: log.info('Deleting invalid theme [%s] (header: %s) (footer: %s)' % (theme.addon.id, header, footer)) theme.addon.delete() theme.delete() rm_stored_dir(header.replace('header.png', ''), storage=lfs) return # Calculate checksum and save. try: theme.checksum = make_checksum(header, footer) theme.save() except IOError as e: log.error(str(e))
def approve_rereview(theme): """Replace original theme with pending theme on filesystem.""" # If reuploaded theme, replace old theme design. storage = LocalFileStorage() rereview = theme.rereviewqueuetheme_set.all() reupload = rereview[0] if reupload.header_path != reupload.theme.header_path: create_persona_preview_images( src=reupload.header_path, full_dst=[reupload.theme.thumb_path, reupload.theme.icon_path], set_modified_on=reupload.theme.addon.serializable_reference()) if not reupload.theme.is_new(): # Legacy themes also need a preview_large.jpg. # Modern themes use preview.png for both thumb and preview so there # is no problem there. copy_stored_file(reupload.theme.thumb_path, reupload.theme.preview_path, storage=storage) move_stored_file(reupload.header_path, reupload.theme.header_path, storage=storage) theme = reupload.theme rereview.delete() theme_checksum(theme) theme.addon.increment_theme_version_number()
def reject_rereview(theme): """Delete pending theme from filesystem.""" storage = LocalFileStorage() rereview = theme.rereviewqueuetheme_set.all() reupload = rereview[0] storage.delete(reupload.header_path) rereview.delete()
def approve_rereview(theme): """Replace original theme with pending theme on filesystem.""" # If reuploaded theme, replace old theme design. storage = LocalFileStorage() rereview = theme.rereviewqueuetheme_set.all() reupload = rereview[0] if reupload.header_path != reupload.theme.header_path: create_persona_preview_images( src=reupload.header_path, full_dst=[ reupload.theme.thumb_path, reupload.theme.icon_path], set_modified_on=[reupload.theme.addon]) if not reupload.theme.is_new(): # Legacy themes also need a preview_large.jpg. # Modern themes use preview.png for both thumb and preview so there # is no problem there. copy_stored_file(reupload.theme.thumb_path, reupload.theme.preview_path, storage=storage) move_stored_file( reupload.header_path, reupload.theme.header_path, storage=storage) theme = reupload.theme footer_path = theme.footer_path if reupload.footer_path != footer_path: if not footer_path: dst_root = os.path.join(user_media_path('addons'), str(theme.addon.id)) footer_path = os.path.join(dst_root, 'footer.png') theme.footer = 'footer.png' theme.save() move_stored_file( reupload.footer_path, footer_path, storage=storage) rereview.delete() theme.addon.increment_theme_version_number()
def make_checksum(header_path, footer_path): ls = LocalFileStorage() footer = footer_path and ls._open(footer_path).read() or '' raw_checksum = ls._open(header_path).read() + footer return hashlib.sha224(raw_checksum).hexdigest()
def make_checksum(header_path): ls = LocalFileStorage() raw_checksum = ls._open(header_path).read() return hashlib.sha224(raw_checksum).hexdigest()
def setUp(self): super(TestLocalFileStorage, self).setUp() self.tmp = tempfile.mkdtemp(dir=settings.TMP_PATH) self.stor = LocalFileStorage()
def setUp(self): super(TestLocalFileStorage, self).setUp() self.tmp = tempfile.mkdtemp() self.stor = LocalFileStorage()