示例#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
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)
示例#3
0
def compile_contracts(watch, contracts):
    """
    Compile project contracts, storing their output in `./build/contracts.json`

    Call bare to compile all contracts or specify contract names or file paths
    to restrict to only compiling those contracts.

    Pass in a file path and a contract name separated by a colon(":") to
    specify only named contracts in the specified file.
    """
    project_dir = os.getcwd()

    click.echo("============ Compiling ==============")
    click.echo("> Loading contracts from: {0}".format(
        get_contracts_dir(project_dir)))

    result = compile_and_write_contracts(project_dir, *contracts)
    contract_source_paths, compiled_sources, output_file_path = result

    click.echo("> Found {0} contract source files".format(
        len(contract_source_paths)))
    for path in contract_source_paths:
        click.echo("- {0}".format(os.path.basename(path)))
    click.echo("")
    click.echo("> Compiled {0} contracts".format(len(compiled_sources)))
    for contract_name in sorted(compiled_sources.keys()):
        click.echo("- {0}".format(contract_name))
    click.echo("")
    click.echo("> Outfile: {0}".format(output_file_path))

    if watch:
        # The path to watch
        watch_path = utils.get_contracts_dir(project_dir)

        click.echo("============ Watching ==============")

        event_handler = ContractChangedEventHandler(
            project_dir=project_dir,
            contract_filters=contracts,
        )
        observer = PollingObserver()
        observer.schedule(event_handler, watch_path, recursive=True)
        observer.start()
        try:
            while observer.is_alive():
                time.sleep(1)
        except KeyboardInterrupt:
            observer.stop()
        observer.join()
示例#4
0
def compile_contracts(watch, optimize, filters):
    """
    Compile project contracts, storing their output in `./build/contracts.json`

    Call bare to compile all contracts or specify contract names or file paths
    to restrict to only compiling those contracts.

    Pass in a file path and a contract name separated by a colon(":") to
    specify only named contracts in the specified file.
    """
    project_dir = os.getcwd()

    click.echo("============ Compiling ==============")
    click.echo("> Loading contracts from: {0}".format(get_contracts_dir(project_dir)))

    result = compile_and_write_contracts(project_dir, *filters, optimize=optimize)
    contract_source_paths, compiled_sources, output_file_path = result

    click.echo("> Found {0} contract source files".format(len(contract_source_paths)))
    for path in contract_source_paths:
        click.echo("- {0}".format(os.path.basename(path)))
    click.echo("")
    click.echo("> Compiled {0} contracts".format(len(compiled_sources)))
    for contract_name in sorted(compiled_sources.keys()):
        click.echo("- {0}".format(contract_name))
    click.echo("")
    click.echo("> Outfile: {0}".format(output_file_path))

    if watch:
        # The path to watch
        click.echo("============ Watching ==============")

        observer = get_contracts_observer(project_dir, filters, {'optimize': optimize})
        observer.start()
        try:
            while observer.is_alive():
                time.sleep(1)
        except KeyboardInterrupt:
            observer.stop()
        observer.join()