-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
44 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,51 @@ | ||
import subprocess | ||
from pathlib import Path | ||
|
||
from jhub_apps.__about__ import __version__ | ||
|
||
import argparse | ||
|
||
PROJECT_ROOT_PATH = Path(__file__).parent.parent | ||
DEFAULT_JUPYTERHUB_CONFIG = PROJECT_ROOT_PATH / "jupyterhub_config.py" | ||
DEFAULT_JUPYTERHUB_SQLLITE_PATH = PROJECT_ROOT_PATH / "jupyterhub.sqlite" | ||
|
||
|
||
def run_japps(jupyterhub_config): | ||
db_url = f"--JupyterHub.db_url=sqlite:////{DEFAULT_JUPYTERHUB_SQLLITE_PATH}" | ||
command = ["jupyterhub", "-f", str(jupyterhub_config), db_url] | ||
print(f"Running command: {' '.join(command)}") | ||
with subprocess.Popen( | ||
command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True | ||
) as process: | ||
try: | ||
while True: | ||
output = process.stdout.readline() | ||
if output == "" and process.poll() is not None: | ||
break | ||
if output: | ||
print(output.strip()) | ||
except Exception as e: | ||
print(f"An error occurred: {e}") | ||
finally: | ||
# Get the remaining output if any | ||
for output in process.stdout.readlines(): | ||
print(output.strip()) | ||
|
||
# Get the return code from the process and print it | ||
return_code = process.poll() | ||
print(f"Process returned with code {return_code}") | ||
|
||
|
||
def app(): | ||
parser = argparse.ArgumentParser( | ||
prog='JHub Apps', | ||
description='JupyterHub App Launcher') | ||
parser.add_argument('--version', action='version', version=__version__) | ||
parser.parse_args() | ||
prog="JHub Apps", description="JupyterHub App Launcher" | ||
) | ||
parser.add_argument("--version", action="version", version=__version__) | ||
parser.add_argument( | ||
"-f", | ||
"--config-file", | ||
default=DEFAULT_JUPYTERHUB_CONFIG, | ||
help="Path to the JupyterHub config file", | ||
) | ||
args = parser.parse_args() | ||
run_japps(jupyterhub_config=args.config_file) |