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)
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 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)
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
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)))
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)
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
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)
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)
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
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