usr bin env python coding utf-8 import re import sys from time import

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import re
import sys
from time import sleep
from thread import start_new_thread
import os
_widgetName = "storage"
_devices = {
'/mnt/cdrom' : 'C',
'/mnt/flash' : 'F',
'/mnt/floppy' : 'f'
}
_awesome_client_path = "%s/bin/awesome-client" % os.environ.get('HOME')
_spaces = ' '*4
def get_storage_status():
# TODO: without awk
result = ''
try:
f = open('/etc/mtab')
mtab = f.read()
f.close()
for i in _devices:
result += ((mtab.find(i) != -1) and _devices[i]) or '-'
return '[ %s ]' % result
except:
return '[ %) ]'
if __name__ == "__main__":
if len(sys.argv) > 1:
_widgetName = sys.argv[1]
while 1:
try:
pipe = os.popen(_awesome_client_path, 'w')
pipe.write( "0 widget_tell %s %s%s\n" % (_widgetName, _spaces, get_storage_status()) )
pipe.close()
finally:
pass
sleep(1)