def myFilter(generator): if tagsMustContainAnyOf: for article in generator.articles: if hasattr(article, 'tags'): tagFound = False for t in article.tags: if t in tagsMustContainAnyOf: tagFound = True break # Found at least one required tag, article must be kept if not tagFound: generator.articles.remove(article) logger.info("Article %s skipped as not contains required tags" % article.title) else: if logger.isEnabledFor(logging.DEBUG): logger.warning("Article %s have no tags" % article.source_path) if tagsMustNotContain: for article in generator.articles: if hasattr(article, 'tags'): for t in article.tags: if t in tagsMustNotContain: generator.articles.remove(article) logger.info("Article %s skipped because has tag %s" % (article.source_path, t)) break
def replacer(m): what = m.group('what') value = m.group('value') origin = m.group('path') if what == 'thumbnail' or what.startswith('thumbnail:'): if what == 'thumbnail': size = content.metadata.get('thumbnail-size') else: size = what.split(':', 1)[1] image = os.path.join(path_prefix, value) if not os.path.isfile(image): logger.warning('Image does not exist: `%s\'.' % value) else: origin = build_url(content, request_thumbnail(value, size, settings), settings) elif what == 'image': image = os.path.join(path_prefix, value) if not os.path.isfile(image): logger.warning('Image does not exist: `%s\'.' % value) else: origin = build_url(content, os.path.join(album_path, value), settings) return ''.join((m.group('markup'), m.group('quote'), origin, m.group('quote')))
def replacer(m): what = m.group('what') value = m.group('value') origin = m.group('path') if what == 'thumbnail' or what.startswith('thumbnail:'): if what == 'thumbnail': size = content.metadata.get('thumbnail-size') else: size = what.split(':', 1)[1] image = os.path.join(path_prefix, value) if not os.path.isfile(image): logger.warning('Image does not exist: `%s\'.' % value) else: origin = build_url(content, request_thumbnail(value, size, settings), settings) elif what == 'image': image = os.path.join(path_prefix, value) if not os.path.isfile(image): logger.warning('Image does not exist: `%s\'.' % value) else: origin = build_url(content, os.path.join(album_path, value), settings) return ''.join( (m.group('markup'), m.group('quote'), origin, m.group('quote')))
def request_thumbnail(image, spec, settings): if settings['THUMBNAIL_OUTPUT_FORMAT'] == 'PNG': ext = 'png' else: ext = 'jpg' if not spec: spec = settings['THUMBNAIL_DEFAULT_SIZE'] if '@' not in spec: quality = settings['THUMBNAIL_DEFAULT_QUALITY'] else: spec, quality = spec.split('@', 1) if 'x' not in spec: size = spec + 'x' + spec else: size = spec try: w, h = map(lambda v: 0 if not v else int(v), size.split('x', 1)) except ValueError: logger.warning('Invalid size for thumbnail %s: %s (using 128x128)' % (image, size)) w, h = 128, 128 try: quality = int(quality) except ValueError: logger.warning('Invalid quality for thumbnail %s: %s (using 80)' % (image, quality)) PENDING_THUMBNAILS.add((image, w, h, quality)) path, filename = os.path.split(image) filename = os.path.splitext(filename)[0] return os.path.join( settings['THUMBNAIL_OUTPUT_PATH'], path, '%dx%d@%d' % (w, h, quality), '%s.%s' % (filename, ext) )
def request_thumbnail(image, spec, settings): if settings['THUMBNAIL_OUTPUT_FORMAT'] == 'PNG': ext = 'png' else: ext = 'jpg' if not spec: spec = settings['THUMBNAIL_DEFAULT_SIZE'] if '@' not in spec: quality = settings['THUMBNAIL_DEFAULT_QUALITY'] else: spec, quality = spec.split('@', 1) if 'x' not in spec: size = spec + 'x' + spec else: size = spec try: w, h = map(lambda v: 0 if not v else int(v), size.split('x', 1)) except ValueError: logger.warning('Invalid size for thumbnail %s: %s (using 128x128)' % (image, size)) w, h = 128, 128 try: quality = int(quality) except ValueError: logger.warning('Invalid quality for thumbnail %s: %s (using 80)' % (image, quality)) PENDING_THUMBNAILS.add((image, w, h, quality)) path, filename = os.path.split(image) filename = os.path.splitext(filename)[0] return os.path.join(settings['THUMBNAIL_OUTPUT_PATH'], path, '%dx%d@%d' % (w, h, quality), '%s.%s' % (filename, ext))