From 15e1c5223be1a06132513f03c45168b263316c40 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Fri, 10 Dec 2021 15:50:58 -0600 Subject: [PATCH] bootstrap during start --- binder/postBuild | 8 -------- binder/start | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/binder/postBuild b/binder/postBuild index 4f9cbc217..3492c3118 100755 --- a/binder/postBuild +++ b/binder/postBuild @@ -12,11 +12,3 @@ cd binder yes | m $(cat VERSION) m - -./init - -python ./bootstrap.py - -mlaunch kill - -rm -rf ./data \ No newline at end of file diff --git a/binder/start b/binder/start index de053f4d8..a683703b1 100755 --- a/binder/start +++ b/binder/start @@ -4,9 +4,11 @@ import shutil import os import shlex import subprocess +from pymongo import MongoClient HERE = os.path.abspath(os.path.dirname(__file__)) +# Get config variables with open(os.path.join(HERE, 'VERSION')) as fid: VERSION = fid.read().strip() @@ -23,6 +25,21 @@ MONGODB_BIN, '--port', PORT, '--hostname', 'localhost', '--setParameter', print(cmd) subprocess.check_call(cmd, cwd=HERE) +# Bootstrap some data +client = MongoClient(directConnection=True)) + +for path in glob.glob(os.path.join(HERE, 'sample_data', '*.json')): + with open(path) as fid: + entries = [json.loads(line) for line in fid] + for entry in entries: + del entry['_id'] + + name, _ = os.path.splitext(os.path.basename(path)) + print(name, len(entries)) + + collection = client.sample_mflix[name] + collection.insert_many(entries) + # Launch Jupyter argv = sys.argv[1:] print(argv)