def setup_class(cls): utils.installLoggers(logging.DEBUG, logging.DEBUG, filename='logs/tests.log') # Start a projectInterface thread running params = StructDict({'fmriPyScript': 'projects/sample/sample.py', 'filesremote': True, 'port': 8921, }) cfg = StructDict({'sessionId': "test", 'subjectName': "test_sample", 'subjectNum': 1, 'subjectDay': 1, 'sessionNum': 1}) cls.webThread = threading.Thread(name='webThread', target=Web.start, args=(params, cfg, True)) cls.webThread.setDaemon(True) cls.webThread.start() time.sleep(.1) # Start a fileWatcher thread running cls.fileThread = threading.Thread( name='fileThread', target=WsFileWatcher.runFileWatcher, args=('localhost:8921',), kwargs={ 'retryInterval': 0.1, 'allowedDirs': ['/tmp', testDir, samplePath], 'allowedTypes': fileTypeList, 'username': '******', 'password': '******', 'testMode': True } ) cls.fileThread.setDaemon(True) cls.fileThread.start() time.sleep(1)
"-s <server>", "-u <username>", "-p <password>", "--test", "-i <retry-connection-interval>" webSocketChannelName: The websocket url extension used to connect and communicate to the remote projectServer, 'wsData' will connect to 'ws://server:port/wsData' """ self.exampleInterface = ExampleInterface(dataRemote=False) self.wsRemoteService = WsRemoteService(args, webSocketChannelName) self.wsRemoteService.addHandlerClass(ExampleInterface, self.exampleInterface) def runDetached(self): """Starts the receiver in its own thread.""" self.recvThread = threading.Thread( name='recvThread', target=self.wsRemoteService.runForever) self.recvThread.setDaemon(True) self.recvThread.start() if __name__ == "__main__": installLoggers(logging.INFO, logging.INFO, filename='logs/ExampleService.log') # parse connection args # These include: "-s <server>", "-u <username>", "-p <password>", "--test", # "-i <retry-connection-interval>" connectionArgs = parseConnectionArgs() exampleService = ExampleService(connectionArgs) exampleService.wsRemoteService.runForever()
def readFileData(filename): data = None fileExtension = Path(filename).suffix if fileExtension == '.dcm': # Anonymize Dicom files dicomImg = readDicomFromFile(filename) dicomImg = anonymizeDicom(dicomImg) data = writeDicomToBuffer(dicomImg) else: with open(filename, 'rb') as fp: data = fp.read() return data if __name__ == "__main__": installLoggers(logging.INFO, logging.INFO, filename='logs/fileWatcher.log') # do arg parse for server to connect to parser = argparse.ArgumentParser() parser.add_argument('-s', action="store", dest="server", default="localhost:8888", help="Server Address with Port [server:port]") parser.add_argument('-i', action="store", dest="interval", type=int, default=5, help="Retry connection interval (seconds)") parser.add_argument( '-d',
currPath = os.path.dirname(os.path.realpath(__file__)) rootPath = os.path.dirname(os.path.dirname(currPath)) sys.path.append(rootPath) from rtCommon.utils import loadConfigFile, installLoggers from rtCommon.structDict import StructDict from rtCommon.projectInterface import Web # HERE: Set the path to the fMRI Python script to run here scriptToRun = 'projects/sample/sample.py' initScript = 'projects/sample/initialize.py' finalizeScript = 'projects/sample/finalize.py' defaultConfig = os.path.join(currPath, 'conf/sample.toml') if __name__ == "__main__": installLoggers(logging.INFO, logging.INFO, filename=os.path.join(currPath, 'logs/sample.log')) argParser = argparse.ArgumentParser() argParser.add_argument('--filesremote', '-x', default=False, action='store_true', help='dicom files retrieved from remote server') argParser.add_argument('--config', '-c', default=defaultConfig, type=str, help='experiment file (.json or .toml)') argParser.add_argument( '--test', '-t',
action='store_true', help='start webServer in test mode, unsecure') args = argParser.parse_args() if args.projectName is None: raise InvocationError('Must specify project name using -p parameter') if args.projectDir is None: args.projectDir = os.path.join(rootPath, 'projects', args.projectName) if args.config is None: args.config = os.path.join(args.projectDir, f'conf/{args.projectName}.toml') if args.mainScript is None: args.mainScript = os.path.join(args.projectDir, f'{args.projectName}.py') if args.initScript is None: args.initScript = os.path.join(args.projectDir, 'initialize.py') if args.finalizeScript is None: args.finalizeScript = os.path.join(args.projectDir, 'finalize.py') if args.remote is True: args.dataRemote = True args.subjectRemote = True installLoggers(logging.INFO, logging.INFO, filename=os.path.join(currPath, f'logs/{args.projectName}.log')) # start the projectServer projectServer = ProjectServer(args) projectServer.start()
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) def runDetached(self): """Starts the receiver in it's own thread.""" self.recvThread = threading.Thread( name='recvThread', target=self.wsRemoteService.runForever) self.recvThread.setDaemon(True) self.recvThread.start() if __name__ == "__main__": installLoggers(logging.INFO, logging.INFO, filename='logs/OpenNeuroService.log') # parse connection args connectionArgs = parseConnectionArgs() try: openNeuroService = OpenNeuroService(connectionArgs) # Use this command to run the service and not return control openNeuroService.wsRemoteService.runForever() # Alternately use this command to start the service in a thread and # return control to main. # openNeuroService.runDetached() except Exception as err: print(f'Exception: {err}')
""" self.dataInterface = DataInterface( dataRemote=False, allowedDirs=args.allowedDirs, allowedFileTypes=args.allowedFileTypes) self.bidsInterface = BidsInterface(dataRemote=False, allowedDirs=args.allowedDirs) self.wsRemoteService = WsRemoteService(args, webSocketChannelName) self.wsRemoteService.addHandlerClass(DataInterface, self.dataInterface) self.wsRemoteService.addHandlerClass(BidsInterface, self.bidsInterface) if __name__ == "__main__": installLoggers(logging.INFO, logging.INFO, filename='logs/CRDataServer.log') # parse connection args # These include: "-s <server>", "-u <username>", "-p <password>", "--test", # "-i <retry-connection-interval>" connectionArgs = parseConnectionArgs() # parse remaining args parser = argparse.ArgumentParser() parser.add_argument( '-d', action="store", dest="allowedDirs", default=defaultAllowedDirs, help="Allowed directories to server files from - comma separated list")
self.subjectInterface = SubjectInterface(subjectRemote=False) self.wsRemoteService = WsRemoteService(args, webSocketChannelName) self.wsRemoteService.addHandlerClass(SubjectInterface, self.subjectInterface) def runDetached(self): """Starts the receiver in it's own thread.""" self.recvThread = threading.Thread( name='recvThread', target=self.wsRemoteService.runForever) self.recvThread.setDaemon(True) self.recvThread.start() if __name__ == "__main__": installLoggers(logging.INFO, logging.INFO, filename='logs/SubjectService.log') # parse connection args # These include: "-s <server>", "-u <username>", "-p <password>", "--test", # "-i <retry-connection-interval>" connectionArgs = parseConnectionArgs() subjectService = SubjectService(connectionArgs) subjectService.runDetached() while True: feedbackMsg = subjectService.subjectInterface.msgQueue.get( block=True, timeout=None) print("Dequeue run: {}, tr: {}, value: {}, timestamp: {}".format( feedbackMsg.get('runId'), feedbackMsg.get('trId'),
import argparse import logging # import project modules # Add base project path (two directories up) currPath = os.path.dirname(os.path.realpath(__file__)) rootPath = os.path.dirname(os.path.dirname(currPath)) sys.path.append(rootPath) from rtCommon.utils import loadConfigFile, installLoggers from rtCommon.structDict import StructDict from rtCommon.projectInterface import Web defaultConfig = os.path.join(currPath, 'conf/faceMatching_organized.toml') if __name__ == "__main__": installLoggers(logging.INFO, logging.INFO, filename=os.path.join(currPath, 'logs/webServer.log')) argParser = argparse.ArgumentParser() argParser.add_argument('--filesremote', '-x', default=False, action='store_true', help='dicom files retrieved from remote server') argParser.add_argument('--config', '-c', default=defaultConfig, type=str, help='experiment file (.json or .toml)') args = argParser.parse_args() # HERE: Set the path to the fMRI Python script to run here