From d779d0fdba8507708853e47c97c5baf1185e503a Mon Sep 17 00:00:00 2001 From: Massaki Archambault Date: Mon, 14 May 2018 15:32:55 -0400 Subject: [PATCH] compact motd memory, check if psutil is installed --- files/.local/bin/motd | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/files/.local/bin/motd b/files/.local/bin/motd index e2ec967..6e80503 100755 --- a/files/.local/bin/motd +++ b/files/.local/bin/motd @@ -1,7 +1,6 @@ #!/usr/bin/env python3 import math -import psutil import shutil import sys import os @@ -9,6 +8,11 @@ import re from subprocess import check_call, DEVNULL, CalledProcessError +try: + import psutil +except: + pass + try: from pyfiglet import figlet_format except ImportError: @@ -106,15 +110,18 @@ def print_services(): def print_mem(): - print('Memory:') - memory = psutil.virtual_memory() - Termutils.print_padded('{:.2f}G used {:6.2f}G free {:6.2f}G total'.format( - to_gb(memory.used), - to_gb(memory.free), - to_gb(memory.total) - )) - Termutils.print_progress_bar(memory.used / memory.total) - print('') + try: + memory = psutil.virtual_memory() + print('{:<18} {:6.2f}G used {:6.2f}G free {:6.2f}G total'.format( + 'Memory:', + to_gb(memory.used), + to_gb(memory.free), + to_gb(memory.total) + )) + Termutils.print_progress_bar(memory.used / memory.total) + print('') + except NameError: + pass def print_fs():