diff --git a/run_macos.sh b/run_macos.sh index 1789d6a..2075b75 100644 --- a/run_macos.sh +++ b/run_macos.sh @@ -1,6 +1,17 @@ #!/bin/bash -# Step 1: Create a virtual environment +CONFIG_DIR="" +USER="" + +while [[ "$#" -gt 0 ]]; do + case $1 in + --ConfigDirectory) CONFIG_DIR="$2"; shift ;; + --User) USER="$2"; shift ;; + *) echo "Unknown parameter passed: $1"; exit 1 ;; + esac + shift +done + echo "Creating virtual environment..." python3 -m venv venv if [ $? -ne 0 ]; then @@ -9,7 +20,6 @@ if [ $? -ne 0 ]; then fi echo "Virtual environment created successfully." -# Step 2: Activate the virtual environment echo "Activating virtual environment..." source venv/bin/activate if [ $? -ne 0 ]; then @@ -18,7 +28,6 @@ if [ $? -ne 0 ]; then fi echo "Virtual environment activated." -# Step 3: Install the required packages echo "Installing dependencies from requirements.txt..." pip install -r requirements.txt if [ $? -ne 0 ]; then @@ -27,12 +36,8 @@ if [ $? -ne 0 ]; then fi echo "Dependencies installed successfully." -# Step 4: Run the application with optional parameters -CONFIG_DIR=${1:-none} -USER=${2:-none} - echo "Starting the application with ConfigDirectory=$CONFIG_DIR and User=$USER..." -python server.py "$CONFIG_DIR" "$USER" +python3 server.py "$CONFIG_DIR" "$USER" if [ $? -ne 0 ]; then echo "Failed to start the application." exit 1 diff --git a/run_windows.bat b/run_windows.bat index 4dcd9da..8f739e7 100644 --- a/run_windows.bat +++ b/run_windows.bat @@ -1,5 +1,22 @@ @echo off -:: Step 1: Create a virtual environment +set "CONFIG_DIR=" +set "USER= " + +:parse_args +if "%~1"=="" goto :done +if /i "%~1"=="--ConfigDirectory" ( + set "CONFIG_DIR=%~2" + shift +) +if /i "%~1"=="--User" ( + set "USER=%~2" + shift +) +shift +goto :parse_args + +:done + echo Creating virtual environment... python -m venv venv if %ERRORLEVEL% NEQ 0 ( @@ -8,7 +25,6 @@ if %ERRORLEVEL% NEQ 0 ( ) echo Virtual environment created successfully. -:: Step 2: Activate the virtual environment echo Activating virtual environment... call venv\Scripts\activate if %ERRORLEVEL% NEQ 0 ( @@ -17,7 +33,6 @@ if %ERRORLEVEL% NEQ 0 ( ) echo Virtual environment activated. -:: Step 3: Install the required packages echo Installing dependencies from requirements.txt... pip install -r requirements.txt if %ERRORLEVEL% NEQ 0 ( @@ -26,10 +41,6 @@ if %ERRORLEVEL% NEQ 0 ( ) echo Dependencies installed successfully. -:: Step 4: Run the application with optional parameters -set "CONFIG_DIR=%1" -set "USER=%2" - echo Starting the application with ConfigDirectory=%CONFIG_DIR% and User=%USER%... python server.py "%CONFIG_DIR%" "%USER%" if %ERRORLEVEL% NEQ 0 ( diff --git a/server.py b/server.py index 52796b0..15e953f 100644 --- a/server.py +++ b/server.py @@ -5,14 +5,24 @@ def parse_arguments(): - if len(sys.argv) > 1: - if (len(sys.argv[1]) > 0): - print("sys.argv 1 is " + str(sys.argv[1])) - instance_utils.CONFIG_DIRECTORY = sys.argv[1] - if len(sys.argv) > 2: - if (len(sys.argv[2]) > 0): - print("sys.argv 2 is " + str(sys.argv[2])) - instance_utils.USER = sys.argv[2] + args = sys.argv[1:] # Skip the script name + for i in range(len(args)): + if args[i].startswith("--ConfigDirectory="): + value = args[i].split("=", 1)[1].strip() + if len(value) > 0: + instance_utils.CONFIG_DIRECTORY = value + elif args[i].startswith("--User="): + value = args[i].split("=", 1)[1].strip() + if len(value) > 0: + instance_utils.USER = value + elif i == 0 and not args[i].startswith("--"): + value = args[i].strip() + if len(value) > 0: + instance_utils.CONFIG_DIRECTORY = value + elif i == 1 and not args[i].startswith("--"): + value = args[i].strip() + if len(value) > 0: + instance_utils.USER = value if __name__ == '__main__':