From 1ca9a545b3728c1b095cefc2f07c7ba049e7044c Mon Sep 17 00:00:00 2001 From: pajjilykk Date: Fri, 3 Apr 2026 21:15:15 +0700 Subject: [PATCH] add launch scripts --- .shii/lab4/run.py | 73 +++++++++++++++++++++++++++++++++++++++++++++++ .shii/lab4/run.sh | 0 2 files changed, 73 insertions(+) create mode 100755 .shii/lab4/run.py mode change 100644 => 100755 .shii/lab4/run.sh diff --git a/.shii/lab4/run.py b/.shii/lab4/run.py new file mode 100755 index 0000000..94348db --- /dev/null +++ b/.shii/lab4/run.py @@ -0,0 +1,73 @@ +#!/usr/bin/env python3 +""" +Lab4 Application Setup & Launch Script +Handles venv, dependencies, and database initialization +""" + +import os +import sys +import subprocess +import shutil +from pathlib import Path + +def main(): + # Get the directory where this script is located + script_dir = Path(__file__).resolve().parent + os.chdir(script_dir) + + print("🔧 Lab4 Application Setup & Launch") + print("=" * 50) + + venv_path = script_dir / "venv" + requirements_file = script_dir / "requirements.txt" + instance_dir = script_dir / "instance" + db_file = instance_dir / "accounting.db" + + # Check and create venv if not exists + if not venv_path.exists(): + print("📦 Virtual environment not found. Creating venv...") + subprocess.run([sys.executable, "-m", "venv", str(venv_path)], check=True) + print("✅ venv created") + else: + print("✅ venv already exists") + + # Determine the Python executable in venv + python_exe = venv_path / "bin" / "python" + pip_exe = venv_path / "bin" / "pip" + + if not python_exe.exists(): + print("❌ Failed to locate Python in venv") + sys.exit(1) + + # Install/upgrade requirements + if requirements_file.exists(): + print("📥 Installing dependencies from requirements.txt...") + subprocess.run([str(pip_exe), "install", "-q", "--upgrade", "pip"], check=True) + subprocess.run([str(pip_exe), "install", "-q", "-r", str(requirements_file)], check=True) + print("✅ Dependencies installed") + else: + print("❌ requirements.txt not found!") + sys.exit(1) + + # Create instance directory if not exists + if not instance_dir.exists(): + print("📁 Creating instance directory...") + instance_dir.mkdir(parents=True, exist_ok=True) + + # Remove old database to create fresh one + if db_file.exists(): + print("🗑️ Removing old database...") + db_file.unlink() + + print() + print("=" * 50) + print("🚀 Starting Flask Application...") + print("=" * 50) + print() + + # Run the Flask app + subprocess.run([str(python_exe), "app.py"]) + +if __name__ == "__main__": + main() + diff --git a/.shii/lab4/run.sh b/.shii/lab4/run.sh old mode 100644 new mode 100755