xmonader / pytasker (http://programming-fr34ks.net/)

all what you need to know about any task.

Clone this repository (size: 9.8 KB): HTTPS / SSH
$ hg clone http://bitbucket.org/xmonader/pytasker/

Changed (Δ821 bytes):

raw changeset »

pytasker/taskman.py (36 lines added, 6 lines removed)

Up to file-list pytasker/taskman.py:

22
22
import sys
23
23
import os #stat
24
24
import pwd #getpwuid
25
import re
25
26
26
27
PROC_DIR_1="/compat/linux/proc"
27
28
PROC_DIR_2="/emul/linux/proc"
@@ -65,6 +66,9 @@ class SystemStatus(object):
65
66
        self.cpuoldused=cpuoldused
66
67
        self.validprocreading=validprocreading
67
68
        
69
    def report(self):
70
        for attr, value in self.__dict__.items():
71
            print attr, " =>" , value
68
72
        
69
73
def get_task_by_pid(pid): #returns Task
70
74
@@ -114,15 +118,41 @@ def iget_tasks(): #tasklist
114
118
def get_task_list():
115
119
    return list(iget_tasks())
116
120
117
def get_system_status(sysstatus):
118
    raise NotImplementedError
121
def get_system_status():
122
    f=None
123
    sysstatus=SystemStatus()
124
    
125
    try:
126
        f=open("/proc/meminfo")
127
        meminfo=f.read()
128
        sysstatus.memtotal=int(re.findall("MemTotal:\s+(\d+) kB", meminfo)[0])
129
        sysstatus.memfree=int(re.findall("MemFree:\s+(\d+) kB", meminfo)[0])
130
        sysstatus.cached=int(re.findall("Cached:\s+(\d+) kB", meminfo)[0])
131
    except Exception, ex:
132
        print ex
133
        
134
    if f is not None:
135
        f.close()
136
        
137
    try:
138
        f=open("/proc/cpuinfo")
139
        cpuinfo=f.read()
140
        sysstatus.cpucount=re.findall("processor[\s:?]*(\d+)\s*", cpuinfo)[-1]
141
    except Exception, ex:
142
        print ex
143
        
144
    if f is not None:
145
        f.close()
146
147
    return sysstatus
119
148
    
120
149
def get_cpu_usage_from_proc(sysstatus):
121
150
    raise NotImplementedError
122
151
    
123
152
124
153
if __name__=="__main__":
125
    t=get_task_by_pid(3399) #totem process -- change it the way you like
126
    t.report()
127
    for task in get_task_list():
128
        print task.name
154
    #t=get_task_by_pid(3399) #totem process -- change it the way you like
155
    #t.report()
156
    #for task in get_task_list():
157
    #    print task.name
158
    #get_system_status().report()