def __init__(self, **args): src_args = ('SRC_USER', 'SRC_HOST', 'SRC_PASS') self.src_u, self.src_h, self.src_p = (args.get(v, None) for v in src_args) dst_args = ('DST_USER', 'DST_HOST', 'DST_PASS', 'DST_PREFIX') self.dst_u, self.dst_h, self.dst_p, self.dst_x = (args.get(v, None) for v in dst_args) try: assert (all((self.src_u, self.src_h, self.src_p))) assert (all((self.dst_u, self.dst_h, self.dst_p, self.dst_x))) except AssertionError: msg = 'configuration error: check {}'.format( (*src_args, *dst_args)) raise RuntimeError(msg) from None self.src_c = dj.Connection(self.src_h, self.src_u, self.src_p) self.dst_c = dj.Connection( self.dst_h, self.dst_u, self.dst_p) # TODO hostinput='' if upgrading to datajoint 0.13.0 src_vmod_cfg = { 'mice': 'common_mice', 'experiment': 'pipeline_experiment', 'odor': 'pipeline_odor', 'meso': 'pipeline_meso', 'stack': 'pipeline_stack', 'treadmill': 'pipeline_treadmill', } dst_vmod_cfg = { 'mice': '{}mice', 'experiment': '{}experiment', 'odor': '{}odor', 'meso': '{}meso', 'stack': '{}stack', 'treadmill': '{}treadmill', } dst_vmod_cfg = { k: v.format(self.dst_x) for k, v in dst_vmod_cfg.items() } def make_vmods(tag, cfg, connection): return { k: dj.create_virtual_module('{}_{}'.format(tag, k), v, connection=connection) for k, v in cfg.items() } self.src_vmods = make_vmods('src', src_vmod_cfg, self.src_c) self.dst_vmods = make_vmods('dst', dst_vmod_cfg, self.dst_c)
def __init__(self, protocol=False): self.setup = socket.gethostname() self.is_pi = os.uname( )[4][:3] == 'arm' if os.name == 'posix' else False self.setup_status = 'running' if protocol else 'ready' fileobject = open( os.path.dirname(os.path.abspath(__file__)) + '/../dj_local_conf.json') con_info = json.loads(fileobject.read()) self.private_conn = dj.Connection(con_info['database.host'], con_info['database.user'], con_info['database.password']) for schema, value in schemata.items( ): # separate connection for internal comminication self._schemata.update({ schema: dj.create_virtual_module(schema, value, connection=self.private_conn) }) self.thread_end, self.thread_lock = threading.Event(), threading.Lock() self.inserter_thread = threading.Thread(target=self.inserter) self.getter_thread = threading.Thread(target=self.getter) self.inserter_thread.start() self.log_setup(protocol) self.getter_thread.start() self.logger_timer.start()
def __init__(self, protocol=False): self.setup, self.is_pi = socket.gethostname(), os.uname( )[4][:3] == 'arm' self.curr_state, self.lock, self.queue, self.curr_trial, self.total_reward = '', False, PriorityQueue( ), 0, 0 self.session_key = dict() self.ping_timer, self.logger_timer = Timer(), Timer() self.setup_status = 'running' if protocol else 'ready' self.log_setup(protocol) fileobject = open( os.path.dirname(os.path.abspath(__file__)) + '/dj_local_conf.json') connect_info = json.loads(fileobject.read()) background_conn = dj.Connection(connect_info['database.host'], connect_info['database.user'], connect_info['database.password']) self.schemata = dict() self.schemata['lab'] = dj.create_virtual_module( 'beh.py', 'lab_behavior', connection=background_conn) self.schemata['mice'] = dj.create_virtual_module( 'mice.py', 'lab_mice', connection=background_conn) self.thread_end, self.thread_lock = threading.Event(), threading.Lock() self.inserter_thread = threading.Thread(target=self.inserter) self.getter_thread = threading.Thread(target=self.getter) self.inserter_thread.start() self.getter_thread.start() self.logger_timer.start() # start session time
def clone_conn(conn): """ Clones a given connection object. Args: conn (dj.Connection): connection object to clone Returns: new dj.Connection object with properties identical to conn """ conn_info = conn.conn_info return dj.Connection( host=conn_info["host"], user=conn_info["user"], password=conn_info["passwd"], init_fun=conn.init_fun, use_tls=conn_info["ssl"], )
def test_dj_connection_class(): """ Should be able to establish a connection """ c = dj.Connection(**CONN_INFO) assert_true(c.is_connected)
def __init__(self): """A connection with only SELECT privilege to djtest schemas""" self.connection = dj.Connection(host=environ.get( 'DJ_TEST_HOST', 'localhost'), user='******', password='******')
def setup_class(cls): """A connection with only SELECT privilege to djtest schemas""" cls.connection = dj.Connection(host=environ.get( 'DJ_TEST_HOST', 'localhost'), user='******', password='******')
import datajoint as dj import socket # connect to local database server for communication wioth 2pmaster s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.connect(("8.8.8.8", 80)) ip = s.getsockname()[0] conn2 = dj.Connection(ip, 'atlab', dj.config['database.password']) if conn2.is_connected: print('Connection to 2pMaster Made...') schema2 = dj.schema('pipeline_behavior', connection=conn2) @schema2 class SetupControl(dj.Lookup): definition = """ # twop_setup : varchar(256) # two photon setup name, e.g. 2P1 setup : varchar(256) # Setup name of behavior/stim computer, e.g. at-stim01 --- ip : varchar(16) # setup IP address, e.g. at-stim01.ad.bcm.edu state="ready" : enum('systemReady','sessionRunning','stimRunning','stimPaused') # state_control="ready" : enum('startSession','startStim','stopStim','stopSession','pauseStim','resumeStim','Initialize','') # animal_id=null : int # animal id session=null : int # session number scan_idx=null : int # stimulus="" : varchar # next_trial=null : int # last_ping=null : timestamp task_idx=7 : int # task identification number task="train" : enum('train','calibrate') trial_done=1 : int # 0=trial running 1=trial finished
def setup_class(cls): """A connection with only SELECT privilege to djtest schemas""" cls.connection = dj.Connection(host=CONN_INFO['host'], user='******', password='******')