-
Notifications
You must be signed in to change notification settings - Fork 22
/
indy-cli
executable file
·104 lines (80 loc) · 3.07 KB
/
indy-cli
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#! /usr/bin/env python3
"""
Convenience script for calling the indy command line interface (CLI). For now,
the CLI is designed for experimenting with the Indy Identity platform, and not
for creating a live consensus pool. For that, it's as simple as defining a node
registry, creating a looper, creating a node, and running it.
$ indy-cli
or supply a command to be executed first
$ indy-cli "new nodes all"
Spec: The indy-cli is a fix for the indy script to provide a command line
execution of commands which require somewhat means to be atomic. The indy
script as it is today fails for executing commands from the command line
if one command depends on the previous for completion. A good example
is to provide a list of commands to indy script and the last one as quit and
you can see that the indy script exits before finishing all the commands
due to asyncronous operation and no concept of atomic operations for commands.
For now this is a solution for the Alice demo to setup without a human linearly
stepping through commands and waiting for responses for the next.
"""
import logging
import os
import sys
import asyncio
import time
# NOTE: Loading of plugin should happen as early as possible
# So put all other required imports after loadPlugins function call below
from plenum.common.plugin_helper import loadPlugins
from indy_common.config_util import getConfig
logging.root.handlers = []
logger = logging.getLogger()
logger.propagate = False
logger.disabled = True
config = getConfig()
baseDir = os.path.expanduser(config.CLI_BASE_DIR)
network_dir = os.path.expanduser(config.CLI_NETWORK_DIR)
if not os.path.exists(baseDir):
os.makedirs(baseDir)
if not os.path.exists(network_dir):
os.makedirs(network_dir)
loadPlugins(baseDir)
# NOTE: Put all regular imports below (not related to loadplugin)
from indy_client.cli.cli import IndyCli
from stp_core.loop.looper import Looper
async def cmdline(cli,commands):
for command in commands:
if not command.startswith("--"):
print("\nRunning command: '{}'...\n".format(command))
cli.parse(command)
await asyncio.sleep(3)
def run_cli():
commands = sys.argv[1:]
withNode = True if '--with-node' in commands else False
with Looper(debug=config.LOOPER_DEBUG) as looper:
curDir = os.getcwd()
logFilePath = os.path.join(curDir, config.logFilePath)
cli = IndyCli(looper=looper,
basedirpath=baseDir,
ledger_base_dir=network_dir,
logFileName=logFilePath,
withNode=withNode
)
looper.run(cmdline(cli,commands) )
commands = []
looper.run(cli.shell(*commands))
default_config = """
[node_reg]
Alpha = 127.0.0.1 8001
Beta = 127.0.0.1 8003
Gamma = 127.0.0.1 8005
Delta = 127.0.0.1 8007
[client_node_reg]
AlphaC = 127.0.0.1 8002
BetaC = 127.0.0.1 8004
GammaC = 127.0.0.1 8006
DeltaC = 127.0.0.1 8008
[storage_locations]
basePath = ~
"""
if __name__ == '__main__':
run_cli()