summaryrefslogtreecommitdiff
path: root/isv.py
blob: ab4268b1349e7609f4cf33f9ad8068cd4771b066 (plain)
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
import subprocess
import configstore
import json


def __run(argv: list, fmt='json-w-units'):
    argv.insert(0, configstore.get_isv_bin())
    if configstore.use_sudo():
        argv.insert(0, 'sudo')
    argv.append('--format')
    argv.append(fmt)

    result = subprocess.run(argv, capture_output=True)
    if result.returncode != 0:
        raise ChildProcessError("isv returned %d: %s" % (result.returncode, result.stderr))

    return json.loads(result.stdout) if 'json' in fmt else result.stdout.decode('utf-8')


def general_status(as_table=False):
    kwargs = {}
    if as_table:
        kwargs['fmt'] = 'table'
    return __run(['--get-general-status'], **kwargs)


def day_generated(y: int, m: int, d: int):
    return __run(['--get-day-generated', str(y), str(m), str(d)])


def rated_information(as_table=False):
    kwargs = {}
    if as_table:
        kwargs['fmt'] = 'table'
    return __run(['--get-rated-information'], **kwargs)


def faults(as_table=False):
    kwargs = {}
    if as_table:
        kwargs['fmt'] = 'table'
    return __run(['--get-faults-warnings'], **kwargs)