Exemplo n.º 1
0
 def status(self):
     """
     Parses /proc/<pid>/status and returns an AttrDict
     """
     fields = ('real', 'effective', 'saved_set', 'filesystem')
     with open("status", opener=self._opener) as file:
         lines = file.read().splitlines()
     status = AttrDict(
         {k: try_int(v)
          for k, v in [_.split(':\t', 1) for _ in lines]})
     status.update({
         'Uid':
         AttrDict(zip(fields, map(Uid, status.Uid.split()))),
         'Gid':
         AttrDict(zip(fields, map(Gid, status.Gid.split()))),
         'Groups':
         list(map(Gid,
                  str(status.Groups).split()))
     })
     status.update({
         k: int(status[k].replace('kB', '').strip())
         for k in ('HugetlbPages', 'RssAnon', 'RssFile', 'RssShmem',
                   'VmData', 'VmExe', 'VmHWM', 'VmLck', 'VmLib', 'VmPeak',
                   'VmPin', 'VmPMD', 'VmPTE', 'VmRSS', 'VmSize', 'VmStk',
                   'VmSwap') if k in status
     })
     return status
Exemplo n.º 2
0
 def test_AttrDict(self):
     d = AttrDict({'a': 1})
     self.assertIsInstance(d, AttrDict)
     self.assertIs(d.a, d['a'])
     del d.a
     self.assertEqual(d, {})
     d['b'] = 2
     self.assertIs(d.b, d['b'])
     del d['b']
     self.assertEqual(d, {})
     self.assertIsNone(d.get('a', None))
     self.assertEqual(d.get('a', 777), 777)
     _d = {'a': 888}
     d.update(_d)
     self.assertEqual(d, _d)