From d55d4782430a241b364b8a41965dc8a4a54b6834 Mon Sep 17 00:00:00 2001 From: arcan1s Date: Tue, 8 Oct 2013 21:56:08 +0400 Subject: [PATCH] Added network, hdd/hddtemp and battery notification --- TODO | 6 +-- sources/contents/code/ptmnotify.py | 60 +++++++++++++++++++++--------- 2 files changed, 44 insertions(+), 22 deletions(-) diff --git a/TODO b/TODO index 18faa5f..19d4a8c 100644 --- a/TODO +++ b/TODO @@ -1,8 +1,4 @@ -1. Notification on left click (system information): - e) hdd, hddtemp - hdd, hddtemp, disk information - f) network - speed, network information - g) battery - battery, ac, acpi information -2. Tooltip (graphical information): +1. Tooltip (graphical information): a) cpu, % b) cpuclock, mhz c) memory, % diff --git a/sources/contents/code/ptmnotify.py b/sources/contents/code/ptmnotify.py index 7bc7259..4cf7d6e 100644 --- a/sources/contents/code/ptmnotify.py +++ b/sources/contents/code/ptmnotify.py @@ -2,7 +2,6 @@ from PyKDE4.kdecore import KComponentData from PyKDE4.kdeui import KNotification -from PyKDE4.plasma import Plasma import commands @@ -33,25 +32,25 @@ class PTMNotify: text = "" if (type == "system"): try: - text = text + "Kernel: " + commands.getoutput("uname -rsm") + "\n" - text = text + "Hostname: " + commands.getoutput("uname -n") + "\n" - text = text + "Whoami: " + commands.getoutput("whoami") + "\n" - text = text + "Uptime: " + commands.getoutput("uptime") + text = text + "Kernel: %s\n" %(commands.getoutput("uname -rsm")) + text = text + "Hostname: %s\n" %(commands.getoutput("uname -n")) + text = text + "Whoami: %s\n" %(commands.getoutput("whoami")) + text = text + "Uptime: %s\n" %(commands.getoutput("uptime")) except: pass elif (type == "processor"): try: output = commands.getoutput("grep 'model name' /proc/cpuinfo | head -1") - text = text + "Model: " + ' '.join(output.split()[3:]) + "\n" + text = text + "Model: %s\n" %(' '.join(output.split()[3:])) output = commands.getoutput("sar -u | tail -1") - text = text + "CPU Usage: " + str(100-float(output[-1])) + "%\n" + text = text + "CPU Usage: %s%%\n" %(str(100-float(output.split()[-1]))) output = commands.getoutput("grep MHz /proc/cpuinfo | head -1") - text = text + "CPU Freq: " + str(int(float(output.split()[-1]))) + " MHz\n" + text = text + "CPU Freq: %s MHz\n" %(str(int(float(output.split()[-1])))) output = commands.getoutput("sensors -u") text = text + "Temps:" for line in output.split("\n"): if (line.find("_input") > -1): - text = text + " " + str(round(float(line.split()[-1]), 0)) + "\xb0C" + text = text + " %s\xb0C" %(str(round(float(line.split()[-1]), 0))) except: pass elif (type == "graphical"): @@ -62,8 +61,7 @@ class PTMNotify: elif (output.lower().find('radeon') > -1): gpudev = "ati" for line in output.split("\n"): - text = text + line.split('"')[0] + " " - text = text + line.split('"')[5] + "\n" + text = text + "%s %s\n" %(line.split('"')[0], line.split('"')[5]) if (gpudev == 'nvidia'): output = commands.getoutput("nvidia-smi -q -d UTILIZATION | grep Gpu | tail -n1") try: @@ -78,7 +76,7 @@ class PTMNotify: value = " N\A" else: value = " N\A" - text = text + "Load: " + value + "%\n" + text = text + "Load: %s%%\n" %(value) if (gpudev == 'nvidia'): output = commands.getoutput("nvidia-smi -q -d TEMPERATURE | grep Gpu | tail -n1") try: @@ -93,17 +91,45 @@ class PTMNotify: value = " N\A" else: value = " N\A" - text = text + "Temp: " + value + "\xb0C" + text = text + "Temp: %s\xb0C\n" %(value) except: pass elif (type == "memory"): try: - output = commands.getoutput("free -mo").split("\n") + output = commands.getoutput("free -m -o").split("\n") memusage = int(output[1].split()[1]) - (int(output[1].split()[3]) + int(output[1].split()[5]) + int(output[1].split()[6])) - text = text + "Memory: " + str(memusage) + " of " + output[1].split()[1] + " (" + str(int(100*memusage/int(output[1].split()[1]))) + "%)\n" - text = text + "Swap: " + output[2].split()[2] + " of " + output[2].split()[1] + " (" + str(int(100*int(output[2].split()[2])/int(output[2].split()[1]))) + "%)\n" + text = text + "Memory: %s of %s (%s%%)\n" %(str(memusage), output[1].split()[1], str(int(100*memusage/int(output[1].split()[1])))) + text = text + "Swap: %s of %s (%s%%)\n" %(output[2].split()[2], output[2].split()[1], str(int(100*int(output[2].split()[2])/int(output[2].split()[1])))) output = commands.getoutput("swapon --show").split("\n") - text = text + "Swap Device: " + output[1].split()[0] + " (" + output[1].split()[1] + ")" + text = text + "Swap Device: %s (%s)" %(output[1].split()[0], output[1].split()[1]) + except: + pass + elif (type == "disk"): + try: + output = commands.getoutput("df -h --output='source,target,used,size,pcent' --exclude-type=fuseblk --exclude-type=tmpfs --exclude-type=devtmpfs").split("\n")[1:] + for line in output: + text = text + "%s (to %s): %s of %s (%s)\n" %(line.split()[0], line.split()[1], line.split()[2], line.split()[3], line.split()[4]) + except: + pass + elif (type == "network"): + try: + output = commands.getoutput("ifconfig -a -s").split("\n")[1:] + text = text + "Devices:" + for line in output: + text = text + " %s" %(line.split()[0]) + output = commands.getoutput("ifconfig -a -s " + self.parent.parent.netdev + " && sleep 0.2 && ifconfig -a -s " + self.parent.parent.netdev).split("\n") + download = int((int(output[3].split()[2]) - int(output[1].split()[2])) / (0.2 * 1024)) + upload = int((int(output[3].split()[6]) - int(output[1].split()[6])) / (0.2 * 1024)) + text = text + "\n%s: %s/%s KB/s\n" %(self.parent.parent.netdev, download, upload) + output = commands.getoutput("ifconfig " + self.parent.parent.netdev + " | grep 'inet '").split()[1] + text = text + "IP: %s\n" %(output[:-1]) + output = commands.getoutput("wget http://checkip.dyndns.org/ -q -O - | awk '{print $6}' | sed 's/<.*>//g'") + text = text + "External IP: %s" %(output[:-1]) + except: + pass + elif (type == "battery"): + try: + text = text + "%s" %(commands.getoutput("acpi -abi")) except: pass