Esempio n. 1
0
 def loadDatabase(repo, path, readOnly):
     '''Load the database from a repo directory.'''
     dbPath = os.path.join(repo.abspath, Database.dbName)
     storage = CachingMiddleware(JSONStorage)
     storage.WRITE_CACHE_SIZE = 100 * 1000
     tinydbDB = TinyDB(dbPath, storage=storage)
     return Database(repo, readOnly, tinydbDB)
Esempio n. 2
0
    def db(self):
        if self._db is None:
            storage = CachingMiddleware(JSONStorage)
            storage.WRITE_CACHE_SIZE = 50  # todo support for user specifying
            self._db = TinyDB(self.source, storage=storage)
            name = self.__class__.__name__
            if "readonly" in name.lower():
                # remove interface for inserting records making this a read only db
                self._db.insert = None
            else:
                self.lock()

            self._finish = weakref.finalize(self, self._close, self._db)

        return self._db
Esempio n. 3
0
 def connect_database(self, *args, **kwargs):
     """Open the database for reading and writing."""
     if self._database is None:
         util.mkdirp(self.prefix)
         dbfile = os.path.join(self.prefix, self.name + '.json')
         try:
             storage = CachingMiddleware(_JsonFileStorage)
             storage.WRITE_CACHE_SIZE = 0
             self._database = tinydb.TinyDB(dbfile, storage=storage)
         except IOError as err:
             raise StorageError("Failed to access %s database '%s': %s" % (self.name, dbfile, err),
                                "Check that you have `write` access")
         if not util.path_accessible(dbfile):
             raise StorageError("Database file '%s' exists but cannot be read." % dbfile,
                                "Check that you have `read` access")
         LOGGER.debug("Initialized %s database '%s'", self.name, dbfile)
Esempio n. 4
0
def getdatabase():

    for ntry in range(3):
        try:
            storage = CachingMiddleware(JSONStorage)
            storage.WRITE_CACHE_SIZE = 600
            db = TinyDB(jobsfile, storage=storage), storage
            if ntry > 0:
                print(blue("The database was successfully fixed."))
            return db
        except ValueError:
            if ntry == 0:
                print(blue("The database is corrupted. Attempting to fix it."))
            debug_json(jobsfile)
    else:
        msg = "The database coulnd't be fixed. Please open an issue in https://github.com/marinang/SimProd/issues"
        msg += " with the 'simjobs.json' file attached."
        raise CorruptedDB(red(msg))
Esempio n. 5
0
def setup_caching_write_many():
    global storage
    storage = CachingMiddleware(MemoryStorage)
    storage.WRITE_CACHE_SIZE = 3
    storage()  # Initialize MemoryStorage
Esempio n. 6
0
def getdatabase(file):
    storage = CachingMiddleware(JSONStorage)
    storage.WRITE_CACHE_SIZE = 20
    return TinyDB(file, storage=storage)
Esempio n. 7
0
# create database with wikipedia tables
from pathlib import Path

path = '../data/db.json'
db_file = Path(path)
if not db_file.is_file():
    create_database(path)


def print_result(b):
    return 'Done.' if b else 'Not Available.'


middleware = CachingMiddleware(JSONStorage)
middleware.WRITE_CACHE_SIZE = 15
with TinyDB('../data/db.json', storage=middleware) as db:
    table = db.table('Picture')
    state = db.table('_default')
    if len(state.all()) < 1:
        state.insert({'currentMovie': None, 'index': -1})

    print("######################\n\
#  Populating Movies #\n\
######################")
    Movie = Query()
    index = 0
    currentIndex = state.all()[0]['index']
    for item in table:
        if not currentIndex >= index:  # TODO: Check if this indexing can be done better
            print('Current Movie:', item['Film'])
def setup_caching_write_many():
    global storage
    storage = CachingMiddleware(MemoryStorage)
    storage.WRITE_CACHE_SIZE = 3
    storage()  # Initialize MemoryStorage