예제 #1
0
파일: init_cmd.py 프로젝트: arhik/populus
def init():
    """
    Generate project layout with an example contract.
    """
    project_dir = os.getcwd()

    contracts_dir = get_contracts_dir(project_dir)
    if utils.ensure_path_exists(contracts_dir):
        click.echo("Created Directory: ./{0}".format(os.path.relpath(contracts_dir)))

    libraries_dir = get_project_libraries_dir(project_dir)
    if utils.ensure_path_exists(libraries_dir):
        click.echo("Created Directory: ./{0}".format(os.path.relpath(libraries_dir)))

    example_contract_path = os.path.join(contracts_dir, 'Example.sol')
    if not os.path.exists(example_contract_path):
        with open(example_contract_path, 'w') as example_contract_file:
            example_contract_file.write('contract Example {\n        function Example() {\n        }\n}\n')  # NOQA
        click.echo("Created Example Contract: ./{0}".format(os.path.relpath(example_contract_path)))  # NOQA

    tests_dir = os.path.join(project_dir, 'tests')
    if utils.ensure_path_exists(tests_dir):
        click.echo("Created Directory: ./{0}".format(os.path.relpath(tests_dir)))

    example_tests_path = os.path.join(tests_dir, 'test_example.py')
    if not os.path.exists(example_tests_path):
        with open(example_tests_path, 'w') as example_tests_file:
            example_tests_file.write('def test_it(deployed_contracts):\n    example = deployed_contracts.Example\n    assert example._meta.address\n')  # NOQA
        click.echo("Created Example Tests: ./{0}".format(os.path.relpath(example_tests_path)))  # NOQA

    initialize_web_directories(project_dir)
예제 #2
0
파일: geth.py 프로젝트: PiDelport/populus
def get_geth_logfile_path(data_dir, logfile_name_fmt="geth-{0}.log"):
    logfile_name = logfile_name_fmt.format(
        datetime.datetime.now().strftime("%Y%m%d-%H%M%S"), )
    log_dir = os.path.join(data_dir, 'logs')
    utils.ensure_path_exists(log_dir)
    logfile_path = os.path.abspath(os.path.join(log_dir, logfile_name))
    return logfile_path
예제 #3
0
def init():
    """
    Generate project layout with an example contract.
    """
    project_dir = os.getcwd()
    contracts_dir = get_contracts_dir(project_dir)
    if utils.ensure_path_exists(contracts_dir):
        click.echo("Created Directory: ./{0}".format(os.path.relpath(contracts_dir)))

    example_contract_path = os.path.join(contracts_dir, 'Example.sol')
    if not os.path.exists(example_contract_path):
        with open(example_contract_path, 'w') as example_contract_file:
            example_contract_file.write('contract Example {\n        function Example() {\n        }\n}\n')  # NOQA
        click.echo("Created Example Contract: ./{0}".format(os.path.relpath(example_contract_path)))  # NOQA

    tests_dir = os.path.join(project_dir, 'tests')
    if utils.ensure_path_exists(tests_dir):
        click.echo("Created Directory: ./{0}".format(os.path.relpath(tests_dir)))

    example_tests_path = os.path.join(tests_dir, 'test_example.py')
    if not os.path.exists(example_tests_path):
        with open(example_tests_path, 'w') as example_tests_file:
            example_tests_file.write('def test_it(deployed_contracts):\n    example = deployed_contracts.Example\n    assert example.address\n')  # NOQA
        click.echo("Created Example Tests: ./{0}".format(os.path.relpath(example_tests_path)))  # NOQA

    initialize_web_directories(project_dir)
예제 #4
0
def get_geth_logfile_path(data_dir, logfile_name_fmt="geth-{0}.log"):
    logfile_name = logfile_name_fmt.format(
        datetime.datetime.now().strftime("%Y%m%d-%H%M%S"),
    )
    log_dir = os.path.join(data_dir, 'logs')
    utils.ensure_path_exists(log_dir)
    logfile_path = os.path.abspath(os.path.join(log_dir, logfile_name))
    return logfile_path
def project_test04(monkeypatch):
    project_dir = os.path.join(PROJECTS_DIR, 'test-04')
    monkeypatch.chdir(project_dir)

    data_dir = get_geth_data_dir(project_dir, 'default')
    ensure_path_exists(data_dir)
    reset_chain(data_dir)

    ensure_account_exists(data_dir)

    return project_dir
예제 #6
0
def project_test04(monkeypatch):
    project_dir = os.path.join(PROJECTS_DIR, 'test-04')
    monkeypatch.chdir(project_dir)

    data_dir = get_geth_data_dir(project_dir, 'default')
    ensure_path_exists(data_dir)
    reset_chain(data_dir)

    ensure_account_exists(data_dir)

    return project_dir
예제 #7
0
def initialize_web_directories(project_dir):
    html_dir = get_html_dir(project_dir)
    if utils.ensure_path_exists(html_dir):
        click.echo("Created Directory: ./{0}".format(os.path.relpath(html_dir)))

    html_index_path = os.path.join(html_dir, 'index.html')
    if not os.path.exists(html_index_path):
        write_default_index_html_document(html_index_path)
        click.echo("Created HTML Index File: ./{0}".format(os.path.relpath(html_index_path)))

    static_assets_dir = get_static_assets_dir(project_dir)
    if utils.ensure_path_exists(static_assets_dir):
        click.echo("Created Directory: ./{0}".format(os.path.relpath(static_assets_dir)))
예제 #8
0
파일: plugin.py 프로젝트: PiDelport/populus
def geth_node(request, populus_config):
    from populus.geth import (
        run_geth_node,
        get_geth_data_dir,
        get_geth_logfile_path,
        ensure_account_exists,
        create_geth_account,
        reset_chain,
        wait_for_geth_to_start,
    )
    from populus.utils import (
        ensure_path_exists,
        kill_proc,
    )

    project_dir = populus_config.get_value(request, 'geth_project_dir')
    chain_name = populus_config.get_value(request, 'geth_chain_name')

    data_dir = get_geth_data_dir(project_dir, chain_name)

    logfile_name_fmt = "geth-{0}-{{0}}.log".format(request.module.__name__)
    logfile_path = get_geth_logfile_path(data_dir, logfile_name_fmt)

    ensure_path_exists(data_dir)
    ensure_account_exists(data_dir)

    num_accounts = populus_config.get_value(request, 'geth_num_accounts')
    if num_accounts > 1:
        for _ in range(num_accounts - 1):
            create_geth_account(data_dir)

    should_reset_chain = populus_config.get_value(request, 'geth_reset_chain')

    if should_reset_chain:
        reset_chain(data_dir)

    rpc_port = populus_config.get_value(request, 'geth_rpc_port')
    rpc_host = populus_config.get_value(request, 'geth_rpc_host')

    geth_max_wait = int(populus_config.get_value(request, 'geth_max_wait'))

    command, proc = run_geth_node(data_dir, rpc_addr=rpc_host,
                                  rpc_port=rpc_port, logfile=logfile_path,
                                  verbosity="6")

    wait_for_geth_to_start(proc, max_wait=geth_max_wait)

    yield proc
    kill_proc(proc)
예제 #9
0
def geth_coinbase(request, populus_config):
    from populus.geth import (
        get_geth_data_dir,
        ensure_account_exists,
    )
    from populus.utils import (
        ensure_path_exists, )

    project_dir = populus_config.get_value(request, 'geth_project_dir')
    chain_name = populus_config.get_value(request, 'geth_chain_name')
    data_dir = get_geth_data_dir(project_dir, chain_name)

    ensure_path_exists(data_dir)
    geth_coinbase = ensure_account_exists(data_dir)
    return geth_coinbase
예제 #10
0
파일: plugin.py 프로젝트: Cryptix23/populus
def geth_coinbase(request, populus_config):
    from populus.geth import (
        get_geth_data_dir,
        ensure_account_exists,
    )
    from populus.utils import (
        ensure_path_exists,
    )

    project_dir = populus_config.get_value(request, 'geth_project_dir')
    chain_name = populus_config.get_value(request, 'geth_chain_name')
    data_dir = get_geth_data_dir(project_dir, chain_name)

    ensure_path_exists(data_dir)
    geth_coinbase = ensure_account_exists(data_dir)
    return geth_coinbase
예제 #11
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)
예제 #12
0
파일: web.py 프로젝트: autolycus/populus
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)
예제 #13
0
def get_geth_data_dir(project_dir, name):
    blockchains_dir = get_blockchains_dir(project_dir)
    data_dir = os.path.abspath(os.path.join(blockchains_dir, name))
    utils.ensure_path_exists(data_dir)
    return data_dir
예제 #14
0
def get_blockchains_dir(project_dir):
    blockchains_dir = os.path.abspath(os.path.join(project_dir, 'chains'))
    utils.ensure_path_exists(blockchains_dir)
    return blockchains_dir
예제 #15
0
파일: geth.py 프로젝트: PiDelport/populus
def get_geth_data_dir(project_dir, name):
    blockchains_dir = get_blockchains_dir(project_dir)
    data_dir = os.path.abspath(os.path.join(blockchains_dir, name))
    utils.ensure_path_exists(data_dir)
    return data_dir
예제 #16
0
파일: geth.py 프로젝트: PiDelport/populus
def get_blockchains_dir(project_dir):
    blockchains_dir = os.path.abspath(os.path.join(project_dir, 'chains'))
    utils.ensure_path_exists(blockchains_dir)
    return blockchains_dir