Commit 48e5303b authored by Jérôme Ortais's avatar Jérôme Ortais
Browse files

Réparation du pour fonctionner avec py2exe et innosetup. Je...

Réparation du pour fonctionner avec py2exe et innosetup. Je m'interroge sur la pertinence de mettre les vignettes dans le dossier ex plutôt que data...
parent b3e0b852
......@@ -32,17 +32,25 @@ Created on 13 avr. 2013
import os
import sys
from glob import glob
import codecs
from glob import glob, has_magic
from os.path import dirname, normpath, join, abspath, realpath
from setuptools import setup, find_packages
py2exe, innosetup = None, None
import py2exe
import innosetup
except ImportError:
# Import pyromaths VERSION from source
_path = normpath(join(abspath(dirname(__file__)), "./src"))
sys.path[0] = realpath(_path)
from pyromaths.Values import VERSION
print "Version ", VERSION
def _unix_opt():
'''UNIX/Linux: generate Python eggs and RPM packages.'''
......@@ -119,41 +127,58 @@ def _mac_opt():
def _win_opt():
'''M$ Win: py2exe helps generate a self-contained app.'''
# import py2exe, innosetup
inno_script = '''
Compression = lzma/max
OutputBaseFilename = pyromaths-%s-win32
Name: "french";
MessagesFile: "compiler:Languages\French.isl"
Name: "french"; MessagesFile: "compiler:Languages\French.isl"
Name: "desktopicon";
Description: "{cm:CreateDesktopIcon}";
GroupDescription: "{cm:AdditionalIcons}";
Flags: unchecked
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked
Name: "{commondesktop}\Pyromaths";
Filename: "{app}\pyromaths.exe"
Name: "{commondesktop}\Pyromaths"; Filename: "{app}\pyromaths.exe"
return dict(
platforms = ['windows'],
app = ["src/"],
data_files = [('data', glob('data/*'))],
('data/images', ['data/images/pyromaths.ico',
'data/images/pyromaths.png', 'data/images/pyromaths-banniere.png',
(r'data/templates', glob(r'data/templates/*.tex')),
(r'data/packages', glob(r'data/packages/*')),
(r'data/packages', glob(r'data/packages/*')),
] + find_data_files('src/pyromaths/ex','data/ex/',['*/img/ex-*.png']),
zipfile = None,
windows = [dict(script="",
windows = [dict(script="src/",
icon_resources=[(1, 'data/images/pyromaths.ico')],
setup_requires = ['py2exe'],
options = dict(py2exe=dict(compressed = 1,
options = dict(py2exe=dict(compressed = True,
optimize = 2,
bundle_files = 3,
includes = ["sip", "gzip"],
packages = ['pyromaths.ex', ],
includes = ['sip', 'gzip', ],
innosetup=dict(inno_script=inno_script, compressed=True)
def find_data_files(source,target,patterns):
if has_magic(source) or has_magic(target):
raise ValueError("Magic not allowed in src, target")
ret = {}
for pattern in patterns:
pattern = os.path.join(source,pattern)
for filename in glob(pattern):
if os.path.isfile(filename):
targetpath = os.path.join(target, os.path.relpath(filename, source))
path = os.path.dirname(targetpath)
return sorted(ret.items())
# Set platform-specific options
if "py2app" in sys.argv:
options = _mac_opt()
......@@ -163,8 +188,12 @@ else:
options = _unix_opt()
# Long description is copied from README file
with open('README') as file:
if innosetup:
# innosetup fails with generated multiline long description
README = "Create maths exercises in LaTeX and PDF format"
with'README', encoding='utf-8', mode='r') as file:
# project metadata
# -*- coding: utf-8 -*-
import inspect
import os
import pkgutil
import types
import sys
levels = {}
......@@ -84,6 +88,10 @@ def __import(name=__name__, parent=None):
if not isinstance(name, basestring):
name = name.__name__
# parent is None: assume 'name' is a package name
# hack tout moche pour l'import des exercices dans la version Windows de Pyromaths :
# Les modules sixiemes, quatriemes doivent être appelés avec le chemin complet,
# alors que les exercices cinquiemes.aires ne doivent être appelés qu'ainsi.
if "." not in name and hasattr(sys, "frozen"): name = "pyromaths.ex." + name
if parent is None: parent = name
elif not isinstance(parent, basestring):
# assume 'parent' is a package instance
......@@ -106,7 +114,17 @@ def _exercises(pkg):
element = mod.__dict__[element]
level = __level(element.level if 'level' in dir(element)
else mod.level)
thumb = os.path.join(pkg.__path__[0], 'img', 'ex-%02d.png' % n)
if hasattr(sys, "frozen"):
# Hack pour déplacer les vignettes de la version Windows dans
# le dossier data/ex/{{ classe }}/img
dirlevel = os.path.split(pkg.__path__[0])[1]
thumb = os.path.join(os.path.normpath(\
os.path.dirname(unicode(sys.executable, \
sys.getfilesystemencoding()))), 'data', 'ex', \
dirlevel, 'img', 'ex-%02d.png' % n)
thumb = os.path.join(pkg.__path__[0], 'img', 'ex-%02d.png' % n)
if __isexercise(element):
element.level = level
element.thumb = thumb
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