Skip to content

Commit

Permalink
Merge pull request #66 from hongquan/hd-script
Browse files Browse the repository at this point in the history
Rewrite HD scripts in Python3
  • Loading branch information
helmuthdu authored May 7, 2018
2 parents df2bb4b + c43f380 commit be8d5df
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 94 deletions.
35 changes: 18 additions & 17 deletions conkycolors/scripts/conkyHD1.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
#!/usr/bin/env python
from os.path import normpath, basename, ismount
import subprocess
#!/usr/bin/env python3

devices = subprocess.Popen(["lsblk | awk '{print $7}' | grep /"], shell=True, stdout=subprocess.PIPE)
import sys
from os.path import abspath, dirname

print ("${voffset 4}")
directory = dirname(abspath(__file__))
sys.path.insert(0, directory)

for device in devices.stdout:
device = device.rstrip().decode("utf-8")
if device == u'/boot/efi':
continue
if (ismount(device)):
if (device == u"/"):
devicename="Root"
else:
devicename = basename(normpath(device)).capitalize()
from hdcommon import get_partitions

print ("${voffset -10}${offset 0}${color0}${font ConkyColors:size=15}i${font}${color}${offset 6}${voffset -10}"+devicename+": ${font Ubuntu:style=Bold:size=8}${color1}${fs_free_perc "+device+"}%${color}${font}\n")
print ("${voffset -10}${offset 1}${color0}${fs_bar 4,17 "+device+"}${color}${offset 10}${voffset -2}F: ${font Ubuntu:style=Bold:size=8}${color2}${fs_free "+device+"}${color}${font} U: ${font Ubuntu:style=Bold:size=8}${color2}${fs_used "+device+"}${color}${font}\n")

print ("${voffset -10}")
print("${voffset 4}")

for device, devicename in get_partitions():
var_map = {'device': device, 'devicename': devicename}
print("${voffset -10}${offset 0}${color0}${font ConkyColors:size=15}i${font}${color}${offset 6}"
"${voffset -10}%(devicename)s: ${font Ubuntu:style=Bold:size=8}${color1}"
"${fs_free_perc %(device)s}%%${color}${font}\n" % var_map)
print("${voffset -10}${offset 1}${color0}${fs_bar 4,17 %(device)s}${color}${offset 10}"
"${voffset -2}F: ${font Ubuntu:style=Bold:size=8}${color2}${fs_free %(device)s}${color}"
"${font} U: ${font Ubuntu:style=Bold:size=8}${color2}${fs_used %(device)s}${color}${font}\n" % var_map)

print("${voffset -10}")
50 changes: 19 additions & 31 deletions conkycolors/scripts/conkyHD2.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,23 @@
#!/usr/bin/env python
from os.path import normpath, basename, ismount
import subprocess
#!/usr/bin/env python3

import os
import sys
from os.path import abspath, dirname

directory = dirname(abspath(__file__))
sys.path.insert(0, directory)

from hdcommon import get_partitions, get_pie_chart_icon

devices = subprocess.Popen(["lsblk | awk '{print $7}' | grep /"], shell=True, stdout=subprocess.PIPE,)

print ("${voffset 4}")

for device in devices.stdout:
device = device.rstrip().decode("utf-8")
if (ismount(device)):
if (device is "/"):
devicename="Root"
else:
devicename = basename(normpath(device)).capitalize()

# start calculation dec value (for the pie chart symbol)
statb = subprocess.Popen("stat -f -c %b "+device+"", shell=True, stdout=subprocess.PIPE,)
statb_value = statb.communicate()[0]
statf = subprocess.Popen("stat -f -c %f "+device+"", shell=True, stdout=subprocess.PIPE,)
statf_value = statf.communicate()[0]
total = int(statb_value)
used = total - int(statf_value)
dec = int((((used * 100) / total) + 5) / 10)
if dec > 9:
icon = "0"
elif dec < 1:
icon = "A"
else:
icon = str(dec)
# end calculation dec

print ("${voffset -6}${color0}${font Pie charts for maps:size=14}"+icon+"${font}${color}${offset 9}${voffset -5}"+devicename+": ${font Ubuntu:style=Bold:size=8}${color1}${fs_free_perc "+device+"}%${color} ${alignr}${color2}${fs_free "+device+"}${color}${font}\n")

print ("${voffset -10}")
for device, devicename in get_partitions():
icon = get_pie_chart_icon(device)

print("${voffset -6}${color0}${font Pie charts for maps:size=14}%(icon)s${font}${color}"
"${offset 9}${voffset -5}%(devicename)s: ${font Ubuntu:style=Bold:size=8}${color1}"
"${fs_free_perc %(device)s}%%${color} ${alignr}${color2}${fs_free %(device)s}${color}${font}\n"
% {'device': device, 'devicename': devicename, 'icon': icon})

print("${voffset -10}")
54 changes: 22 additions & 32 deletions conkycolors/scripts/conkyHD3.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,26 @@
#!/usr/bin/env python
from os.path import normpath, basename, ismount
import subprocess
#!/usr/bin/env python3

import os
import sys
from os.path import abspath, dirname

directory = dirname(abspath(__file__))
sys.path.insert(0, directory)

from hdcommon import get_partitions, get_pie_chart_icon

devices = subprocess.Popen(["lsblk | awk '{print $7}' | grep /"], shell=True, stdout=subprocess.PIPE,)

print ("${voffset 4}")

for device in devices.stdout:
device = device.rstrip().decode("utf-8")
if (ismount(device)):
if (device is "/"):
devicename="Root"
else:
devicename = basename(normpath(device)).capitalize()

# start calculation dec value (for the pie chart symbol)
statb = subprocess.Popen("stat -f -c %b "+device+"", shell=True, stdout=subprocess.PIPE,)
statb_value = statb.communicate()[0]
statf = subprocess.Popen("stat -f -c %f "+device+"", shell=True, stdout=subprocess.PIPE,)
statf_value = statf.communicate()[0]
total = int(statb_value)
used = total - int(statf_value)
dec = int((((used * 100) / total) + 5) / 10)
if dec > 9:
icon = "0"
elif dec < 1:
icon = "A"
else:
icon = str(dec)
# end calculation dec

print ("${voffset -10}${color0}${font Pie charts for maps:size=15}"+icon+"${font}${color}${offset 9}${voffset -9}"+devicename+": ${font Ubuntu:style=Bold:size=8}${color1}${fs_free_perc "+device+"}%${color}${font}\n")
print ("${voffset -10}${offset 29}F: ${font Ubuntu:style=Bold:size=8}${color2}${fs_free "+device+"}${color}${font} U: ${font Ubuntu:style=Bold:size=8}${color2}${fs_used "+device+"}${color}${font}\n")

print ("${voffset -10}")
for device, devicename in get_partitions():
icon = get_pie_chart_icon(device)
var_map = {'device': device, 'devicename': devicename, 'icon': icon}

print("${voffset -10}${color0}${font Pie charts for maps:size=15}%(icon)s"
"${font}${color}${offset 9}${voffset -9}%(devicename)s: "
"${font Ubuntu:style=Bold:size=8}${color1}${fs_free_perc %(device)s}%%${color}${font}\n" % var_map)
print("${voffset -10}${offset 29}F: ${font Ubuntu:style=Bold:size=8}${color2}"
"${fs_free %(device)s}${color}${font} U: ${font Ubuntu:style=Bold:size=8}${color2}"
"${fs_used %(device)s}${color}${font}\n" % var_map)

print("${voffset -10}")
30 changes: 16 additions & 14 deletions conkycolors/scripts/conkyHD4.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
#!/usr/bin/env python
from os.path import normpath, basename, ismount
import subprocess
#!/usr/bin/env python3

devices = subprocess.Popen(["lsblk | awk '{print $7}' | grep /"], shell=True, stdout=subprocess.PIPE,)
import os
import sys
from os.path import abspath, dirname

print ("${voffset 4}${color0}${font ConkyColors:size=18}h${font}${color}${voffset 5}${offset -21}${diskiograph 4,17}${voffset -32}\n")
directory = dirname(abspath(__file__))
sys.path.insert(0, directory)

for device in devices.stdout:
device = device.rstrip().decode("utf-8")
if (ismount(device)):
if (device is "/"):
devicename="Root"
else:
devicename = basename(normpath(device)).capitalize()
from hdcommon import get_partitions

print ("${voffset -10}${goto 32}"+devicename+": ${font Ubuntu:style=Bold:size=8}${color1}${fs_free_perc "+device+"}%${color}${font} ${alignr}${font Ubuntu:style=Bold:size=8}${color2}${fs_free "+device+"}${color}${font}\n")

print ("${voffset -10}")
print("${voffset 4}${color0}${font ConkyColors:size=18}h${font}${color}${voffset 5}${offset -21}${diskiograph 4,17}${voffset -32}\n")

for device, devicename in get_partitions():
print("${voffset -10}${goto 32}%(devicename)s: ${font Ubuntu:style=Bold:size=8}${color1}"
"${fs_free_perc %(device)s}%%${color}${font} ${alignr}${font Ubuntu:style=Bold:size=8}"
"${color2}${fs_free %(device)s}${color}${font}\n"
% {'device': device, 'devicename': devicename})

print("${voffset -10}")
36 changes: 36 additions & 0 deletions conkycolors/scripts/hdcommon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env python3

import os
from os.path import normpath, basename, ismount
from subprocess import Popen, PIPE

def get_partitions():
p_lsblk = Popen(['lsblk'], stdout=PIPE)
p_awk = Popen(['awk', '{print $7}'], stdin=p_lsblk.stdout, stdout=PIPE)
p_grep = Popen(['grep', '/'], stdin=p_awk.stdout, stdout=PIPE)
p_lsblk.stdout.close()
p_awk.stdout.close()
output = p_grep.communicate()[0]
for line in output.splitlines():
device = line.rstrip().decode('utf-8')
if not ismount(device):
continue
if device.startswith('/snap/') or device == '/boot/efi':
continue
if (device == "/"):
yield device, "Root"
else:
yield device, basename(normpath(device)).capitalize()


def get_pie_chart_icon(device):
stat = os.statvfs(device)
total = stat.f_blocks
free = stat.f_bfree
used = total - free
dec = int((((used * 100) / total) + 5) / 10)
if dec > 9:
return "0"
if dec < 1:
return "A"
return str(dec)

0 comments on commit be8d5df

Please sign in to comment.