move glob and utils

This commit is contained in:
Dmitry Belyaev 2021-10-07 13:39:09 +03:00
parent 96023662d3
commit 8eef627c2e
Signed by: b4tman
GPG Key ID: 41A00BF15EA7E5F3
3 changed files with 33 additions and 25 deletions

18
app/glob.py Normal file
View File

@ -0,0 +1,18 @@
from flask import g
from app.config import load_config, config_location
from app.manager import PublicationManager
def get_config():
if 'config' not in g:
g.config = load_config(config_location())
return g.config
def get_manager():
if 'manager' not in g:
g.manager = PublicationManager(get_config())
return g.manager

10
app/utils.py Normal file
View File

@ -0,0 +1,10 @@
from typing import Optional
from flask_restful import abort
from pathvalidate import is_valid_filepath
def validate_url(url: Optional[str]):
if url is not None:
if not is_valid_filepath(url, platform='posix'):
abort(400, message='invalid url')

View File

@ -1,14 +1,14 @@
import os
from typing import List, Optional, Dict
from typing import List, Dict
import traceback
from flask import Flask, g, render_template
from flask import Flask, render_template
from flask_restful import Resource, Api, reqparse, abort
from flask_cors import CORS
from pathvalidate import is_valid_filepath
from app.config import load_config, config_location
from app.manager import infobase_data_blank, PublicationManager
from app.glob import get_config, get_manager
from app.manager import infobase_data_blank
from app.utils import validate_url
from brackets import get_infobases as br_get_infobases
apache_restart_flagfile = 'restart_apache'
@ -28,20 +28,6 @@ remove_parser = reqparse.RequestParser()
remove_parser.add_argument('force', type=bool, default=False)
def get_config():
if 'config' not in g:
g.config = load_config(config_location())
return g.config
def get_manager():
if 'manager' not in g:
g.manager = PublicationManager(get_config())
return g.manager
def load_infobases(config) -> List[str]:
result = []
if 'infobases' in config and 'server_file' in config['infobases']:
@ -49,12 +35,6 @@ def load_infobases(config) -> List[str]:
return result
def validate_url(url: Optional[str]):
if url is not None:
if not is_valid_filepath(url, platform='posix'):
abort(400, message='invalid url')
class InfobasesAvailable(Resource):
def get(self) -> List[str]:
cfg = get_config()