示例#1
0
文件: run.py 项目: okfn/buildkit
from buildkit import stacks
import sys
import os

run_args = stacks.obj(
    summary = 'Perform common tasks relating to generating and building Python packages',
    child_command_specs = stacks.find_commands(
        '%s.command'%__package__, 
        os.path.join(os.path.dirname(__file__), 'command'),
    ),
    facility_specs = stacks.find_facilities(
        '%s.facility'%__package__, 
        os.path.join(os.path.dirname(__file__), 'facility'),
    ),
)

if __name__ == '__main__':
    result = stacks.run(**run_args)
    sys.exit(result)

示例#2
0
文件: generate.py 项目: okfn/buildkit
def prepare(
    generate,
    start_path, 
    replacements=None,
    ignore_extensions=[],
    exclude_paths=[],
    binary_extensions=[],
):
    exclude_paths = [stacks.uniform_path(path) for path in exclude_paths]
    if not os.path.exists(start_path) or not os.path.isdir(start_path):
        raise Exception('No such directory %r'%start_path)
    if replacements is None:
        replacements = {}
    if start_path.endswith(os.sep):
        start_path = start_path[:-1]
    for k, v in replacements.items():
        for other_key, other_value in replacements.items():
            if k != other_key:
                if k in other_key:
                    raise Exception(
                        'The replacement of %r with %r is not guaranteed '
                        'becuase the value is a substring of another value '
                        '%r associated with %r. Please remove one of these '
                        'and correct manually afterwards.' % (
                            v, k, other_key, other_value
                        )
                    )
    vars_used = []
    templates = []
    paths = []
    for dirpath, dirnames, filenames in os.walk(start_path):
        for dirname in dirnames:
            path = os.path.join(dirpath, dirname)
            if generate.exclude(exclude_paths, path):
                continue
            relpath = stacks.relpath(path, start_path)
            if path and not path in paths:
                paths.append(relpath)
        for filename in filenames:
            path = os.path.join(dirpath, filename)
            relpath = stacks.relpath(path, start_path)
            if generate.exclude(exclude_paths, path):
                continue
            ext = filename.split('.')[-1]
            if ext in ignore_extensions:
                continue
            fp = open(path, 'rb')
            content = fp.read()
            fp.close()
            if ext in binary_extensions:
                templates.append(
                    (
                        relpath, 
                        base64.standard_b64encode(content),  
                        True,
                    ) 
                )
            else:
                templates.append(
                    (
                        relpath,
                        generate.replace(content, replacements, vars_used),
                        False,
                    )
                )
    failed_to_use = []
    for item in replacements.keys():
        if item not in vars_used:
            failed_to_use.append(item)
    if failed_to_use:
        raise Exception(
            'Did not use these replacements: %r'%(
                failed_to_use,
            )
        )
    return stacks.obj(
        templates = templates,
        paths = paths,
        vars_used = vars_used,
        replacements = replacements,
    )