def setup(self):
     cache_dir = user_cache_dir(self.appname)
     if not os.path.exists(cache_dir):
         os.makedirs(cache_dir)
     self.file = os.path.join(cache_dir, self.filename)
     logger.info('Using cache for {}: {}'.format(self.appname, self.file))
     self.cache = json_store.open(self.file)
Exemple #2
0
 def __init__(self):
     if not ConfigStoreJson.store:
         #print "ConfigStoreJson.__init__"
         self.app_data_dir = user_data_dir('kotori', 'daqzilla')
         logger.debug("ConfigStoreJson app_data_dir: {}".format(self.app_data_dir))
         if not os.path.exists(self.app_data_dir):
             os.makedirs(self.app_data_dir)
         self.config_file = os.path.join(self.app_data_dir, 'config.json')
         ConfigStoreJson.store = json_store.open(self.config_file)
Exemple #3
0
 def __init__(self):
     if not ConfigStoreJson.store:
         #print "ConfigStoreJson.__init__"
         self.app_data_dir = user_data_dir('kotori-daq', 'Elmyra')
         logger.debug("ConfigStoreJson app_data_dir: {}".format(self.app_data_dir))
         if not os.path.exists(self.app_data_dir):
             os.makedirs(self.app_data_dir)
         self.config_file = os.path.join(self.app_data_dir, 'config.json')
         ConfigStoreJson.store = json_store.open(self.config_file)
def convert(oldfile):
    if not os.path.isfile(oldfile):
        raise ValueError("No such file: {}".format(oldfile))

    data = shelve.open(oldfile)

    newfile = oldfile.rsplit(".db")[0] + ".json"
    store = json_store.open(newfile)
    store.update(data)
    store.sync()
def test_empty_store():
    store = get_new_store()
    try:
        assert_equal(store, {})

        store2 = json_store.open(store.path)
        assert store2 is not store
        assert_equal(store2, store)
    finally:
        os.remove(store.path)
def get_new_store(json_kw=None):
    # get a random filename to use
    with NamedTemporaryFile(prefix=__name__ + ".") as f:
        path = f.name
    assert not os.path.exists(path), (
        "Tempfile was not deleted: %s" % path)

    store = json_store.open(path, json_kw)
    assert os.path.exists(path), "New store file was not created"
    return store
def test_empty_store():
    store = get_new_store()
    try:
        assert store == {}

        store2 = json_store.open(store.path)
        assert store2 is not store
        assert store2 == store
    finally:
        os.remove(store.path)
Exemple #8
0
def main(oldfile):
    if not os.path.isfile(oldfile):
        print "No such file:", oldfile
        raise SystemExit(1)

    data = shelve.open(oldfile)

    newfile = oldfile.rsplit(".db")[0] + ".json"
    store = json_store.open(newfile)
    store.update(data)
    store.sync()
def get_new_store(json_kw=None, mode=None):
    # get a random filename to use
    with NamedTemporaryFile(prefix=__name__ + ".") as f:
        path = f.name
    assert not os.path.exists(path), (
        "Tempfile was not deleted: %s" % path)

    kwargs = {}

    if mode is not None:
        kwargs['mode'] = mode

    store = json_store.open(path, json_kw, **kwargs)
    assert os.path.exists(path), "New store file was not created"
    return store
def test_store_stocking():
    store = get_new_store()
    try:
        assert_equal(store, {})
        store_copyfile = store.path + ".copy"

        store[u'\N{UMBRELLA}'] = 'umbrella'
        store.sync()
        assert_equal(len(store), 1)

        store['nested'] = [{'dict': {'a': None}}, u'\N{CLOUD}']
        store.sync()
        assert_equal(len(store), 2)

        shutil.copyfile(store.path, store_copyfile)
        store2 = json_store.open(store_copyfile)
        assert_equal(store2, store)
    finally:
        os.remove(store.path)
        if os.path.exists(store_copyfile):
            os.remove(store_copyfile)
def test_store_stocking():
    store = get_new_store()
    try:
        assert store == {}
        store_copyfile = store.path + ".copy"

        store['\N{UMBRELLA}'] = 'umbrella'
        store.sync()
        assert len(store) == 1

        store['nested'] = [{'dict': {'a': None}}, '\N{CLOUD}']
        store.sync()
        assert len(store) == 2

        shutil.copyfile(store.path, store_copyfile)
        store2 = json_store.open(store_copyfile)
        assert store2 == store
    finally:
        os.remove(store.path)
        if os.path.exists(store_copyfile):
            os.remove(store_copyfile)
Exemple #12
0
 def setup(self):
     if not ConfigStoreJson.store:
         #print "ConfigStoreJson.__init__"
         ConfigStoreJson.store = json_store.open(self.config_file)