def _process_css(self, css, event): stylesheet = css._localFile path = get_archived_file(stylesheet, self.archive_dirs)[1] if path is None: self.print_error( cformat('%{red!}CSS file not found on disk; skipping it'), event_id=event.id) return with open(path, 'rb') as f: stylesheet_content = convert_to_unicode(f.read()) event.stylesheet_metadata = { 'size': len(stylesheet_content), 'hash': crc32(stylesheet_content), 'filename': secure_filename(convert_to_unicode(stylesheet.fileName), 'stylesheet.css'), 'content_type': 'text/css' } event.stylesheet = stylesheet_content if not self.quiet: self.print_success(cformat('- %{cyan}[CSS] {}').format( stylesheet.fileName), event_id=event.id)
def _process_logo(self, logo, event): path = get_archived_file(logo, self.archive_dirs)[1] if path is None: self.print_error(cformat('%{red!}Logo not found on disk; skipping it'), event_id=event.id) return try: logo_image = Image.open(path) except IOError as e: self.print_warning("Cannot open {}: {}".format(path, e), event_id=event.id) return if logo_image.mode == 'CMYK': self.print_warning("Logo is a CMYK {}; converting to RGB".format(logo_image.format), event_id=event.id) # this may result in wrong colors, but there's not much we can do... logo_image = logo_image.convert('RGB') logo_bytes = BytesIO() logo_image.save(logo_bytes, 'PNG') logo_bytes.seek(0) logo_content = logo_bytes.read() logo_filename = secure_filename(convert_to_unicode(logo.fileName), 'logo') logo_filename = os.path.splitext(logo_filename)[0] + '.png' event.logo_metadata = { 'size': len(logo_content), 'hash': crc32(logo_content), 'filename': logo_filename, 'content_type': 'image/png' } event.logo = logo_content if not self.quiet: self.print_success(cformat('- %{cyan}[Logo] {}').format(logo.fileName), event_id=event.id)
def migrate_event_notes(self): self.print_step('migrating event notes') janitor_user = User.get_one(self.janitor_user_id) self.print_msg('Using janitor user {}'.format(janitor_user), always=True) for event, obj, minutes, special_prot in committing_iterator(self._iter_minutes()): if special_prot: self.print_warning( cformat('%{yellow!}{} minutes have special permissions; skipping them').format(obj), event_id=event.id ) continue path = get_archived_file(minutes, self.archive_dirs)[1] if path is None: self.print_error(cformat('%{red!}{} minutes not found on disk; skipping them').format(obj), event_id=event.id) continue with open(path, 'r') as f: data = convert_to_unicode(f.read()).strip() if not data: self.print_warning(cformat('%{yellow}{} minutes are empty; skipping them').format(obj), always=False, event_id=event.id) continue note = EventNote(linked_object=obj) note.create_revision(RenderMode.html, data, janitor_user) db.session.add(note) if not self.quiet: self.print_success(cformat('%{cyan}{}').format(obj), event_id=event.id)
def _process_css(self, css, event): stylesheet = css._localFile path = get_archived_file(stylesheet, self.archive_dirs)[1] if path is None: self.print_error(cformat('%{red!}CSS file not found on disk; skipping it'), event_id=event.id) return with open(path, 'rb') as f: stylesheet_content = convert_to_unicode(f.read()) event.stylesheet_metadata = { 'size': len(stylesheet_content), 'hash': crc32(stylesheet_content), 'filename': secure_filename(convert_to_unicode(stylesheet.fileName), 'stylesheet.css'), 'content_type': 'text/css' } event.stylesheet = stylesheet_content if not self.quiet: self.print_success(cformat('- %{cyan}[CSS] {}').format(stylesheet.fileName), event_id=event.id)
def _process_icon(self, cat, icon): path = get_archived_file(icon, self.archive_dirs)[1] if path is None: self.print_error( cformat('%{red!}Icon not found on disk; skipping it'), event_id=cat.id) return try: icon_image = Image.open(path) except IOError as e: self.print_warning("Cannot open {}: {}".format(path, e), event_id=cat.id) return if icon_image.mode == 'CMYK': self.print_warning("Icon is a CMYK {}; converting to RGB".format( icon_image.format), always=False, event_id=cat.id) # this may result in wrong colors, but there's not much we can do... icon_image = icon_image.convert('RGB') if icon_image.size != (16, 16): self.print_warning( "Icon is {}x{}; resizing to 16x16".format(*icon_image.size), always=False, event_id=cat.id) icon_image = icon_image.resize((16, 16), Image.ANTIALIAS) icon_bytes = BytesIO() icon_image.save(icon_bytes, 'PNG') icon_bytes.seek(0) icon_content = icon_bytes.read() icon_filename = secure_filename(convert_to_unicode(icon.fileName), 'icon') icon_filename = os.path.splitext(icon_filename)[0] + '.png' cat.icon_metadata = { 'size': len(icon_content), 'hash': crc32(icon_content), 'filename': icon_filename, 'content_type': 'image/png' } cat.icon = icon_content
def _process_icon(self, cat, icon): path = get_archived_file(icon, self.archive_dirs)[1] if path is None: self.print_error(cformat('%{red!}Icon not found on disk; skipping it'), event_id=cat.id) return try: icon_image = Image.open(path) except IOError as e: self.print_warning("Cannot open {}: {}".format(path, e), event_id=cat.id) return if icon_image.mode == 'CMYK': self.print_warning("Icon is a CMYK {}; converting to RGB".format(icon_image.format), always=False, event_id=cat.id) # this may result in wrong colors, but there's not much we can do... icon_image = icon_image.convert('RGB') if icon_image.size != (16, 16): self.print_warning("Icon is {}x{}; resizing to 16x16".format(*icon_image.size), always=False, event_id=cat.id) icon_image = icon_image.resize((16, 16), Image.ANTIALIAS) icon_bytes = BytesIO() icon_image.save(icon_bytes, 'PNG') icon_bytes.seek(0) icon_content = icon_bytes.read() icon_filename = secure_filename(convert_to_unicode(icon.fileName), 'icon') icon_filename = os.path.splitext(icon_filename)[0] + '.png' cat.icon_metadata = { 'size': len(icon_content), 'hash': crc32(icon_content), 'filename': icon_filename, 'content_type': 'image/png' } cat.icon = icon_content