Ejemplo n.º 1
0
    def __init__(self, path, database_backend="leveldb"):
        if not (os.path.exists(path) or os.path.isdir(path)):
            err_msg = ('"{}" is not a valid directory').format(path)
            raise IOError(err_msg)

        if database_backend == "unqlite":
            assert UNQLITE_AVAILABLE, (
                "You selected unqlite as database backend, but it is not "
                "installed. Please install it via `pip install unqlite`")
            self.cui_db = unqlite.UnQLite(os.path.join(path, "cui.unqlite"))
            self.cui_db_put = self.cui_db.store
            self.cui_db_get = self.cui_db.fetch
            self.semtypes_db = unqlite.UnQLite(
                os.path.join(path, "semtypes.unqlite"))
            self.semtypes_db_put = self.semtypes_db.store
            self.semtypes_db_get = self.semtypes_db.fetch
        elif database_backend == "leveldb":
            self.cui_db = leveldb.LevelDB(os.path.join(path, "cui.leveldb"))
            self.cui_db_put = self.cui_db.Put
            self.cui_db_get = self.cui_db.Get
            self.semtypes_db = leveldb.LevelDB(
                os.path.join(path, "semtypes.leveldb"))
            self.semtypes_db_put = self.semtypes_db.Put
            self.semtypes_db_get = self.semtypes_db.Get
        else:
            raise ValueError(
                f"database_backend {database_backend} not recognized")
Ejemplo n.º 2
0
 def test(self):
     db = unqlite.UnQLite(DBname)
     cl = db.collection(COLLECTIONname)
     # doc = cl.fetch(0)
     # pprint(doc)
     cf = cl.filter(lambda x: x["word"].endswith("a"))
     pprint(cf)
Ejemplo n.º 3
0
 def toDB(self, dbname, collectionname):
     # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     #
     # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     db = unqlite.UnQLite(dbname)
     cl = db.collection(collectionname)
     if not cl.exists():
         cl.create()
     else:
         cl.drop()
         cl.create()
     # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     #
     # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     pickles = self._getPickles()
     for pk in pickles:
         print("processing------", pk)
         with open(pk, "rb") as target:
             tmp = pickle.load(target)
             # tmpdict = dict()
             # for k, v in tmp.items():
             #     tmpdict['word'] = k
             #     for kk, vv in v.items():
             #         tmpdict[kk] = vv
             # cl.store(tmpdict)
             # cl.store(tmp)
             # pprint(tmp)
             for k, v in tmp.items():
                 cl.store(v)
         print("done")
Ejemplo n.º 4
0
 def __init__(self, path):
     self.database = unqlite.UnQLite(path)
     self.repositories = dict()
     for asset_module in ASSET_MODULES:
         identifier = asset_module.REPOSITORY
         repository = self.database.collection(identifier)
         repository.create()
         self.repositories[identifier] = repository
Ejemplo n.º 5
0
 def __init__(self, name):
     self.db = unqlite.UnQLite(name)
     self.bins = self.db.collection('bins')
     if not self.bins.exists():
         self.bins.create()
     self.shoes = self.db.collection('shoes')
     if not self.shoes.exists():
         self.shoes.create()
Ejemplo n.º 6
0
def get_db(db_path: str = None, mem_db=False) -> unqlite.UnQLite:
    global db
    if db == None:
        db = unqlite.UnQLite(db_path if not mem_db else ':mem:')

        create_collection_if_not_exist('jobs')
        create_collection_if_not_exist('task_history')

    return db
Ejemplo n.º 7
0
    def __init__(self, subpath):
        """
		"""
        if op.isfile(subpath):
            self.subpath = subpath

        self.dbsubs = unqlite.UnQLite("subs.db")
        self.dbword = unqlite.UnQLite("word.db")

        subtitles = self.dbsubs.collection("subtitles")
        if subtitles.exists():
            pass
        else:
            subtitles.create()

        words = self.dbword.collection("words")
        if words.exists():
            pass
        else:
            words.create()
Ejemplo n.º 8
0
    def setup(self):
        self.unq_db = unqlite.UnQLite(
            os.path.join(self.db_dir, "blind_settings.db"))
        # check_same_thread=False is solely to quiet a spurious error that appears to be due
        # to a bug in twisted, where the connection is closed by a different thread than the
        # one that opened it. The individual connections in the pool are not used in multiple
        # threads.
        self.sql_db = adbapi.ConnectionPool('sqlite3',
                                            os.path.join(
                                                self.db_dir, "blind_peers.db"),
                                            check_same_thread=False)

        return self.sql_db.runQuery(
            "create table if not exists approved_peers (" +
            "    ip_address text, " + "    port integer" + ")")
Ejemplo n.º 9
0
        def wrapper(*args, **kwargs):
            # Connect to the database
            db = unqlite.UnQLite(filename, flags, open_database)
            # Add the connection handle as a keyword argument.
            kwargs[keyword] = db

            try:
                rv = callback(*args, **kwargs)
            except unqlite.UnQLiteError as e:
                db.rollback()
                raise bottle.HTTPError(500, "Database Error", e)
            except bottle.HTTPError:
                db.rollback()
                raise
            finally:
                db.close()
            return rv
Ejemplo n.º 10
0
    def __init__(self, filename):
        """
        Initialize the database and flask app
        """
        log.info('')

        self._single_thread_required = False

        # Initialize the input parameters
        self._filename = filename

        self._db = unqlite.UnQLite(self._filename)
        log.debug('Opened unqlite database file {} {}'.format(
            self._filename, self._db))

        # Setup the unqlite database collections
        log.debug('Setting up data collection')
        self._data = self._db.collection('data')
        if not self._data.exists():
            log.debug('  ... doesn' 't exist so creating.')
            self._data.create()

        self._cutout = self._db.collection('cutout')
        log.debug('Setting up cutout collection')
        if not self._cutout.exists():
            log.debug('  ... doesn' 't exist so creating.')
            self._cutout.create()

        self._fingerprint = self._db.collection('fingerprint')
        log.debug('Setting up fingerprint collection')
        if not self._fingerprint.exists():
            log.debug('  ... doesn' 't exist so creating.')
            self._fingerprint.create()

        self._similarity = self._db.collection('similarity')
        log.debug('Setting up similarity collection')
        if not self._similarity.exists():
            log.debug('  ... doesn' 't exist so creating.')
            self._similarity.create()
Ejemplo n.º 11
0
 def run(self):
     self.fetch()  # stores in data
     db = unqlite.UnQLite(self.output().path)
     etf = db.collection('etf')
     etf.create()
     etf.store(self.data)
Ejemplo n.º 12
0
import click
import unqlite
from . import config
database = unqlite.UnQLite(filename=config.dbLocation)

from . import authenticate


@click.group()
def cli():
    pass


cli.add_command(authenticate.auth)


if __name__ == "__main__":
    cli()
Ejemplo n.º 13
0
 def _open_db(self):
     filename = os.path.join(self.db_dir, self.NAME)
     log.debug("Opening %s as the settings database", filename)
     self.db = unqlite.UnQLite(filename)
     return defer.succeed(True)
Ejemplo n.º 14
0
 def connect(cls, uri):
     return unqlite.UnQLite(uri)
Ejemplo n.º 15
0
 def open_db():
     self.db = unqlite.UnQLite(os.path.join(self.db_dir,
                                            "ptcwallet.db"))
Ejemplo n.º 16
0
 def filter(self):
     etf_db = unqlite.UnQLite(self.input().path)
     etf_list = etf_db.collection('etf')
     filter_lambda = eval(META['ETF_DB']['FILTER_LAMBDA'].format(
         **META['ETF_DB']['FILTERS']))
     self.data = etf_list.filter(filter_lambda)
Ejemplo n.º 17
0
 def __init__(self, filepath):
     self.db = unqlite.UnQLite(str(filepath))