__init__.py 1.65 KB
Newer Older
1
2
3
4
5
6
7
#!/usr/bin/env python3

import os
from flask import Flask
from .config_reader import AppConfigReader
from .lib.crons import Crons

8
9
VERSION = "1.0.1"

Floreal Cabanettes's avatar
Floreal Cabanettes committed
10
11
12
13
14
app = None
app_title = None
APP_DATA = None
config_reader = None
mailer = None
Floreal Cabanettes's avatar
Floreal Cabanettes committed
15
app_folder = None
16
17
MODE = "webserver"
DEBUG = False
18
19


20
21
def launch(mode="webserver", debug=False):
    global app, app_title, app_folder, APP_DATA, config_reader, mailer, MODE, DEBUG
Floreal Cabanettes's avatar
Floreal Cabanettes committed
22
    app_folder = os.path.dirname(os.path.realpath(__file__))
23

24
25
    MODE = mode
    DEBUG = debug
26

Floreal Cabanettes's avatar
Floreal Cabanettes committed
27
28
    # Init config reader:
    config_reader = AppConfigReader()
29

Floreal Cabanettes's avatar
Floreal Cabanettes committed
30
31
    UPLOAD_FOLDER = config_reader.upload_folder
    APP_DATA = config_reader.app_data
32

Floreal Cabanettes's avatar
Floreal Cabanettes committed
33
    app_title = "D-GENIES - Dotplot large Genomes in an Interactive, Efficient and Simple way"
34

Floreal Cabanettes's avatar
Floreal Cabanettes committed
35
    # Init Flask:
36
    app = Flask(__name__, static_url_path='/static')
Floreal Cabanettes's avatar
Floreal Cabanettes committed
37
38
39
    app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
    app.config['MAX_CONTENT_LENGTH'] = config_reader.max_upload_file_size
    app.config['SECRET_KEY'] = 'dsqdsq-255sdA-fHfg52-25Asd5'
40

Floreal Cabanettes's avatar
Floreal Cabanettes committed
41
    # Init mail:
42
43
44
    if MODE == "webserver":
        from .lib.mailer import Mailer
        mailer = Mailer(app)
45

46
47
48
49
    # Create data dir if not exists
    if not os.path.exists(config_reader.app_data):
        os.makedirs(config_reader.app_data)

Floreal Cabanettes's avatar
Floreal Cabanettes committed
50
51
    if config_reader.debug and config_reader.log_dir != "stdout" and not os.path.exists(config_reader.log_dir):
        os.makedirs(config_reader.log_dir)
52

Floreal Cabanettes's avatar
Floreal Cabanettes committed
53
    # Crons:
54
    if os.getenv('DISABLE_CRONS') != "True" and MODE == "webserver":
Floreal Cabanettes's avatar
Floreal Cabanettes committed
55
56
57
58
59
60
61
        print("Starting crons...")
        crons = Crons(app_folder, config_reader.debug or os.getenv('LOGS') == "True")
        crons.start_all()

    from dgenies import views

    return app