extending setup
This commit is contained in:
79
setup.py
79
setup.py
@@ -15,39 +15,46 @@ from web.utils import get_mysql_config
|
|||||||
|
|
||||||
cmd = sys.argv[1] if len(sys.argv) > 1 else "help"
|
cmd = sys.argv[1] if len(sys.argv) > 1 else "help"
|
||||||
|
|
||||||
if cmd == "mysql-init":
|
try:
|
||||||
cfg = get_mysql_config()
|
if cmd == "mysql-init":
|
||||||
root_url = f"mysql+pymysql://{cfg['user']}:{cfg['password']}@{cfg['host']}:{cfg['port']}/"
|
cfg = get_mysql_config()
|
||||||
dbname = cfg["database"]
|
root_url = f"mysql+pymysql://{cfg['user']}:{cfg['password']}@{cfg['host']}:{cfg['port']}/"
|
||||||
root_engine = create_engine(root_url, future=True)
|
dbname = cfg["database"]
|
||||||
with root_engine.begin() as conn:
|
root_engine = create_engine(root_url, future=True)
|
||||||
conn.execute(text(
|
with root_engine.begin() as conn:
|
||||||
f"CREATE DATABASE IF NOT EXISTS `{dbname}` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci"))
|
conn.execute(text(
|
||||||
mysql_url = f"mysql+pymysql://{cfg['user']}:{cfg['password']}@{cfg['host']}:{cfg['port']}/{dbname}?charset=utf8mb4"
|
f"CREATE DATABASE IF NOT EXISTS `{dbname}` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci"))
|
||||||
mysql_engine = create_engine(mysql_url, future=True)
|
mysql_url = f"mysql+pymysql://{cfg['user']}:{cfg['password']}@{cfg['host']}:{cfg['port']}/{dbname}?charset=utf8mb4"
|
||||||
from web.db import Base
|
mysql_engine = create_engine(mysql_url, future=True)
|
||||||
Base.metadata.create_all(mysql_engine)
|
from web.db import Base
|
||||||
print("MySQL database and tables ensured")
|
Base.metadata.create_all(mysql_engine)
|
||||||
elif cmd == "counts":
|
print("MySQL database and tables ensured")
|
||||||
cfg = get_mysql_config()
|
sys.exit(0)
|
||||||
url = f"mysql+pymysql://{cfg['user']}:{cfg['password']}@{cfg['host']}:{cfg['port']}/{cfg['database']}?charset=utf8mb4"
|
elif cmd == "counts":
|
||||||
engine = create_engine(url, future=True)
|
cfg = get_mysql_config()
|
||||||
with engine.begin() as conn:
|
url = f"mysql+pymysql://{cfg['user']}:{cfg['password']}@{cfg['host']}:{cfg['port']}/{cfg['database']}?charset=utf8mb4"
|
||||||
for table in [
|
engine = create_engine(url, future=True)
|
||||||
"users",
|
with engine.begin() as conn:
|
||||||
"regions",
|
for table in [
|
||||||
"keywords",
|
"users",
|
||||||
"user_regions",
|
"regions",
|
||||||
"user_keywords",
|
"keywords",
|
||||||
"job_listings",
|
"user_regions",
|
||||||
"job_descriptions",
|
"user_keywords",
|
||||||
"cached_pages",
|
"job_listings",
|
||||||
"user_interactions",
|
"job_descriptions",
|
||||||
]:
|
"cached_pages",
|
||||||
try:
|
"user_interactions",
|
||||||
n = conn.execute(text(f"SELECT COUNT(*) FROM {table}"))
|
]:
|
||||||
print(f"{table}: {list(n)[0][0]}")
|
try:
|
||||||
except Exception as e:
|
n = conn.execute(text(f"SELECT COUNT(*) FROM {table}"))
|
||||||
print(f"{table}: error {e}")
|
print(f"{table}: {list(n)[0][0]}")
|
||||||
else:
|
except Exception as e:
|
||||||
print(__doc__)
|
print(f"{table}: error {e}")
|
||||||
|
sys.exit(0)
|
||||||
|
else:
|
||||||
|
print(__doc__)
|
||||||
|
sys.exit(0)
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error: {e}")
|
||||||
|
sys.exit(1)
|
||||||
|
|||||||
30
setup.sh
Normal file
30
setup.sh
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# Robust Debian-compatible setup script for the jobs web app
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
PY=python3
|
||||||
|
if ! command -v ${PY} >/dev/null 2>&1; then
|
||||||
|
echo "python3 not found; try installing python3 and rerun this script"
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Creating virtualenv .venv"
|
||||||
|
${PY} -m venv .venv
|
||||||
|
|
||||||
|
echo "Activating virtualenv"
|
||||||
|
# shellcheck disable=SC1091
|
||||||
|
source .venv/bin/activate
|
||||||
|
|
||||||
|
echo "Upgrading pip and installing requirements"
|
||||||
|
pip install --upgrade pip setuptools wheel || true
|
||||||
|
if ! pip install -r requirements.txt; then
|
||||||
|
echo "pip install failed; inspect output above. Continuing to allow manual fixes."
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Ensuring DB schema (if configured). Running: python setup.py mysql-init"
|
||||||
|
if ! python setup.py mysql-init; then
|
||||||
|
echo "setup.py mysql-init failed — check MySQL settings in config/settings.json"
|
||||||
|
# don't fail the whole script; the DB step is optional for local dev without MySQL
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Setup complete. To activate the venv in this shell: source .venv/bin/activate"
|
||||||
Reference in New Issue
Block a user