Cleaning
This commit is contained in:
parent
755a5ac611
commit
8968a136d3
@ -11,11 +11,16 @@ bars = "_▂▃▄▅▆▇█"
|
|||||||
batteries = ""
|
batteries = ""
|
||||||
batteries_charging = ""
|
batteries_charging = ""
|
||||||
|
|
||||||
|
|
||||||
class Monitor:
|
class Monitor:
|
||||||
"""
|
"""
|
||||||
A monitor on which many workspaces can appear.
|
A monitor on which many workspaces can appear.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, id: int, name: str):
|
def __init__(self, id: int, name: str):
|
||||||
|
"""
|
||||||
|
Constructs a monitor from its id and its name.
|
||||||
|
"""
|
||||||
self.id = id
|
self.id = id
|
||||||
self.name = name
|
self.name = name
|
||||||
|
|
||||||
@ -84,7 +89,11 @@ class Workspace:
|
|||||||
|
|
||||||
Workspaces with id from 10 * n + k belongs to the same monitor for k in [1, 10].
|
Workspaces with id from 10 * n + k belongs to the same monitor for k in [1, 10].
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, id: int):
|
def __init__(self, id: int):
|
||||||
|
"""
|
||||||
|
Constructs a workspace from its id.
|
||||||
|
"""
|
||||||
self.id = id
|
self.id = id
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@ -141,15 +150,16 @@ def to_bar(x):
|
|||||||
|
|
||||||
|
|
||||||
def monitor_stats():
|
def monitor_stats():
|
||||||
try:
|
|
||||||
import psutil
|
|
||||||
except:
|
|
||||||
print('Stats requires psutil (run `pip install psutil`)', file=sys.stderr)
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Monitors CPU and MEM usage and prints info in file.
|
Monitors CPU and MEM usage and prints info in file.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
try:
|
||||||
|
import psutil
|
||||||
|
except ModuleNotFoundError:
|
||||||
|
print('Stats requires psutil (run `pip install psutil`)', file=sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
cpu_values = [0] * 10
|
cpu_values = [0] * 10
|
||||||
mem_values = [0] * 10
|
mem_values = [0] * 10
|
||||||
|
|
||||||
@ -181,12 +191,12 @@ def monitor_stats():
|
|||||||
battery_class = None
|
battery_class = None
|
||||||
|
|
||||||
battery_json = f', "class": "{battery_class}"' if battery_class else ''
|
battery_json = f', "class": "{battery_class}"' if battery_class else ''
|
||||||
battery_json = '{"text": "' + battery_icon + ' ' + "% 4.0f"%battery.percent + '%"' + battery_json + '}'
|
battery_json = '{"text": "' + battery_icon + ' ' + "% 4.0f" % battery.percent + '%"' + battery_json + '}'
|
||||||
|
|
||||||
with open('.stat.txt', 'w') as f:
|
with open('.stat.txt', 'w') as f:
|
||||||
f.write(
|
f.write(
|
||||||
' ' + ''.join([to_bar(x) for x in cpu_values]) + ' ' + "% 5.1f"%cpu_percent + '%\n' +
|
' ' + ''.join([to_bar(x) for x in cpu_values]) + ' ' + "% 5.1f" % cpu_percent + '%\n' +
|
||||||
' ' + ''.join([to_bar(x) for x in mem_values]) + ' ' + "% 5.1f"%mem_percent + '%\n' +
|
' ' + ''.join([to_bar(x) for x in mem_values]) + ' ' + "% 5.1f" % mem_percent + '%\n' +
|
||||||
battery_json
|
battery_json
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user