コード例 #1
0
    def __init__(self,
                 config_path="config.json",
                 ws_server="localhost",
                 ws_port=4444):

        # Internal service variables
        self._action_buffer = []
        self._action_counter = 2
        self._portobjects = []

        #load tinydb configuration database
        logging.debug("Trying to load config file  from %s" % config_path)
        tiny_database = TinyDB(config_path, indent=4)
        tiny_db = tiny_database.table("keys", cache_size=20)
        tiny_devdb = tiny_database.table("devices", cache_size=20)

        #get all mappings and devices
        self._mappings = tiny_db.all()
        self._devices = tiny_devdb.all()

        #open dbj datebase for mapping and clear
        self.mappingdb = dbj("temp-mappingdb.json")
        self.mappingdb.clear()

        #convert database to dbj in-memory
        for _mapping in self._mappings:
            self.mappingdb.insert(_mapping)

        logging.debug("Mapping database: `%s`" % str(self.mappingdb.getall()))

        if len(self.mappingdb.getall()) < 1:
            logging.critical("Could not cache device mappings")
            # ENOENT (No such file or directory)
            exit(2)

        logging.debug("Successfully imported mapping database")

        result = tiny_devdb.all()
        if not result:
            logging.critical("Config file %s doesn't exist or is damaged" %
                             config_path)
            # ENOENT (No such file or directory)
            exit(2)

        logging.info("Successfully parsed config file")

        logging.debug("Retrieved MIDI port name(s) `%s`" % result)

        # close tinydb
        tiny_database.close()

        # setting up a Websocket client
        logging.debug("Attempting to connect to OBS using websocket protocol")
        self.obs_socket = WebSocketApp("ws://%s:%d" % (ws_server, ws_port))
コード例 #2
0
ファイル: test_dbj.py プロジェクト: pdrb/dbj
 def setUp(self):
     self.db = dbj('tests_dbj.db')
コード例 #3
0
ファイル: test_dbj.py プロジェクト: pdrb/dbj
 def test__autosave(self):
     self.db = dbj('tests_dbj.db', autosave=True)
     self.db.insert({'test': 'testing'})
     self.db.insert({'test2': 'testing2'})
     self.db = dbj('tests_dbj.db')
     self.assertEqual(self.db.size(), 2)
コード例 #4
0
ファイル: main.py プロジェクト: AindriuBrennan/MIDItoOBS
    def __init__(self,
                 config_path=args.config,
                 ws_server=args.host,
                 ws_port=args.port):
        # Setting up logging first and foremost
        self.log = get_logger("midi_to_obs")

        # Internal service variables
        self._action_buffer = []
        self._action_counter = 2
        self._portobjects = []

        # Feedback blocking
        self.blockcount = 0
        self.block = False
        #load tinydb configuration database
        self.log.debug("Trying to load config file  from %s" % config_path)
        tiny_database = TinyDB(config_path, indent=4)
        tiny_db = tiny_database.table("keys", cache_size=20)
        tiny_devdb = tiny_database.table("devices", cache_size=20)

        #get all mappings and devices
        self._mappings = tiny_db.all()
        self._devices = tiny_devdb.all()

        #open dbj datebase for mapping and clear
        self.mappingdb = dbj("temp-mappingdb.json")
        self.mappingdb.clear()

        #convert database to dbj in-memory
        for _mapping in self._mappings:
            self.mappingdb.insert(_mapping)

        self.log.debug("Mapping database: `%s`" % str(self.mappingdb.getall()))

        if len(self.mappingdb.getall()) < 1:
            self.log.critical("Could not cache device mappings")
            # ENOENT (No such file or directory)
            exit(2)

        self.log.debug("Successfully imported mapping database")

        result = tiny_devdb.all()
        if not result:
            self.log.critical("Config file %s doesn't exist or is damaged" %
                              config_path)
            # ENOENT (No such file or directory)
            exit(2)

        self.log.info("Successfully parsed config file")

        self.log.debug("Retrieved MIDI port name(s) `%s`" % result)
        #create new class with handler and open from there, just create new instances
        for device in result:
            self._portobjects.append(
                (DeviceHandler(device, device.doc_id), device.doc_id))

        self.log.info("Successfully initialized midi port(s)")
        del result

        # close tinydb
        tiny_database.close()

        # setting up a Websocket client
        self.log.debug("Attempting to connect to OBS using websocket protocol")
        self.obs_socket = WebSocketApp("ws://%s:%d" % (ws_server, ws_port))
        self.obs_socket.on_message = lambda ws, message: self.handle_obs_message(
            ws, message)
        self.obs_socket.on_error = lambda ws, error: self.handle_obs_error(
            ws, error)
        self.obs_socket.on_close = lambda ws: self.handle_obs_close(ws)
        self.obs_socket.on_open = lambda ws: self.handle_obs_open(ws)
コード例 #5
0
import os
import timeit
import resource

from dbj import dbj

db = dbj('bench_database.json')
n = 100000


def insert_auto():
    for i in range(n):
        db.insert({'index': i})


def insert_sup():
    for i in range(n):
        db.insert({'index': i}, str(i))


def retrieve_all():
    for key in db.getallkeys():
        db.get(key)


def delete_all():
    for key in db.getallkeys():
        db.delete(key)


print('\n' + '-' * 32)