forked from liquidctl/liquidctl
-
Notifications
You must be signed in to change notification settings - Fork 2
/
liquiddump
executable file
·105 lines (90 loc) · 3.63 KB
/
liquiddump
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/env python
"""liquiddump – continuously dump monitoring data from liquidctl devices.
This is a experimental script that continuously dumps the status of all
available devices to stdout in newline-delimited JSON.
Usage:
liquiddump [options]
liquiddump --help
liquiddump --version
Options:
--interval <seconds> Update interval in seconds [default: 2]
--hid <module> Override API for USB HIDs: usb, hid or hidraw
--legacy-690lc Use Asetek 690LC in legacy mode (old Krakens)
--vendor <id> Filter devices by vendor id
--product <id> Filter devices by product id
--release <number> Filter devices by release number
--serial <number> Filter devices by serial number
--bus <bus> Filter devices by bus
--address <address> Filter devices by address in bus
--usb-port <port> Filter devices by USB port in bus
--pick <number> Pick among many results for a given filter
-v, --verbose Output additional information
-g, --debug Show debug information on stderr
--version Display the version number
--help Show this message
Examples:
liquiddump
liquiddump --product 0xb200
liquiddump --interval 0.5
liquiddump > file.jsonl
liquiddump | jq -c .
This program is free software: you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any later
version.
Copyright (C) 2019 Jonas Malaco
Copyright (C) 2019 each contribution's author
You should have received a copy of all applicable licenses along with this
program, in a file called LICENSE.txt.
This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details.
"""
import json
import logging
import sys
import time
import liquidctl.cli as _borrow
import usb
from docopt import docopt
from liquidctl.driver import *
LOGGER = logging.getLogger(__name__)
if __name__ == '__main__':
args = docopt(__doc__, version='0.1.0')
frwd = _borrow._make_opts(args)
devs = list(find_liquidctl_devices(**frwd))
update_interval = float(args['--interval'])
if args['--debug']:
args['--verbose'] = True
logging.basicConfig(level=logging.DEBUG, format='[%(levelname)s] %(name)s: %(message)s')
elif args['--verbose']:
logging.basicConfig(level=logging.INFO, format='%(levelname)s: %(message)s')
else:
logging.basicConfig(level=logging.WARNING, format='%(message)s')
sys.tracebacklimit = 0
try:
for d in devs:
LOGGER.info('Initializing %s', d.description)
d.connect()
status = {}
while True:
for d in devs:
try:
status[d.description] = d.get_status()
except usb.core.USBError as err:
LOGGER.warning('Failed to read from the device, possibly serving stale data')
LOGGER.debug(err, exc_info=True)
print(json.dumps(status), flush=True)
time.sleep(update_interval)
except KeyboardInterrupt:
LOGGER.info('Canceled by user')
except:
LOGGER.exception('Unexpected error')
sys.exit(1)
finally:
for d in devs:
try:
LOGGER.info('Disconnecting from %s', d.description)
d.disconnect()
except:
LOGGER.exception('Unexpected error when disconnecting')