mirror of
https://github.com/gryf/wmdocklib.git
synced 2025-12-21 21:38:03 +01:00
up to version 0.1.3
This commit is contained in:
@@ -4,5 +4,5 @@
|
|||||||
2. Copy pywmhdmon.py to somewhere in your path (like ~/bin or
|
2. Copy pywmhdmon.py to somewhere in your path (like ~/bin or
|
||||||
/usr/local/bin).
|
/usr/local/bin).
|
||||||
|
|
||||||
3. Copy the sample.pywmhdmon to ~/.pywmhdmon and edit as you like.
|
3. Copy the sample.pywmhdmonrc to ~/.pywmhdmonrc and edit as you like.
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,12 @@ As usual, I didn't find a dockapp that fitted me. And I really like to
|
|||||||
see the current disk activity since my disks are so quiet that I can't
|
see the current disk activity since my disks are so quiet that I can't
|
||||||
hear when they work.
|
hear when they work.
|
||||||
|
|
||||||
[CONTACT]
|
[BUGS]
|
||||||
Mail anything related to this program to me, Kristoffer Erlandsson,
|
The activity bar does not work with the proc filesystem that comes with
|
||||||
<krier115@student.liu.se>
|
the 2.6 kernels. It is just a matter of rewriting the app to parse the
|
||||||
|
new format, but I'm low on time personally.
|
||||||
|
|
||||||
|
[CONTACT]
|
||||||
|
Contact me with anything regarding this program, see
|
||||||
|
http://errl.info/contact.html for ways to do this.
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,16 @@ Licensed under the GNU General Public License.
|
|||||||
|
|
||||||
|
|
||||||
Changes
|
Changes
|
||||||
|
2004-07-15 Kristoffer Erlandsson
|
||||||
|
Added a patch from Mario Frasca (Thanks!) which prevents the app from showing
|
||||||
|
the data from the host file system if there is no filesystem mounted at the
|
||||||
|
given point.
|
||||||
|
|
||||||
|
2003-09-01 Kristoffer Erlandsson
|
||||||
|
Fixed a bug where the numbers wouldn't show if they were between 1000 and 1024.
|
||||||
|
|
||||||
|
2003-06-25 Kristoffer Erlandsson
|
||||||
|
Fixed a bug where a mouse click caused the app to enter an infinite loop
|
||||||
|
|
||||||
2003-06-24 Kristoffer Erlandsson
|
2003-06-24 Kristoffer Erlandsson
|
||||||
Additional fine tuning
|
Additional fine tuning
|
||||||
@@ -71,9 +81,12 @@ digits = '0123456789:/-%. '
|
|||||||
defaultConfigFile = '~/.pywmhdmonrc'
|
defaultConfigFile = '~/.pywmhdmonrc'
|
||||||
defaultRGBFiles = ('/usr/lib/X11/rgb.txt', '/usr/X11R6/lib/X11/rgb.txt')
|
defaultRGBFiles = ('/usr/lib/X11/rgb.txt', '/usr/X11R6/lib/X11/rgb.txt')
|
||||||
defaultProcStat = '/proc/stat'
|
defaultProcStat = '/proc/stat'
|
||||||
displayModes = ('bar', 'percent', 'free')
|
displayModes = ('bar', 'percent', 'free', 'used')
|
||||||
defaultMode = 'bar'
|
defaultMode = 'bar'
|
||||||
|
|
||||||
|
class NotMounted(OSError):
|
||||||
|
pass
|
||||||
|
|
||||||
class PywmHDMon:
|
class PywmHDMon:
|
||||||
def __init__(self, pathsToMonitor, procStat='/proc/stat', actMonEnabled=1):
|
def __init__(self, pathsToMonitor, procStat='/proc/stat', actMonEnabled=1):
|
||||||
self._pathsToMonitor = pathsToMonitor
|
self._pathsToMonitor = pathsToMonitor
|
||||||
@@ -97,10 +110,20 @@ class PywmHDMon:
|
|||||||
'''Get the free and total space of the filesystem which path is on.
|
'''Get the free and total space of the filesystem which path is on.
|
||||||
|
|
||||||
Return a tuple with (<total space>, <free space>) in bytes. Raise
|
Return a tuple with (<total space>, <free space>) in bytes. Raise
|
||||||
OSError if we can't stat the path.
|
OSError if we can't stat the path. Raise NotMounted if not mounted.
|
||||||
These operations are quite costly, not adviced to perform these checks
|
These operations are quite costly, not adviced to perform these checks
|
||||||
more than once every 10 seconds.
|
more than once every 10 seconds.
|
||||||
'''
|
'''
|
||||||
|
# check if is mounted <- st_dev(/mount/point) == st_dev(/mount)
|
||||||
|
if path is not '/':
|
||||||
|
statOwn = os.stat(path)
|
||||||
|
|
||||||
|
# the following is a bit ugly: it removes the trailing
|
||||||
|
# dirname from the mount point. split by '/', leave the
|
||||||
|
# last string, join back, check for empty string.
|
||||||
|
statCnt = os.stat('/'.join(path.split('/')[:-1]) or '/')
|
||||||
|
if statOwn[2] == statCnt[2]:
|
||||||
|
raise NotMounted
|
||||||
stat = os.statvfs(path)
|
stat = os.statvfs(path)
|
||||||
blockSize = stat.f_bsize
|
blockSize = stat.f_bsize
|
||||||
availableBlocks = stat.f_bavail
|
availableBlocks = stat.f_bavail
|
||||||
@@ -133,13 +156,19 @@ class PywmHDMon:
|
|||||||
def paintHdData(self, line, data, mode):
|
def paintHdData(self, line, data, mode):
|
||||||
total, free = data
|
total, free = data
|
||||||
xStart = width - xOffset - 6 * letterWidth - 1
|
xStart = width - xOffset - 6 * letterWidth - 1
|
||||||
if mode == 'percent':
|
if total==0:
|
||||||
|
self.addString('-----', xStart, self.getY(line))
|
||||||
|
pass
|
||||||
|
elif mode == 'percent':
|
||||||
percent = (float(free) / float(total)) * 100.0
|
percent = (float(free) / float(total)) * 100.0
|
||||||
percentStr = (str(int(round(percent))) + '%').rjust(5)
|
percentStr = (str(int(round(percent))) + '%').rjust(5)
|
||||||
self.addString(percentStr, xStart, self.getY(line))
|
self.addString(percentStr, xStart, self.getY(line))
|
||||||
elif mode == 'free':
|
elif mode == 'free':
|
||||||
freeStr = bytesToStr(free).rjust(5)
|
freeStr = bytesToStr(free).rjust(5)
|
||||||
self.addString(freeStr, xStart, self.getY(line))
|
self.addString(freeStr, xStart, self.getY(line))
|
||||||
|
elif mode == 'used':
|
||||||
|
totalStr = bytesToStr(total).rjust(5)
|
||||||
|
self.addString(totalStr, xStart, self.getY(line))
|
||||||
elif mode == 'bar':
|
elif mode == 'bar':
|
||||||
percentUsed = (float(total - free) / float(total)) * 100.0
|
percentUsed = (float(total - free) / float(total)) * 100.0
|
||||||
self.paintGraph(percentUsed, xStart, self.getY(line) + 2,
|
self.paintGraph(percentUsed, xStart, self.getY(line) + 2,
|
||||||
@@ -201,6 +230,7 @@ class PywmHDMon:
|
|||||||
while not event is None:
|
while not event is None:
|
||||||
if event['type'] == 'destroynotify':
|
if event['type'] == 'destroynotify':
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
event = pywmhelpers.getEvent()
|
||||||
|
|
||||||
def mainLoop(self):
|
def mainLoop(self):
|
||||||
counter = -1
|
counter = -1
|
||||||
@@ -217,6 +247,8 @@ class PywmHDMon:
|
|||||||
self.paintLabel(index + 1, label)
|
self.paintLabel(index + 1, label)
|
||||||
try:
|
try:
|
||||||
hdData = self.getHdInfo(path)
|
hdData = self.getHdInfo(path)
|
||||||
|
except NotMounted:
|
||||||
|
hdData = (0, 0)
|
||||||
except OSError, e:
|
except OSError, e:
|
||||||
sys.stderr.write(
|
sys.stderr.write(
|
||||||
"Can't get hd data from %s: %s\n" % (path, str(e)))
|
"Can't get hd data from %s: %s\n" % (path, str(e)))
|
||||||
@@ -316,19 +348,36 @@ def bytesToStr(bytes):
|
|||||||
gb = 1024 * mb
|
gb = 1024 * mb
|
||||||
tb = 1024 * gb
|
tb = 1024 * gb
|
||||||
pb = 1024 * tb
|
pb = 1024 * tb
|
||||||
numDigits = 3
|
|
||||||
if bytes < kb:
|
if bytes < kb:
|
||||||
return makeNumDigits(bytes, numDigits) + 'B'
|
size = bytes
|
||||||
|
letter = 'B'
|
||||||
|
#return makeNumDigits(bytes, numDigits) + 'B'
|
||||||
elif bytes < mb:
|
elif bytes < mb:
|
||||||
return makeNumDigits(bytes/kb, numDigits) + 'k'
|
size = bytes / kb
|
||||||
|
letter = 'k'
|
||||||
|
#return makeNumDigits(bytes/kb, numDigits) + 'k'
|
||||||
elif bytes < gb:
|
elif bytes < gb:
|
||||||
return makeNumDigits(bytes/mb, numDigits) + 'M'
|
size = bytes / mb
|
||||||
|
letter = 'M'
|
||||||
|
#return makeNumDigits(bytes/mb, numDigits) + 'M'
|
||||||
elif bytes < tb:
|
elif bytes < tb:
|
||||||
return makeNumDigits(bytes/gb, numDigits) + 'G'
|
size = bytes / gb
|
||||||
|
letter = 'G'
|
||||||
|
#return makeNumDigits(bytes/gb, numDigits) + 'G'
|
||||||
elif bytes < pb:
|
elif bytes < pb:
|
||||||
return makeNumDigits(bytes/tb, numDigits) + 'T'
|
size = bytes / tb
|
||||||
|
letter = 'T'
|
||||||
|
#return makeNumDigits(bytes/tb, numDigits) + 'T'
|
||||||
else:
|
else:
|
||||||
return makeNumDigits(bytes/pb, numDigits) + 'P'
|
size = bytes / pb
|
||||||
|
letter = 'p'
|
||||||
|
#return makeNumDigits(bytes/pb, numDigits) + 'P'
|
||||||
|
if size >= 1000:
|
||||||
|
res = makeNumDigits(size, 4)
|
||||||
|
else:
|
||||||
|
res = makeNumDigits(size, 3)
|
||||||
|
res += letter
|
||||||
|
return res
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|||||||
26
pywmhdmon/sample.pywmhdmonrc
Normal file
26
pywmhdmon/sample.pywmhdmonrc
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
[DEFAULT]
|
||||||
|
# Displaymodes are free, percent or bar, displays the free size, free percent
|
||||||
|
# and a bar representing space, respectively.
|
||||||
|
1.label=/
|
||||||
|
1.path=/
|
||||||
|
1.displaymode=free
|
||||||
|
|
||||||
|
2.label=c
|
||||||
|
2.path=/mnt/c
|
||||||
|
2.displaymode=free
|
||||||
|
|
||||||
|
3.label=d
|
||||||
|
3.path=/mnt/d
|
||||||
|
3.displaymode=free
|
||||||
|
|
||||||
|
4.label=e
|
||||||
|
4.path=/mnt/e
|
||||||
|
4.displaymode=free
|
||||||
|
|
||||||
|
textcolor=light sea green
|
||||||
|
background=black
|
||||||
|
barfgcolor=light sea green
|
||||||
|
barbgcolor=grey45
|
||||||
|
|
||||||
|
#rgbfile=/usr/lib/X11/rgb.txt
|
||||||
|
|
||||||
Reference in New Issue
Block a user