From 932056ab7a0a019b86d591006474124f0a974047 Mon Sep 17 00:00:00 2001 From: Shotgunosine Date: Thu, 15 Feb 2018 15:42:23 -0500 Subject: [PATCH] Add options for starting html server and meteor --- auto_mindcontrol.py | 14 ++++++++++++++ start_static_server.py | 11 +++++++++++ 2 files changed, 25 insertions(+) create mode 100644 start_static_server.py diff --git a/auto_mindcontrol.py b/auto_mindcontrol.py index d27c1dd..2efd315 100644 --- a/auto_mindcontrol.py +++ b/auto_mindcontrol.py @@ -3,8 +3,15 @@ from pathlib import Path import json from bids.grabbids import BIDSLayout +import subprocess +import os +import shutil parser = argparse.ArgumentParser(description='Autogenerate mindcontrol settings from a BIDS directory') +parser.add_argument('--server', action = 'store_true', + help='Start a simple file server in the bids directory.') +parser.add_argument('--meteor', action = 'store_true', + help='Start the meteor server that will serve mindcontrol.') parser.add_argument('bids_dir', help='The directory with the input dataset ' 'formatted according to the BIDS standard.') @@ -85,3 +92,10 @@ # Write out the settings file to the mindcontrol directory with open("settings.auto.json", "w") as h: json.dump(settings,h) + +if args.server: + shutil.copy2("start_static_server.py",bids_dir) + subprocess.Popen("python start_static_server.py", cwd = bids_dir, shell = True) +if args.meteor: + meteor = subprocess.Popen("meteor --settings settings.auto.json".split(' ')) + meteor.wait() \ No newline at end of file diff --git a/start_static_server.py b/start_static_server.py new file mode 100644 index 0000000..99a9812 --- /dev/null +++ b/start_static_server.py @@ -0,0 +1,11 @@ +#!/usr/bin/env python +import http.server +import os + +class MyHTTPRequestHandler(http.server.SimpleHTTPRequestHandler): + def end_headers(self): + self.send_header("Access-Control-Allow-Origin", "*") + http.server.SimpleHTTPRequestHandler.end_headers(self) + +if __name__ == '__main__': + http.server.test(HandlerClass=MyHTTPRequestHandler, port=3002) \ No newline at end of file