示例#1
0
def process_copy_jobs(site, config, write_list):
    logger = logging.getLogger('roxy')
    config = configure.current_config()
    for j in _copy_queue:
        for src, dest in j(site):
            logger.info("copying {} ▶ {}".format(src, dest))
            util.copy(src, (config['build_path'], dest))
示例#2
0
        def fit(*args, **kwargs):
            config = configure.current_config()
            assets = fn(*args, **kwargs)
            contexts = []
            for asset in assets:
                for size, params in sizes.items():
                    path = os.path.join(config['asset_source_path'], asset.path)
                    image = Image.open(path)

                    bounds = [min(image.size[i], params[i]) for i in range(2)]
                    preview = ImageOps.fit(image, bounds, method=Image.ANTIALIAS)
                    values = {
                        'filename': asset.filename,
                        'size': size,
                        'extension': fmt.lower()
                    }

                    _, path = tempfile.mkstemp(suffix='.'+fmt.lower())

                    def setter(path, size=size):
                        setattr(asset, size, path)
                        session = get_session()
                        session.add(asset)

                    with open(path, 'rb') as f:
                        preview.save(path, format=fmt)
                        contexts.append((path, values, setter))

            return contexts
示例#3
0
        def queued_copy(*args, **kwargs):
            config = configure.current_config()
            jobs = fn(*args, **kwargs)
            to_copy = []
            for j in jobs:
                if len(j) == 2:
                    source, context = j
                    setter = None
                if len(j) == 3:
                    source, context, setter = j
                path = template_fmt.format(**context)
                to_copy.append((source, path))
                if setter:
                    setter(path)

            return to_copy