Commit cab7809b authored by Olivier Cornu's avatar Olivier Cornu
Browse files

Découverte automatique des packages d'exercices situés dans pyromaths.ex.

Un package d'exercies doit avoir une propriété 'description', de type
Unicode, dans son fichier __init__.py.

Note: L'affichage des niveaux dans l'UI correspond à l'ordre de découverte
des packages d'exercices correspondant, c'est à dire l'ordre alphabétique.
parent 3c410a0a
......@@ -7,6 +7,7 @@ from os import environ, name
from sys import executable, getfilesystemencoding
import sys
import pkgutil, types
import ex
def we_are_frozen():
"""Returns whether we are frozen via py2exe.
......@@ -94,13 +95,26 @@ def _exercices(pkg):
exercices.append(element)
return exercices
def _packages():
''' List exercise packages from pyromaths.ex. '''
import ex.sixiemes, ex.cinquiemes, ex.quatriemes, ex.troisiemes, ex.lycee
return [ex.sixiemes, ex.cinquiemes, ex.quatriemes, ex.troisiemes, ex.lycee]
def _packages(pkg):
''' Discover all packages located in pkg. '''
packages = []
# search packages
for _, name, ispkg in pkgutil.iter_modules(pkg.__path__, pkg.__name__+'.'):
# skip modules
if not ispkg: continue
# import discovered package
package = __import__(name, fromlist=pkg.__name__)
# exercise packages must have a description property
if 'description' not in dir(package): continue
description = package.__dict__['description']
# description property must be Unicode
if not type(description) is types.UnicodeType: continue
# valid exercise package
packages.append(package)
return packages
# Packages d'exercices
PACKAGES = _packages()
PACKAGES = _packages(ex)
LESFICHES = []
for pkg in PACKAGES:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment