def TestWrite(self):
     self.store.Set('pig', 'grunt')
     self.store.Write()
     assert (self.store.Get('pig') == 'grunt')
     store2 = KV.KeyValueStore(self.temp_file, redhawk.GetVersion())
     assert (store2.Get('pig') == 'grunt')
     store2.Close()
Exemple #2
0
    def __init__(self, database_file, parser, store_new=True):
        self.database_file = database_file
        self.parser = parser
        self.store_new = store_new
        # logging.info("Reading..\n")
        if self.database_file is None:
            self.database = None
            return

        if not os.path.exists(database_file):
            logging.warning("Database %s does not exist." %
                            (self.database_file))
            self.database = None
            return

        if not KVStore.IsValidStore(database_file):
            print(database_file)
            logging.error("Not a valid store. Recreating..\n")
            KVStore.RemoveExistingStore(database_file)
            KVStore.CreateNewStore(database_file, redhawk.GetVersion())

        self.database = KVStore.KeyValueStore(database_file,
                                              redhawk.GetVersion())
        # logging.info("Done.")
        return
def TestBadVersionInitKeyValueStore():
    temp_file = GetTempFile()

    KV.CreateNewStore(temp_file, redhawk.GetVersion())
    store = shelve.open(temp_file, 'c')
    store[KV.VERSION_KEY] = '0.0.0'
    store = KV.KeyValueStore(temp_file, redhawk.GetVersion())
    return
def TestCreateAndRemoveStores():
    temp_file = GetTempFile()
    KV.CreateNewStore(temp_file, redhawk.GetVersion())
    store = KV.KeyValueStore(temp_file, redhawk.GetVersion())
    assert (store.GetVersion() == redhawk.GetVersion())
    store.Close()
    KV.RemoveExistingStore(temp_file)
    assert (not os.path.exists(temp_file))
    def setUp(self):
        setUp()
        self.temp_file = GetTempFile()
        KV.CreateNewStore(self.temp_file, redhawk.GetVersion())
        store = shelve.open(self.temp_file, 'c')
        store['dog'] = 'woof'
        store['cat'] = 'meow'
        store.close()

        self.store = KV.KeyValueStore(self.temp_file, redhawk.GetVersion())
        return
    def TestChangeVersion(self):
        self.store.Close()
        store = shelve.open(self.temp_file, 'c')
        store[KV.VERSION_KEY] = '0.0.0'
        store.close()

        temp_file = GetTempFile()
        fp = sys.stderr
        sys.stderr = sys.stdout

        print("Expected Error :")
        self.store = KV.KeyValueStore(self.temp_file, redhawk.GetVersion())

        sys.stderr = fp

        assert (self.store.GetVersion() == redhawk.GetVersion())
Exemple #7
0
def Main(args):
    parser = optparse.OptionParser(usage, description=description)
    options, args = parser.parse_args(args)

    if len(args):
        parser.error("Extra options given. This command takes no options!")

    database_file = S.GetDatabase()

    if database_file is None:
        S.ExitWithError(
            S.MakeStringFromTemplate(
                "No database found. Maybe $prog init first?"))

    store = KVStore.KeyValueStore(database_file, redhawk.GetVersion())
    for i in store.GetKeys():
        print(U.GetDBPathRelativeToCurrentDirectory(i))
    store.Close()
    return
Exemple #8
0
def Main(args):
    parser = optparse.OptionParser(usage, description=description)
    options, args = parser.parse_args(args)

    if not len(args):
        parser.error("No files given.")

    database_file = S.GetDatabase()

    if database_file is None:
        S.ExitWithError(
            S.MakeStringFromTemplate(
                "No database found. Maybe $prog init first?"))

    store = KVStore.KeyValueStore(database_file, redhawk.GetVersion())
    for f in S.GetSupportedFiles(args):
        key = S.GetKey(f, database_file)
        if store.HasKey(key):
            print("Removing: %s" % (U.GetDBPathRelativeToCurrentDirectory(f)))
            store.RemoveKey(key)
        else:
            print("Not found: %s" % (U.GetDBPathRelativeToCurrentDirectory(f)))
    store.Close()
    return
def TestNiceInitKeyValueStore():
    temp_file = GetTempFile()

    KV.CreateNewStore(temp_file, redhawk.GetVersion())
    store = KV.KeyValueStore(temp_file, redhawk.GetVersion())
    return
 def TestRetainOnClose(self):
     self.store.Set('pig', 'grunt')
     self.store.Close()
     self.store = KV.KeyValueStore(self.temp_file, redhawk.GetVersion())
     assert (self.store.Get('pig') == 'grunt')