def on_any_event(self, event): if hasattr(event, "dest_path"): # This indicates that the event was a creation of the # active data symlink and not the delete. path = event.src_path activePath = get_active_data_dir(self.project_dir) if os.path.normpath(path) == os.path.normpath(activePath): # This means that a new active chain directory symlink # was created and we can refresh our known contracts newDataPath = os.readlink(activePath) message = ( "\n=========== Active Directory Changed ===========\n" "New Active Dir: {active_dir}\n" ).format(active_dir=newDataPath) click.echo(click.style(message, fg="yellow")) # Update the known setup_known_instances(self.context, activePath)
def on_any_event(self, event): if hasattr(event, "dest_path"): # This indicates that the event was a creation of the # active data symlink and not the delete. path = event.src_path activePath = get_active_data_dir(self.project_dir) if os.path.normpath(path) == os.path.normpath(activePath): # This means that a new active chain directory symlink # was created and we can refresh our known contracts newDataPath = os.readlink(activePath) message = ( "\n=========== Active Directory Changed ===========\n" "New Active Dir: {active_dir}\n").format( active_dir=newDataPath) click.echo(click.style(message, fg="yellow")) # Update the known setup_known_instances(self.context, activePath)
def attach(active): """ Enter a python shell with contracts and blockchain client available. """ project_dir = os.path.abspath(os.getcwd()) contracts_meta = utils.load_contracts(project_dir) client = Client('127.0.0.1', '8545') context = { 'contracts': package_contracts(contracts_meta), 'client': client, } data_dir = None if active: data_dir = get_active_data_dir(project_dir) if os.path.islink(data_dir): setup_known_instances(context, data_dir) else: click.echo(click.style("No Valid Active Chain Data Directory Found!", fg="red")) def redeploy(contracts=[], record=True): return(deploy_set( context, client, project_dir, data_dir=data_dir, record=record, contracts_by_name=contracts )) context["redeploy"] = redeploy contract_names = ', '.join(sorted(contracts_meta.keys())) banner = textwrap.dedent( """ Python: {python_version} Populus: v{populus_version} Project Path: {project_dir} contracts -> Contract classes client -> Blockchain client ({client_type}) redeploy -> Method to re-deploy project contracts Example: deployed_cts = redeploy() deployed_cts = redeploy(record = False) deployed_cts = redeploy(contracts = ["Example"]) Contracts: {contracts} Check contracts.<type>.known for deployed contracts. """ ).format( python_version=sys.version.partition('\n')[0], populus_version=populus.__version__, project_dir=project_dir, client_type="json-rpc", contracts=click.wrap_text( contract_names, initial_indent='', subsequent_indent=' ' * 4, ), ).strip() if is_ipython: shell = InteractiveConsole(user_ns=context) else: shell = InteractiveConsole(context) # Start the active directory link observer event_handler = ActiveDataDirChangedEventHandler( project_dir=project_dir, context=context, ) observer = get_active_dir_observer(project_dir, event_handler) observer.start() shell.interact(banner) observer.stop() observer.join()
def attach(active): """ Enter a python shell with contracts and blockchain client available. """ project_dir = os.path.abspath(os.getcwd()) contracts_meta = utils.load_contracts(project_dir) client = Client('127.0.0.1', '8545') context = { 'contracts': package_contracts(contracts_meta), 'client': client, } data_dir = None if active: data_dir = get_active_data_dir(project_dir) if os.path.islink(data_dir): setup_known_instances(context, data_dir) else: click.echo( click.style("No Valid Active Chain Data Directory Found!", fg="red")) def redeploy(contracts=[], record=True): return (deploy_set(context, client, project_dir, data_dir=data_dir, record=record, contracts_by_name=contracts)) context["redeploy"] = redeploy contract_names = ', '.join(sorted(contracts_meta.keys())) banner = textwrap.dedent(""" Python: {python_version} Populus: v{populus_version} Project Path: {project_dir} contracts -> Contract classes client -> Blockchain client ({client_type}) redeploy -> Method to re-deploy project contracts Example: deployed_cts = redeploy() deployed_cts = redeploy(record = False) deployed_cts = redeploy(contracts = ["Example"]) Contracts: {contracts} Check contracts.<type>.known for deployed contracts. """).format( python_version=sys.version.partition('\n')[0], populus_version=populus.__version__, project_dir=project_dir, client_type="json-rpc", contracts=click.wrap_text( contract_names, initial_indent='', subsequent_indent=' ' * 4, ), ).strip() if is_ipython: shell = InteractiveConsole(user_ns=context) else: shell = InteractiveConsole(context) # Start the active directory link observer event_handler = ActiveDataDirChangedEventHandler( project_dir=project_dir, context=context, ) observer = get_active_dir_observer(project_dir, event_handler) observer.start() shell.interact(banner) observer.stop() observer.join()