def delete(ctx: Context, agent_name): """Delete an agent.""" path = Path(agent_name) # check that the target folder is an AEA project. cwd = os.getcwd() try: os.chdir(agent_name) fp = open(DEFAULT_AEA_CONFIG_FILE, mode="r", encoding="utf-8") ctx.agent_config = ctx.agent_loader.load(fp) _try_to_load_agent_config(ctx) except Exception: logger.error("The name provided is not an AEA project.") sys.exit(1) finally: os.chdir(cwd) logger.info("Deleting agent project directory '/{}'...".format(path)) # delete the agent's directory try: shutil.rmtree(path, ignore_errors=False) except OSError: logger.error( "An error occurred while deleting the agent directory. Aborting..." ) sys.exit(1)
def install(ctx: Context, requirement: Optional[str]): """Install the dependencies.""" _try_to_load_agent_config(ctx) if requirement: logger.debug( "Installing the dependencies in '{}'...".format(requirement)) dependencies = list( map(lambda x: x.strip(), open(requirement).readlines())) else: logger.debug("Installing all the dependencies...") dependencies = ctx.get_dependencies() for d in dependencies: logger.info("Installing {}...".format(d)) try: subp = subprocess.Popen( [sys.executable, "-m", "pip", "install", d]) subp.wait(30.0) assert subp.returncode == 0 except Exception: logger.error( "An error occurred while installing {}. Stopping...".format(d)) sys.exit(1)
def run(click_context, connection_names: List[str], env_file: str, install_deps: bool): """Run the agent.""" ctx = cast(Context, click_context.obj) _try_to_load_agent_config(ctx) _load_env_file(env_file) agent_name = cast(str, ctx.agent_config.agent_name) _verify_or_create_private_keys(ctx) _verify_ledger_apis_access() private_key_paths = dict([(identifier, config.path) for identifier, config in ctx.agent_config.private_key_paths.read_all()]) ledger_api_configs = dict([ (identifier, (config.addr, config.port)) for identifier, config in ctx.agent_config.ledger_apis.read_all() ]) wallet = Wallet(private_key_paths) ledger_apis = LedgerApis(ledger_api_configs) connection_names = [ctx.agent_config.default_connection ] if connection_names is None else connection_names connections = [] _try_to_load_protocols(ctx) try: for connection_name in connection_names: connection = _setup_connection(connection_name, wallet.public_keys[FETCHAI], ctx) connections.append(connection) except AEAConfigException as e: logger.error(str(e)) sys.exit(1) if install_deps: if Path("requirements.txt").exists(): click_context.invoke(install, requirement="requirements.txt") else: click_context.invoke(install) agent = AEA(agent_name, connections, wallet, ledger_apis, resources=Resources(str(Path(".")))) try: agent.start() except KeyboardInterrupt: logger.info("Interrupted.") # pragma: no cover except Exception as e: logger.exception(e) sys.exit(1) finally: agent.stop()
def add_key(ctx: Context, type_, file): """Add a private key to the wallet.""" _try_to_load_agent_config(ctx) _validate_private_key_path(file, type_) try: ctx.agent_config.private_key_paths.create( type_, PrivateKeyPathConfig(type_, file)) except ValueError as e: # pragma: no cover logger.error(str(e)) # pragma: no cover ctx.agent_loader.dump( ctx.agent_config, open(os.path.join(ctx.cwd, DEFAULT_AEA_CONFIG_FILE), "w"))
def run(ctx: Context, connection_name: str): """Run the agent.""" _try_to_load_agent_config(ctx) agent_name = cast(str, ctx.agent_config.agent_name) private_key_pem_path = cast(str, ctx.agent_config.private_key_pem_path) if private_key_pem_path == "": private_key_pem_path = _create_temporary_private_key_pem_path() else: _try_validate_private_key_pem_path(private_key_pem_path) crypto = Crypto(private_key_pem_path=private_key_pem_path) public_key = crypto.public_key connection_name = ctx.agent_config.default_connection if connection_name is None else connection_name _try_to_load_protocols(ctx) try: connection = _setup_connection(connection_name, public_key, ctx) except AEAConfigException as e: logger.error(str(e)) exit(-1) return logger.debug("Installing all the dependencies...") for d in ctx.get_dependencies(): logger.debug("Installing {}...".format(d)) try: subp = subprocess.Popen( [sys.executable, "-m", "pip", "install", d]) subp.wait(30.0) except Exception: logger.error( "An error occurred while installing {}. Stopping...".format(d)) exit(-1) mailbox = MailBox(connection) agent = AEA(agent_name, mailbox, private_key_pem_path=private_key_pem_path, directory=str(Path("."))) try: agent.start() except KeyboardInterrupt: logger.info("Interrupted.") except Exception as e: logger.exception(e) finally: agent.stop()
def scaffold(ctx: Context): """Scaffold a resource for the agent.""" _try_to_load_agent_config(ctx)
def freeze(ctx: Context): """Get the dependencies.""" _try_to_load_agent_config(ctx) for d in ctx.get_dependencies(): print(d)
def remove(ctx: Context): """Remove a resource from the agent.""" _try_to_load_agent_config(ctx)
def add(ctx: Context, registry): """Add a resource to the agent.""" if registry: ctx.set_config("is_registry", True) _try_to_load_agent_config(ctx)
def add(ctx: Context): """Add a resource to the agent.""" _try_to_load_agent_config(ctx)
def list(ctx: Context): """List the installed resources.""" _try_to_load_agent_config(ctx)