| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
s |
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
import os |
| 30 |
from runpy import run_path |
| 31 |
|
| 32 |
from .parametres import modules_par_defaut |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
_skip_dir = ('OLD', '__pycache__') |
| 37 |
_modules_dir = os.path.normpath(os.path.join(__file__, '..', '..', 'modules')) |
| 38 |
|
| 39 |
def _detecter_modules(): |
| 40 |
modules = [] |
| 41 |
descriptions = {} |
| 42 |
def err(nom, msg): |
| 43 |
print("Warning: %s n'est pas un module valide (%s)." %(nom, msg)) |
| 44 |
for nom in os.listdir(_modules_dir): |
| 45 |
if nom not in _skip_dir and os.path.isdir(os.path.join(_modules_dir, nom)): |
| 46 |
description_file = os.path.join(_modules_dir, nom, 'description.py') |
| 47 |
if os.path.isfile(description_file): |
| 48 |
try: |
| 49 |
compile(nom + '=0', '', 'single') |
| 50 |
try: |
| 51 |
d = {} |
| 52 |
d = run_path(description_file, d) |
| 53 |
if d['description']['groupe'] != "Modules": |
| 54 |
n. |
| 55 |
continue |
| 56 |
descriptions[nom] = d['description'] |
| 57 |
modules.append(nom) |
| 58 |
except: |
| 59 |
err(nom, "fichier '%s' incorrect" %description_file) |
| 60 |
except Exception: |
| 61 |
err(nom, "nom de module invalide") |
| 62 |
else: |
| 63 |
err(nom, "fichier 'description.py' introuvable") |
| 64 |
return modules, descriptions |
| 65 |
|
| 66 |
try: |
| 67 |
modules, descriptions_modules = _detecter_modules() |
| 68 |
except OSError: |
| 69 |
print("Warning: impossible de détecter les modules (répertoire '%s') !" % _modules_dir) |
| 70 |
modules = [] |
| 71 |
descriptions_modules = {} |
| 72 |
|
| 73 |
|
| 74 |
modules_actifs = dict.fromkeys(modules, False) |
| 75 |
|
| 76 |
for nom in modules_par_defaut: |
| 77 |
modules_actifs[nom] = True |
| 78 |
|
| 79 |
|
| 80 |
def _key(nom): |
| 81 |
r, |
| 82 |
e. |
| 83 |
key = [1000000, nom] |
| 84 |
if nom in modules_par_defaut: |
| 85 |
key[0] = modules_par_defaut.index(nom) |
| 86 |
return key |
| 87 |
|
| 88 |
modules.sort(key = _key) |