Copy static files to working directory
Some checks failed
Amarillo/amarillo-gitea/amarillo-core/pipeline/head There was a failure building this commit
Some checks failed
Amarillo/amarillo-gitea/amarillo-core/pipeline/head There was a failure building this commit
This commit is contained in:
parent
f02fb0cbd8
commit
f00692904c
7
.gitignore
vendored
7
.gitignore
vendored
|
|
@ -172,3 +172,10 @@ data/trash/
|
|||
data/gtfs/
|
||||
data/tmp/
|
||||
data/agencyconf
|
||||
|
||||
|
||||
#these files are under app/static but they get copied to the outside directory on startup
|
||||
logging.conf
|
||||
config
|
||||
static/*
|
||||
templates/*
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
@ -38,3 +45,26 @@ def geodesic_distance_in_m(coord1, coord2):
|
|||
lons = [coord1[0], coord2[0]]
|
||||
lats = [coord1[1], coord2[1]]
|
||||
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}")
|
||||
|
|
@ -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",
|
||||
|
|
|
|||
Loading…
Reference in a new issue