Skip to content

Commit

Permalink
Merge pull request hyperledger#327 from AlexanderShekhovcov/master
Browse files Browse the repository at this point in the history
Fix validator info tool
  • Loading branch information
andkononykhin authored Aug 28, 2017
2 parents 56dd3e6 + 748825a commit 936788e
Showing 1 changed file with 34 additions and 20 deletions.
54 changes: 34 additions & 20 deletions scripts/validator-info
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys
import argparse
import os
import datetime
import time
import asyncio
import concurrent.futures
import curses

import datetime
import json
import pprint

import os
import sys
import time
import subprocess
from collections import OrderedDict

import asyncio
import concurrent.futures
from glob import glob

from sovrin_common.config_util import getConfig
from stp_core.common.log import getlogger

from stp_core.common.log import Logger

from stp_core.common.log import getlogger

config = getConfig()

Expand Down Expand Up @@ -125,11 +120,6 @@ class ValidatorStats(BaseStats):
# TODO moving parts to other classes seems reasonable but
# will drop visibility of output

def format_state(state):
return "is {} {}".format(
"currently" if state == "running" else "", state
)

def format_port(port, protocol, ip):
return "{}{}".format(
port,
Expand All @@ -150,8 +140,8 @@ class ValidatorStats(BaseStats):
return ", ".join(parts) if parts else '0 seconds'

lines = [
"Validator {} {}".format(
self['alias'], format_state(self['state'])),
"Validator {} is {}".format(
self['alias'], self['state']),
"#Current time: {}".format(
datetime.datetime.fromtimestamp(
self['timestamp']).strftime(
Expand Down Expand Up @@ -256,10 +246,34 @@ def get_stats_from_file(fpath, verbose, _json):

logger.debug("Data {}".format(stats))
vstats = ValidatorStats(stats, verbose)
vstats.update(state=get_process_state())
vstats.update(enabled=get_enabled_state())

return (json.dumps(vstats, indent=2) if _json else vstats)


def get_process_state():
ret = subprocess.check_output('systemctl is-failed sovrin-node; exit 0', stderr=subprocess.STDOUT, shell=True)
ret = ret.decode().strip()
if ret == 'inactive':
return 'stopped'
elif ret == 'active':
return 'running'
else:
return ret


def get_enabled_state():
ret = subprocess.check_output('systemctl is-enabled sovrin-node; exit 0', stderr=subprocess.STDOUT, shell=True)
ret = ret.decode().strip()
if ret == 'enabled' or ret == 'static':
return True
elif ret == 'disabled':
return False
else:
return ret


def watch(fpath, verbose, _json):

def _watch(stdscr):
Expand Down

0 comments on commit 936788e

Please sign in to comment.