Revision d706a8af
Added by David Sorber over 4 years ago
| software/misc/display.py | ||
|---|---|---|
|
#!/usr/bin/python
|
||
|
#!/usr/bin/python3
|
||
|
import os
|
||
|
import subprocess
|
||
|
import sys
|
||
| ... | ... | |
|
|
||
|
def get_ipv4_addr(interface):
|
||
|
cmd = 'ifconfig {:s}'.format(interface)
|
||
|
for line in subprocess.check_output(cmd, shell=True).split('\n'):
|
||
|
for line in subprocess.check_output(cmd, shell=True).decode('utf-8').split('\n'):
|
||
|
if line.strip().startswith('inet '):
|
||
|
return line.split()[1]
|
||
|
else:
|
||
| ... | ... | |
|
def get_fs_usage(mount_point):
|
||
|
cmd = 'df -h | grep {:s}'.format(mount_point)
|
||
|
try:
|
||
|
line = subprocess.check_output(cmd, shell=True).split('\n')[0]
|
||
|
line = subprocess.check_output(cmd, shell=True).decode('utf-8').split('\n')[0]
|
||
|
except IndexError:
|
||
|
return '{:s}MOUNT POINT NOT FOUND{:s}'.format(RED, END)
|
||
|
line_tokens = line.split()
|
||
|
|
||
|
usage_percent = int(line_tokens[4][:-1])
|
||
|
percent_str = '{:s}{:>3d}%{:s}'.format(BOLD, usage_percent, END)
|
||
|
percent_str = '{:s}{:>2d}%{:s}'.format(BOLD, usage_percent, END)
|
||
|
if usage_percent > 90:
|
||
|
percent_str = '{:s}{:s}{:>3d}%{:s}'.format(BOLD, RED, usage_percent, END)
|
||
|
percent_str = '{:s}{:s}{:>2d}%{:s}'.format(BOLD, RED, usage_percent, END)
|
||
|
elif usage_percent > 70:
|
||
|
percent_str = '{:s}{:s}{:>3d}%{:s}'.format(BOLD, YELLOW, usage_percent, END)
|
||
|
percent_str = '{:s}{:s}{:>2d}%{:s}'.format(BOLD, YELLOW, usage_percent, END)
|
||
|
|
||
|
|
||
|
output = '{:10s} ({:<9s}) - {:>4s} of {:>4s} [ {:s} ] used; '\
|
||
| ... | ... | |
|
rows = int(rows)
|
||
|
columns = int(columns)
|
||
|
|
||
|
hostname = subprocess.check_output('hostname', shell=True).strip()
|
||
|
hostname = subprocess.check_output('hostname', shell=True).decode('utf-8').strip()
|
||
|
|
||
|
ip_addr = get_ipv4_addr('enp4s0')
|
||
|
root_stats = get_fs_usage('/dev/sda2')
|
||
|
storage_stats = get_fs_usage('/dev/md0')
|
||
|
|
||
|
print YELLOW + BOLD + ' _ _ '
|
||
|
print ' | | | | '
|
||
|
print ' _ __ | |__ __ _| | __ _ _ __ __ __'
|
||
|
print "| '_ \| '_ \ / _` | |/ _` | '_ \\ \/ /"
|
||
|
print '| |_) | | | | (_| | | (_| | | | |> < '
|
||
|
print "| .__/|_| |_|\__,_|_|\__,_|_| |_/_/\_\ "
|
||
|
print '| | '
|
||
|
print '|_| ' + END
|
||
|
print PURPLE + BOLD + '-' * columns + END
|
||
|
print
|
||
|
print '{:<17s} {:s} {:s} {:s}'.format(make_bold('Hostname:'), hostname,
|
||
|
make_bold('IP:'), ip_addr)
|
||
|
print '{:<17s} {:s}'.format(make_bold('Storage:'), root_stats)
|
||
|
print '{:<17s} {:s}'.format(make_bold(' '), storage_stats)
|
||
|
print
|
||
|
print(YELLOW + BOLD + ' _ _ ')
|
||
|
print(' | | | | ')
|
||
|
print(' _ __ | |__ __ _| | __ _ _ __ __ __')
|
||
|
print("| '_ \| '_ \ / _` | |/ _` | '_ \\ \/ /")
|
||
|
print('| |_) | | | | (_| | | (_| | | | |> < ')
|
||
|
print("| .__/|_| |_|\__,_|_|\__,_|_| |_/_/\_\ ")
|
||
|
print('| | ')
|
||
|
print('|_| ' + END)
|
||
|
print(PURPLE + BOLD + '-' * columns + END)
|
||
|
print()
|
||
|
# ~ print('{:<17s} {:s}'.format(make_bold('Hostname:'), hostname))
|
||
|
print('{:<17s} {:s} {:s} {:s}'.format(make_bold('Hostname:'), hostname,
|
||
|
make_bold('IP:'), ip_addr))
|
||
|
print('{:<17s} {:s}'.format(make_bold('Storage:'), root_stats))
|
||
|
print('{:<17s} {:s}'.format(make_bold(' '), storage_stats))
|
||
|
print()
|
||
|
|
||
|
print PURPLE + BOLD + '-' * columns + END
|
||
|
print
|
||
|
print subprocess.check_output('w -i', shell=True)
|
||
|
print PURPLE + BOLD + '-' * columns + END
|
||
|
print
|
||
|
print(PURPLE + BOLD + '-' * columns + END)
|
||
|
print()
|
||
|
print(subprocess.check_output('w -i', shell=True).decode('utf-8'))
|
||
|
print(PURPLE + BOLD + '-' * columns + END)
|
||
|
print()
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
sys.exit(main())
|
||
Adding local updates to display.py that were never properly committed.