This repository has been archived by the owner on Jun 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathengine.py
executable file
·71 lines (63 loc) · 2.41 KB
/
engine.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env python
from website import app
from dotenv import load_dotenv
from pathlib import Path
import argparse
from importlib import import_module
load_dotenv()
BASE_DIR = Path(__file__).resolve().parent
def db_update(cls_type):
cls_instance = cls_type()
print(cls_instance.filename, 'en cours.')
try:
data = cls_instance.request()
cls_instance.output(data) # filter on request result and save it
except FileNotFoundError:
print('Error', cls_type, ': FileNotFound')
def db_cross_update(cls_type, max_range: int = 0):
cls_instance = cls_type()
print(cls_instance, 'en cours.')
try:
cls_instance.load(max_range=max_range)
cls_instance.apply_algo()
cls_instance.dump()
except FileNotFoundError:
print('Error', cls_type, ': FileNotFound')
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Pollux - Fonctionnalités.')
parser.add_argument("-uDB", "--updateDB",
nargs='*',
help="Mettre à jour les bases de données de l'application.")
parser.add_argument("-uCDB", "--updateCrossDB",
nargs='*',
help="Appliquer un algorithme pour mettre à jour une base de données croisée.")
parser.add_argument("-mr", "--maxRange")
args = parser.parse_args()
if args.updateDB is not None:
db_args = args.updateDB
for db_arg in db_args:
arg = db_arg.replace('.py', '').replace('/', '.')
try:
cls = import_module(arg).Works
except ModuleNotFoundError:
print(f'Module {arg} introuvable.')
except AttributeError:
print(f'Classe {arg}.Works introuvable.')
else:
db_update(cls)
print('Mise à jour terminée.')
elif args.updateCrossDB is not None:
arg = args.updateCrossDB[0].replace('.py', '').replace('/', '.')
try:
cls = import_module(arg).Cross
except ModuleNotFoundError:
print(f'Module {arg} introuvable.')
except AttributeError:
print(f'Classe {arg}.Cross introuvable.')
else:
db_cross_update(cls, max_range=int(args.maxRange or 0))
print('Mise à jour terminée.')
elif args.maxRange is not None:
print("Utilisable qu'avec la commande --updateCrossDB.")
else:
app.run()