ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/pystatgrab/_statgrab.pyx
(Generate patch)

Comparing projects/pystatgrab/_statgrab.pyx (file contents):
Revision 1.16 by tdb, Sat Jul 30 10:49:42 2005 UTC vs.
Revision 1.21 by tdb, Mon Jun 16 21:06:49 2008 UTC

# Line 27 | Line 27 | ctypedef int gid_t
27  
28   cdef extern from "statgrab.h":
29      cdef extern int sg_init()
30 +    cdef extern int sg_shutdown()
31 +    cdef extern int sg_snapshot()
32      cdef extern int sg_drop_privileges()
33  
34      ctypedef enum sg_error:
# Line 140 | Line 142 | cdef extern from "statgrab.h":
142          long long total_inodes
143          long long used_inodes
144          long long free_inodes
145 +        long long avail_inodes
146 +        long long io_size
147 +        long long block_size
148 +        long long total_blocks
149 +        long long free_blocks
150 +        long long used_blocks
151 +        long long avail_blocks
152  
153      cdef extern sg_fs_stats *sg_get_fs_stats(int *entries)
154  
# Line 265 | Line 274 | py_SG_PROCESS_STATE_ZOMBIE = SG_PROCESS_STATE_ZOMBIE
274   py_SG_PROCESS_STATE_UNKNOWN = SG_PROCESS_STATE_UNKNOWN
275  
276  
277 < class Result:
277 > class Result(dict):
278      def __init__(self, attrs):
279 <        self.attrs = attrs
280 <        for attr in attrs:
272 <            setattr(self, attr, attrs[attr])
273 <    def __getitem__(self, item):
274 <        return getattr(self, item)
275 <    def __repr__(self):
276 <        return str(self.attrs)
279 >        self.attrs = attrs # to maintain compatibility
280 >        super(Result, self).__init__(attrs)
281  
282 +    def __getattr__(self, item):
283 +        try:
284 +            return self.__getitem__(item)
285 +        except KeyError:
286 +            raise AttributeError(item)
287 +
288   class StatgrabException(Exception):
289      def __init__(self, value):
290          self.value = value
# Line 288 | Line 298 | def py_sg_init():
298      else:
299          return False
300  
301 + def py_sg_shutdown():
302 +    if sg_shutdown() == 0:
303 +        return True
304 +    else:
305 +        return False
306 +
307 + def py_sg_snapshot():
308 +    if sg_snapshot() == 0:
309 +        return True
310 +    else:
311 +        return False
312 +
313   def py_sg_drop_privileges():
314      if sg_drop_privileges() == 0:
315          return True
# Line 448 | Line 470 | def py_sg_get_fs_stats():
470               'total_inodes': s.total_inodes,
471               'used_inodes': s.used_inodes,
472               'free_inodes': s.free_inodes,
473 +             'avail_inodes': s.avail_inodes,
474 +             'io_size': s.io_size,
475 +             'block_size': s.block_size,
476 +             'total_blocks': s.total_blocks,
477 +             'free_blocks': s.free_blocks,
478 +             'used_blocks': s.used_blocks,
479 +             'avail_blocks': s.avail_blocks,
480              }
481          ))
482          s = s + 1
# Line 583 | Line 612 | def py_sg_get_process_stats():
612          raise StatgrabException, 'sg_get_process_stats() returned NULL'
613      list = []
614      for i from 0 <= i < entries:
615 <        if s.process_name == NULL:
616 <            s.process_name = ''
617 <        if s.proctitle == NULL:
618 <            s.proctitle = ''
615 >        if s.process_name is NULL:
616 >            process_name = ''
617 >        else:
618 >            process_name = s.process_name
619 >        if s.proctitle is NULL:
620 >            proctitle = ''
621 >        else:
622 >            proctitle = s.proctitle
623          list.append(Result(
624 <            {'process_name': s.process_name,
625 <             'proctitle' : s.proctitle,
624 >            {'process_name': process_name,
625 >             'proctitle' : proctitle,
626               'pid' : s.pid,
627               'parent' : s.parent,
628               'pgid' : s.pgid,

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines