Ejemplo n.º 1
0
    def __init__(self, dataRemote=False, subjectRemote=False, webUI=None):
        """
        Args:
            dataRemote: whether file read/write requests will be handled directly by the projectServer
                or forwarded over websocket RPC to a remote service.
            subjectRemote: whether subject send/receive feedback will be handled locally within projectServer
                or forwarded over websocket RPC to a remote service.
        """
        self.dataRemote = dataRemote
        self.subjectRemote = subjectRemote
        allowedDirs = None
        allowedFileTypes = None
        if dataRemote is False:
            # Allow all file types and directories for local filesystem access
            allowedDirs = ['*']
            allowedFileTypes = ['*']

        # Instantiate the client service instances
        ProjectRPCService.exposed_DataInterface = DataInterface(
            dataRemote=dataRemote,
            allowedDirs=allowedDirs,
            allowedFileTypes=allowedFileTypes)
        ProjectRPCService.exposed_BidsInterface = BidsInterface(
            dataRemote=dataRemote)
        ProjectRPCService.exposed_SubjectInterface = SubjectInterface(
            subjectRemote=subjectRemote)
        ProjectRPCService.exposed_WebDisplayInterface = webUI
Ejemplo n.º 2
0
 def __init__(self, rpyc_timeout=60, yesToPrompts=False):
     """
     Establishes an RPC connection to a localhost projectServer on a predefined port.
     The projectServer must be running on the same computer as the script using this interface.
     """
     try:
         safe_attrs = rpyc.core.protocol.DEFAULT_CONFIG.get('safe_attrs')
         safe_attrs.add('__format__')
         rpcConn = rpyc.connect(
             'localhost',
             12345,
             config={
                 "allow_public_attrs": True,
                 "safe_attrs": safe_attrs,
                 "allow_pickle": True,
                 "sync_request_timeout": rpyc_timeout,
                 # "allow_getattr": True,
                 # "allow_setattr": True,
                 # "allow_delattr": True,
                 # "allow_all_attrs": True,
             })
         # Need to provide an override class of DataInstance to return data from getImage
         self.dataInterface = WrapRpycObject(rpcConn.root.DataInterface)
         self.subjInterface = WrapRpycObject(rpcConn.root.SubjectInterface)
         self.bidsInterface = WrapRpycObject(rpcConn.root.BidsInterface)
         self.exampleInterface = WrapRpycObject(
             rpcConn.root.ExampleInterface)
         # WebDisplay is always run within the projectServer (i.e. not a remote service)
         self.webInterface = rpcConn.root.WebDisplayInterface
         self.rpcConn = rpcConn
     except ConnectionRefusedError as err:
         if yesToPrompts:
             print(
                 'Unable to connect to projectServer, continuing using localfiles'
             )
             reply = 'y'
         else:
             reply = input(
                 'Unable to connect to projectServer, continue using localfiles? '
                 + '(y/n): ')
         reply.lower().strip()
         if reply[0] == 'y':
             # These will be run in the same process as the experiment script
             self.dataInterface = DataInterface(dataRemote=False,
                                                allowedDirs=['*'],
                                                allowedFileTypes=['*'])
             self.subjInterface = SubjectInterface(subjectRemote=False)
             self.bidsInterface = BidsInterface(dataRemote=False,
                                                allowedDirs=['*'])
             self.exampleInterface = ExampleInterface(dataRemote=False)
             # Without a webServer (projectServer) the webInterface won't be able to do
             #   anything. Create a stub instance here with ioLoopInst=None so that calls
             #   to it won't thow exceptions.
             self.webInterface = WebDisplayInterface(ioLoopInst=None)
         else:
             raise err
Ejemplo n.º 3
0
 def __init__(self, args, webSocketChannelName='wsData'):
     """
     Uses the WsRemoteService framework to parse connection-related args and establish
     a connection to a remote projectServer. Instantiates a local version of BidsInterface
     to handle client requests coming from the projectServer connection.
     Args:
         args: Argparse args related to connecting to the remote server. These include
             "-s <server>", "-u <username>", "-p <password>", "--test", 
             "-i <retry-connection-interval>"
         webSocketChannelName: The websocket url extension used to connecy and communicate
             to the remote projectServer, e.g. 'wsData' would connect to 'ws://server:port/wsData'
     """
     self.bidsInterface = BidsInterface(dataRemote=False)
     self.wsRemoteService = WsRemoteService(args, webSocketChannelName)
     self.wsRemoteService.addHandlerClass(BidsInterface, self.bidsInterface)
Ejemplo n.º 4
0
 def test_clientLocalBidsInterface(self):
     TestBidsInterface.serversForTests.stopServers()
     # Allowed dirs for local case set to the same as in the backgroundTestServers
     bidsInterface = BidsInterface(dataRemote=False, allowedDirs=allowedDirs)
     dicomStreamTest(bidsInterface)
     openNeuroStreamTest(bidsInterface)