コード例 #1
0
 def RestoreReboots(self):
     pobjs = persistobj.GetPersistentObjects(objdir=self.config_dir,
                                             rootname=BOOTROOTNAME)
     reboots = []
     for pobj in pobjs:
         if hasattr(pobj, 'command_key'):
             reboots.append(('M Reboot', pobj.command_key))
         else:
             print 'Reboot object %s has no command_key' % pobj.filename
         pobj.Delete()
     return reboots
コード例 #2
0
ファイル: download.py プロジェクト: mhils/catawampus
 def RestoreDownloads(self):
   pobjs = persistobj.GetPersistentObjects(objdir=self.config_dir,
                                           rootname=DNLDROOTNAME)
   for pobj in pobjs:
     if not hasattr(pobj, 'command_key'):
       print 'Download Object %s has no command_key' % pobj.filename
       pobj.Delete()
       continue
     dl = DOWNLOADOBJ(stateobj=pobj,
                      transfer_complete_cb=self.TransferCompleteCallback)
     self._downloads.append(dl)
     dl.RebootCallback(0, None)
コード例 #3
0
ファイル: persistobj_test.py プロジェクト: prahlad574/my
 def testGetPersistentObjects(self):
     expected = [
         '{"foo": "bar1", "baz": 4}', '{"foo": "bar2", "baz": 5}',
         '{"foo": "bar3", "baz": 6}', 'This is not a JSON file'
     ]  # test corrupt file hanlding
     for obj in expected:
         with tempfile.NamedTemporaryFile(dir=self.tmpdir,
                                          prefix='tr69_dnld',
                                          delete=False) as f:
             f.write(obj)
     actual = persistobj.GetPersistentObjects(self.tmpdir)
     self.assertEqual(len(actual), len(expected) - 1)
     found = [False, False, False]
     for entry in actual:
         if entry.foo == 'bar1' and entry.baz == 4:
             found[0] = True
         if entry.foo == 'bar2' and entry.baz == 5:
             found[1] = True
         if entry.foo == 'bar3' and entry.baz == 6:
             found[2] = True
     self.assertTrue(found[0])
     self.assertTrue(found[1])
     self.assertTrue(found[2])