--- projects/pystatgrab/_statgrab.pyx 2005/09/14 18:15:44 1.18 +++ projects/pystatgrab/_statgrab.pyx 2008/06/16 21:06:49 1.21 @@ -17,7 +17,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # -# $Id: _statgrab.pyx,v 1.18 2005/09/14 18:15:44 ats Exp $ +# $Id: _statgrab.pyx,v 1.21 2008/06/16 21:06:49 tdb Exp $ # ctypedef long time_t @@ -27,6 +27,8 @@ ctypedef int gid_t cdef extern from "statgrab.h": cdef extern int sg_init() + cdef extern int sg_shutdown() + cdef extern int sg_snapshot() cdef extern int sg_drop_privileges() ctypedef enum sg_error: @@ -272,16 +274,17 @@ py_SG_PROCESS_STATE_ZOMBIE = SG_PROCESS_STATE_ZOMBIE py_SG_PROCESS_STATE_UNKNOWN = SG_PROCESS_STATE_UNKNOWN -class Result: +class Result(dict): def __init__(self, attrs): - self.attrs = attrs - for attr in attrs: - setattr(self, attr, attrs[attr]) - def __getitem__(self, item): - return getattr(self, item) - def __repr__(self): - return str(self.attrs) + self.attrs = attrs # to maintain compatibility + super(Result, self).__init__(attrs) + def __getattr__(self, item): + try: + return self.__getitem__(item) + except KeyError: + raise AttributeError(item) + class StatgrabException(Exception): def __init__(self, value): self.value = value @@ -291,6 +294,18 @@ class StatgrabException(Exception): def py_sg_init(): if sg_init() == 0: + return True + else: + return False + +def py_sg_shutdown(): + if sg_shutdown() == 0: + return True + else: + return False + +def py_sg_snapshot(): + if sg_snapshot() == 0: return True else: return False