예제 #1
0
파일: keymanage.py 프로젝트: Ads7/isbndb-py
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)
예제 #2
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"
예제 #3
0
파일: key_test.py 프로젝트: Ads7/isbndb-py
    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"