Coverage for application/__init__.py: 74%

38 statements  

« prev     ^ index     » next       coverage.py v7.9.1, created at 2025-06-23 02:22 +0000

1import os 

2from pathlib import Path 

3 

4from dotenv import load_dotenv 

5from flask import Flask 

6from flask_session import Session 

7from time import time 

8 

9 

10load_dotenv() 

11 

12app = Flask(__name__) 

13app.secret_key = os.environ.get('SECRET_KEY') 

14app.config.from_object('application.config.Config') 

15 

16Session(app) 

17 

18print('\nLaunching application...') 

19 

20from application import main 

21from application.image_reference import image_reference_bp 

22from application.image_review import image_review_bp 

23from application.qaqc import qaqc_bp 

24from application.vars import vars_bp 

25from application.tator import tator_bp 

26 

27app.register_blueprint(image_reference_bp, url_prefix='/image-reference') 

28app.register_blueprint(image_review_bp, url_prefix='/image-review') 

29app.register_blueprint(qaqc_bp, url_prefix='/qaqc') 

30app.register_blueprint(vars_bp, url_prefix='/vars') 

31app.register_blueprint(tator_bp, url_prefix='/tator') 

32 

33print('\n\033[1;32;48mApplication running. Press CTRL + C to stop.\033[1;37;0m\n') 

34 

35if os.environ.get('_FLASK_ENV') == 'production': 

36 import webbrowser 

37 webbrowser.open_new('http://127.0.0.1:8000') 

38 

39# clean VARS frame cache 

40try: 

41 current_time = time() 

42 for cache_file in Path('cache', 'vars_frames').glob('*'): 

43 if not cache_file.is_file(): 

44 continue 

45 file_age = current_time - cache_file.stat().st_mtime 

46 if file_age > 60 * 60 * 24 * 14: # remove files older than 2 weeks 

47 file_size = cache_file.stat().st_size 

48 cache_file.unlink() 

49except Exception as e: 

50 print(f'Error during cache cleanup: {str(e)}')