Exemplo n.º 1
0
def collect_static_assets(project_dir):
    project_assets_path = get_static_assets_dir(project_dir)

    build_dir = get_build_dir(project_dir)
    build_assets_path = os.path.join(build_dir, 'assets')
    ensure_path_exists(build_assets_path)
    build_js_assets_path = os.path.join(build_assets_path, 'js')
    ensure_path_exists(build_js_assets_path)

    # Put the contracts json in place.
    contracts_js_path = os.path.join(get_build_dir(project_dir), 'contracts.js')
    shutil.copy(contracts_js_path, build_js_assets_path)

    search_paths = (
        POPULUS_ASSET_PATH,
        project_assets_path,
    )

    for base_assets_dir in search_paths:
        prefix_length = len(base_assets_dir)
        for (dirpath, dirnames, filenames) in os.walk(base_assets_dir):
            asset_dir = os.path.join(build_assets_path, dirpath[prefix_length + 1:])
            ensure_path_exists(asset_dir)

            for filename in filenames:
                asset_path = os.path.abspath(os.path.join(dirpath, filename))
                shutil.copy(asset_path, asset_dir)
Exemplo n.º 2
0
def get_contracts_code_observer(project_dir):
    observer = PollingObserver()

    build_path = utils.get_build_dir(project_dir)
    event_handler = ContractCodeChangedEventHandler(project_dir=project_dir)
    observer.schedule(event_handler, build_path, recursive=False)

    return observer
Exemplo n.º 3
0
def get_contracts_code_observer(project_dir):
    observer = PollingObserver()

    build_path = utils.get_build_dir(project_dir)
    event_handler = ContractCodeChangedEventHandler(project_dir=project_dir)
    observer.schedule(event_handler, build_path, recursive=False)

    return observer
Exemplo n.º 4
0
def get_static_assets_observer(project_dir):
    build_path = utils.get_build_dir(project_dir)

    observer = PollingObserver()

    contracts_js_event_handler = ContractsJSChangedEventHandler(project_dir=project_dir)
    observer.schedule(contracts_js_event_handler, build_path, recursive=False)

    if project_has_assets(project_dir):
        assets_watch_path = get_static_assets_dir(project_dir)
        assets_event_handler = AssetsChangedEventHandler(project_dir=project_dir)
        observer.schedule(assets_event_handler, assets_watch_path, recursive=True)

    return observer
Exemplo n.º 5
0
def compile_js_contracts(project_dir):
    build_dir = get_build_dir(project_dir)

    contracts_json_path = os.path.join(build_dir, 'contracts.json')
    with open(contracts_json_path) as contracts_json_file:
        contracts_json = contracts_json_file.read()

    js_contracts = js_contracts_template.format(contract_data=contracts_json)

    js_contracts_path = get_contracts_js_path(project_dir)

    with open(js_contracts_path, 'w') as js_contracts_file:
        js_contracts_file.write(js_contracts)

    return js_contracts_path
Exemplo n.º 6
0
def collect_static_assets(project_dir):
    project_assets_path = get_static_assets_dir(project_dir)

    build_dir = get_build_dir(project_dir)
    build_assets_path = os.path.join(build_dir, "assets")
    ensure_path_exists(build_assets_path)
    build_js_assets_path = os.path.join(build_assets_path, "js")
    ensure_path_exists(build_js_assets_path)

    # Put the contracts json in place.
    contracts_js_path = os.path.join(get_build_dir(project_dir), "contracts.js")
    shutil.copy(contracts_js_path, build_js_assets_path)

    search_paths = (POPULUS_ASSET_PATH, project_assets_path)

    for base_assets_dir in search_paths:
        prefix_length = len(base_assets_dir)
        for (dirpath, dirnames, filenames) in os.walk(base_assets_dir):
            asset_dir = os.path.join(build_assets_path, dirpath[prefix_length + 1 :])
            ensure_path_exists(asset_dir)

            for filename in filenames:
                asset_path = os.path.abspath(os.path.join(dirpath, filename))
                shutil.copy(asset_path, asset_dir)
Exemplo n.º 7
0
def compile_js_contracts(project_dir):
    build_dir = get_build_dir(project_dir)

    contracts_json_path = os.path.join(build_dir, "contracts.json")
    with open(contracts_json_path) as contracts_json_file:
        contracts_json = contracts_json_file.read()

    js_contracts = js_contracts_template.format(contract_data=contracts_json)

    js_contracts_path = get_contracts_js_path(project_dir)

    with open(js_contracts_path, "w") as js_contracts_file:
        js_contracts_file.write(js_contracts)

    return js_contracts_path
Exemplo n.º 8
0
def get_static_assets_observer(project_dir):
    build_path = utils.get_build_dir(project_dir)

    observer = PollingObserver()

    contracts_js_event_handler = ContractsJSChangedEventHandler(
        project_dir=project_dir)
    observer.schedule(contracts_js_event_handler, build_path, recursive=False)

    if project_has_assets(project_dir):
        assets_watch_path = get_static_assets_dir(project_dir)
        assets_event_handler = AssetsChangedEventHandler(
            project_dir=project_dir)
        observer.schedule(assets_event_handler,
                          assets_watch_path,
                          recursive=True)

    return observer
Exemplo n.º 9
0
def get_compiled_contract_destination_path(project_dir):
    build_dir = get_build_dir(project_dir)
    file_path = os.path.join(build_dir, 'contracts.json')
    return file_path
Exemplo n.º 10
0
def get_contracts_js_path(project_dir):
    build_dir = get_build_dir(project_dir)
    return os.path.join(build_dir, 'contracts.js')
Exemplo n.º 11
0
def get_build_assets_dir(project_dir):
    build_dir = get_build_dir(project_dir)
    return os.path.abspath(os.path.join(build_dir, 'assets'))
Exemplo n.º 12
0
def get_compiled_contract_destination_path(project_dir):
    build_dir = get_build_dir(project_dir)
    file_path = os.path.join(build_dir, 'contracts.json')
    return file_path
Exemplo n.º 13
0
def get_contracts_js_path(project_dir):
    build_dir = get_build_dir(project_dir)
    return os.path.join(build_dir, "contracts.js")
Exemplo n.º 14
0
def get_build_assets_dir(project_dir):
    build_dir = get_build_dir(project_dir)
    return os.path.abspath(os.path.join(build_dir, "assets"))