forked from golemfactory/clay
-
Notifications
You must be signed in to change notification settings - Fork 6
/
golemcli.py
60 lines (48 loc) · 1.87 KB
/
golemcli.py
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
import argparse
import sys
from golem.core.common import config_logging
from golem.interface.cli import CLI
from golem.interface.client import account
from golem.interface.client.environments import Environments
from golem.interface.client.network import Network
from golem.interface.client.payments import payments, incomes
from golem.interface.client.resources import Resources
from golem.interface.client.settings import Settings
from golem.interface.client.tasks import Tasks, Subtasks
from golem.interface.websockets import WebSocketCLI
# prevent 'unused' warnings
_ = {
Tasks, Subtasks, Network, Environments, Resources, Settings,
account, incomes, payments,
}
def start():
flags = dict(
interactive=('-i', '--interactive'),
address=('-a', '--address'),
port=('-p', '--port'),
)
flag_options = dict(
interactive=dict(dest="interactive", action="store_true", default=False, help="Enter interactive mode"),
address=dict(dest="address", type=str, default='127.0.0.1', help="Golem node's address"),
port=dict(dest="port", type=int, default=60103, help="Golem node's port"),
)
# process initial arguments
parser = argparse.ArgumentParser(add_help=False)
for flag_name, flag in flags.items():
parser.add_argument(*flag, **flag_options[flag_name])
args = sys.argv[1:]
parsed, forwarded = parser.parse_known_args(args)
# setup logging if in interactive mode
interactive = parsed.interactive
if interactive:
config_logging("golem_cli.log")
cli = CLI()
else:
import logging
logging.raiseExceptions = 0
cli = CLI(main_parser=parser, main_parser_options=flag_options)
# run the cli
ws_cli = WebSocketCLI(cli, address=parsed.address, port=parsed.port)
ws_cli.execute(forwarded, interactive=interactive)
if __name__ == '__main__':
start()