forked from golemfactory/clay
-
Notifications
You must be signed in to change notification settings - Fork 0
/
golemcli.py
executable file
·83 lines (64 loc) · 2.47 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env python
import os
import argparse
import sys
from multiprocessing import freeze_support
# Export pbr version for peewee_migrate user
os.environ["PBR_VERSION"] = '3.1.1'
# pylint: disable=wrong-import-position
from golem.core.common import config_logging, install_reactor # noqa
from golem.interface.cli import CLI # noqa
from golem.interface.client import debug # noqa
from golem.interface.client.account import Account # noqa
from golem.interface.client.environments import Environments # noqa
from golem.interface.client.network import Network # noqa
from golem.interface.client.payments import payments, incomes # noqa
from golem.interface.client.resources import Resources # noqa
from golem.interface.client.settings import Settings # noqa
from golem.interface.client.tasks import Tasks, Subtasks # noqa
from golem.interface.websockets import WebSocketCLI # noqa
# prevent 'unused' warnings
_ = {
Tasks, Subtasks, Network, Environments, Resources, Settings,
Account, incomes, payments, debug
}
def start():
freeze_support()
delete_reactor()
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='localhost',
help="Golem node's RPC address"),
port=dict(dest="port", type=int, default=61000,
help="Golem node's RPC 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("_cli")
cli = CLI()
else:
import logging
logging.raiseExceptions = 0
cli = CLI(main_parser=parser, main_parser_options=flag_options)
# run the cli
install_reactor()
ws_cli = WebSocketCLI(cli, host=parsed.address, port=parsed.port)
ws_cli.execute(forwarded, interactive=interactive)
def delete_reactor():
if 'twisted.internet.reactor' in sys.modules:
del sys.modules['twisted.internet.reactor']
if __name__ == '__main__':
start()