def main(): options, args = handleopts() if args: kfname = args[0] else: kfname = None keys.loadKeys(kfname) if options.add: if keys.addKey(options.add): print "Successfully added key: %s" % (options.add) keys.saveKeys() sys.exit(0) else: print "Invalid key: %s, exiting" % (options.add) sys.exit(1) elif options.remove: # Note on implementation this will call keys.remove(key) in a try # block like above print "Option currently disabled, key removal is not yet implemented" sys.exit(1) else: i = 0 for k in keys._KEYS: i += 1 print '%s. %s: %s' % (i,k.name, k) sys.exit(0)
def test_saveKeys(self): import os, os.path print "Testing SaveKeys...", keys._KEYFILE = '' self.assertRaises(Exception, keys.saveKeys) kf = prependdir+'xml/keys3' keys.loadKeys(prependdir+'xml/keys') os.remove(kf) if os.path.exists(kf): raise Exception, 'didnt delete kf' keys._KEYFILE = kf x = keys._KEYS keys.saveKeys() keys.loadKeys(kf) self.assert_(os.path.exists(kf), "FAILED (kf doesnt exits)") self.assert_(x == keys._KEYS, "FAILED (didnt save right)") print "OK"
def test_saveKeys(self): import os, os.path print "Testing SaveKeys...", keys._KEYFILE = "" self.assertRaises(Exception, keys.saveKeys) kf = prependdir + "xml/keys3" keys.loadKeys(prependdir + "xml/keys") os.remove(kf) if os.path.exists(kf): raise Exception, "didnt delete kf" keys._KEYFILE = kf x = keys._KEYS keys.saveKeys() keys.loadKeys(kf) self.assert_(os.path.exists(kf), "FAILED (kf doesnt exits)") self.assert_(x == keys._KEYS, "FAILED (didnt save right)") print "OK"