Merge static-files #2

Merged
Csaba merged 4 commits from static-files into main 2023-12-18 15:47:29 +01:00
13 changed files with 48 additions and 5 deletions

9
.gitignore vendored
View file

@ -171,4 +171,11 @@ data/failed/
data/trash/
data/gtfs/
data/tmp/
data/agencyconf
data/agencyconf
#these files are under app/static but they get copied to the outside directory on startup
logging.conf
config
static/*
templates/*

1
MANIFEST.in Normal file
View file

@ -0,0 +1 @@
recursive-include amarillo/static/ *

View file

@ -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

View file

@ -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]
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}")

View file

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 17 KiB

View file

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 15 KiB

View file

@ -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",