diff --git a/.gitignore b/.gitignore index d9e645d..ebb9386 100644 --- a/.gitignore +++ b/.gitignore @@ -171,4 +171,11 @@ data/failed/ data/trash/ data/gtfs/ data/tmp/ -data/agencyconf \ No newline at end of file +data/agencyconf + + +#these files are under app/static but they get copied to the outside directory on startup +logging.conf +config +static/* +templates/* \ No newline at end of file diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..5aae476 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1 @@ +recursive-include amarillo/static/ * \ No newline at end of file diff --git a/amarillo/app/main.py b/amarillo/app/main.py index 746ece7..dd38764 100644 --- a/amarillo/app/main.py +++ b/amarillo/app/main.py @@ -6,14 +6,19 @@ import uvicorn import mimetypes from starlette.staticfiles import StaticFiles +logging.config.fileConfig('logging.conf', disable_existing_loggers=False) +logger = logging.getLogger("main") + +from amarillo.app.utils.utils import copy_static_files +#this has to run before app.configuration is imported, otherwise we get validation error for config because the config file is not copied yet +copy_static_files(["conf", "static", "templates", "logging.conf", "config"]) + import amarillo.plugins from amarillo.app.configuration import configure_services, configure_admin_token from amarillo.app.routers import carpool, agency, agencyconf, region from fastapi import FastAPI from amarillo.app.views import home -logging.config.fileConfig('logging.conf', disable_existing_loggers=False) -logger = logging.getLogger("main") # https://pydantic-docs.helpmanual.io/usage/settings/ # from amarillo.app.views import home diff --git a/amarillo/app/utils/utils.py b/amarillo/app/utils/utils.py index 51a48e6..1e6bde3 100644 --- a/amarillo/app/utils/utils.py +++ b/amarillo/app/utils/utils.py @@ -1,8 +1,15 @@ import os import re +import os +import shutil +from pathlib import Path +import logging + from datetime import datetime, date, timedelta from pyproj import Geod +logger = logging.getLogger(__name__) + def assert_folder_exists(foldername): if not os.path.isdir(foldername): os.makedirs(foldername) @@ -37,4 +44,27 @@ def geodesic_distance_in_m(coord1, coord2): geod = Geod(ellps="WGS84") lons = [coord1[0], coord2[0]] lats = [coord1[1], coord2[1]] - return geod.line_lengths(lons, lats)[0] \ No newline at end of file + return geod.line_lengths(lons, lats)[0] + + +def copy_static_files(files_and_dirs_to_copy): + amarillo_dir = Path(__file__).parents[2] + source_dir = os.path.join(amarillo_dir, "static") + + destination_dir = os.getcwd() + + for item in files_and_dirs_to_copy: + source_path = os.path.join(source_dir, item) + destination_path = os.path.join(destination_dir, item) + + if os.path.exists(destination_path): + # logger.info(f"{item} already exists") + continue + + if os.path.isfile(source_path): + shutil.copy2(source_path, destination_path) + logger.info(f"Copied {item} to {destination_path}") + + if os.path.isdir(source_path): + shutil.copytree(source_path, destination_path) + logger.info(f"Copied directory {item} and its contents to {destination_path}") \ No newline at end of file diff --git a/config b/amarillo/static/config similarity index 100% rename from config rename to amarillo/static/config diff --git a/logging.conf b/amarillo/static/logging.conf similarity index 100% rename from logging.conf rename to amarillo/static/logging.conf diff --git a/static/css/docs.css b/amarillo/static/static/css/docs.css similarity index 100% rename from static/css/docs.css rename to amarillo/static/static/css/docs.css diff --git a/static/css/theme.css b/amarillo/static/static/css/theme.css similarity index 100% rename from static/css/theme.css rename to amarillo/static/static/css/theme.css diff --git a/static/img/cloud.png b/amarillo/static/static/img/cloud.png similarity index 100% rename from static/img/cloud.png rename to amarillo/static/static/img/cloud.png diff --git a/static/img/favicon.ico b/amarillo/static/static/img/favicon.ico similarity index 100% rename from static/img/favicon.ico rename to amarillo/static/static/img/favicon.ico diff --git a/templates/home/index.html b/amarillo/static/templates/home/index.html similarity index 100% rename from templates/home/index.html rename to amarillo/static/templates/home/index.html diff --git a/templates/shared/layout.html b/amarillo/static/templates/shared/layout.html similarity index 100% rename from templates/shared/layout.html rename to amarillo/static/templates/shared/layout.html diff --git a/pyproject.toml b/pyproject.toml index 87eb960..984a8eb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "amarillo-core" -version = "0.0.7" +version = "0.0.8" dependencies = [ "fastapi[all]==0.104.0", "geopandas==0.14",