daemon.py: new method: get_exec_version_str()

This commit is contained in:
The MMGen Project 2022-06-13 17:30:21 +00:00
commit 074e2b2b74
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
2 changed files with 21 additions and 1 deletions

View file

@ -284,6 +284,22 @@ class CoinDaemon(Daemon):
yield CoinProtocol.Base.create_network_id(coin,network)
return list(gen())
@classmethod
def get_exec_version_str(cls):
try:
cp = run([cls.exec_fn,'--version'],stdout=PIPE,stderr=PIPE,check=True)
except:
try:
cp = run([cls.exec_fn,'version'],stdout=PIPE,stderr=PIPE,check=True)
except:
die(2,f'Unable to execute {cls.exec_fn}')
if cp.returncode:
die(2,f'Unable to execute {cls.exec_fn}')
else:
res = cp.stdout.decode().splitlines()
return ( res[0] if len(res) == 1 else [s for s in res if 'ersion' in s][0] ).strip()
def __new__(cls,
network_id = None,
proto = None,

View file

@ -23,6 +23,7 @@ opts_data = {
-q, --quiet Produce quieter output
-u, --usermode Run the daemon in user (non test-suite) mode
-v, --verbose Produce more verbose output
-V, --print-version Print version strings from execed daemons (not RPC)
-W, --no-wait Don't wait for daemons to change state before exiting
""",
'notes': """
@ -50,7 +51,10 @@ def run(network_id=None,proto=None,daemon_id=None):
daemon_id = daemon_id )
d.debug = d.debug or opt.debug
d.wait = not opt.no_wait
if opt.get_state:
if opt.print_version:
msg('{:16} {}'.format( d.exec_fn+':', d.get_exec_version_str() ))
elif opt.get_state:
print(d.state_msg())
elif opt.testing:
for cmd in d.start_cmds if action == 'start' else [d.stop_cmd]: