File: setup.py

package info (click to toggle)
mnemosyne 2.0~RC1-3
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 3,872 kB
  • sloc: python: 19,339; makefile: 5
file content (225 lines) | stat: -rw-r--r-- 9,321 bytes parent folder | download
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
import os, sys, shutil, glob

from distutils.core import Extension
from setuptools import setup

if sys.platform == "win32":
    import py2exe
    from py2exe.build_exe import py2exe
else:
    class py2exe:
        pass

import mnemosyne.version


class InnoScript:
    def __init__(self, name, lib_dir, dist_dir, windows_exe_files = [],
                 lib_files = [], qm_files = [],
                 version = mnemosyne.version.version):
        self.lib_dir = lib_dir
        self.dist_dir = dist_dir
        if not self.dist_dir[-1] in "\\/":
            self.dist_dir += "\\"
        self.name = name
        self.version = version
        self.windows_exe_files = [self.chop(p) for p in windows_exe_files]
        self.lib_files = [self.chop(p) for p in lib_files]

    def chop(self, pathname):
        assert pathname.startswith(self.dist_dir)
        return pathname[len(self.dist_dir):]

    def create(self, pathname="dist\\mnemosyne.iss"):
        self.pathname = pathname
        ofi = self.file = open(pathname, "w")
        print >> ofi, "; WARNING: This script has been created by py2exe. "+\
                        "Changes to this script"
        print >> ofi, "; will be overwritten the next time py2exe is run!"
        print >> ofi, r"[Setup]"
        print >> ofi, r"AppName=%s" % self.name
        print >> ofi, r"AppVerName=%s %s" % (self.name, self.version)
        print >> ofi, r"DefaultDirName={pf}\%s" % self.name
        print >> ofi, r"DefaultGroupName=%s" % self.name
        print >> ofi

        print >> ofi, r"[Files]"
        for path in self.windows_exe_files + self.lib_files:
            print >> ofi, r'Source: "%s"; DestDir: "{app}\%s"; Flags: ignoreversion' \
                                    % (path, os.path.dirname(path))
        print >> ofi

        print >> ofi, r"[Icons]"
        for path in self.windows_exe_files:
            print >> ofi, r'Name: "{group}\%s"; Filename: "{app}\%s"' \
                            % (self.name, path),
        print >> ofi, ' ; WorkingDir: {app}'
        print >> ofi, 'Name: "{group}\Uninstall %s"; Filename: "{uninstallexe}"'\
                            % self.name

    def compile(self):
        try:
            import ctypes
        except ImportError:
            try:
                import win32api
            except ImportError:
                import os
                os.startfile(self.pathname)
            else:
                print "Ok, using win32api."
                win32api.ShellExecute(0,"compile", self.pathname, None, None, 0)
        else:
            print "Cool, you have ctypes installed."
            res = ctypes.windll.shell32.ShellExecuteA(0, "compile",
                self.pathname, None, None, 0)
            if res < 32:
                raise RuntimeError, "ShellExecute failed, error %d" % res


class build_installer(py2exe):

    """This first builds the exe file(s), then creates a Windows installer.
    You need InnoSetup for it.

    """

    def run(self):
        # First, let py2exe do it's work.
        py2exe.run(self)
        lib_dir = self.lib_dir
        dist_dir = self.dist_dir
        # Create the Installer, using the files py2exe has created.
        script = InnoScript("Mnemosyne", lib_dir, dist_dir,
                            self.windows_exe_files, self.lib_files,
                            version=mnemosyne.version.version)
        script.create()
        script.compile()
        # Note: the final setup.exe will be in an Output subdirectory.

if sys.platform == "win32": # For py2exe.
    import matplotlib
    sys.path.append("C:\\Program Files\\Microsoft Visual Studio 9.0\\VC\\redist\\x86\\Microsoft.VC90.CRT")
    base_path = ""
    data_files = [("Microsoft.VC90.CRT", glob.glob(r"C:\Program Files\Microsoft Visual Studio 9.0\VC\redist\x86\Microsoft.VC90.CRT\*.*")),
                  ("mpl-data", glob.glob(r"C:\Python27\Lib\site-packages\matplotlib\mpl-data\*.*")),
                  # Because matplotlibrc does not have an extension, glob does not find it (at least I think that"s why)
                  # So add it manually here:
                  ("mpl-data", [r"C:\Python27\Lib\site-packages\matplotlib\mpl-data\matplotlibrc"]),
                  (r"mpl-data\images", glob.glob(r"C:\Python27\Lib\site-packages\matplotlib\mpl-data\images\*.*")),
                  (r"mpl-data\fonts\ttf", glob.glob(r"C:\Python27\Lib\site-packages\matplotlib\mpl-data\fonts\ttf\*.*")),
                  ("phonon_backend", ["C:\Python27\Lib\site-packages\PyQt4\plugins\phonon_backend\phonon_ds94.dll"]),
                  ("imageformats", glob.glob(r"C:\Python27\Lib\site-packages\PyQt4\plugins\imageformats\*.dll")),
                  ("sqldrivers", ["C:\Python27\Lib\site-packages\PyQt4\plugins\sqldrivers\qsqlite4.dll"])
                  ]
elif sys.platform == "darwin": # For py2app.
    base_path = ""
    data_files = []
else:
    base_path = os.path.join(sys.exec_prefix, "lib", "python" + sys.version[:3],
                             "site-packages","mnemosyne")
    data_files = [("/usr/share/applications", ["mnemosyne.desktop"]),
                  ("/usr/share/icons", ["pixmaps/mnemosyne.png"])]
# Translations.
if sys.platform == "win32":
    for mo in [x for x in glob.glob(os.path.join("mo", "*")) \
        if os.path.isdir(x)]:
        p, lang = os.path.split(mo)
        data_files.append((os.path.join("share", "locale",
            os.path.split(mo)[1], "LC_MESSAGES"),
            [os.path.join(mo, "LC_MESSAGES", "mnemosyne.mo")]))
        data_files.append((os.path.join("share", "qt4", "translations"),
            glob.glob(os.path.join("mnemosyne", "pyqt_ui", "qm", '*'))))
else:
    for mo in [x for x in glob.glob(os.path.join("mo", "*"))
               if os.path.isdir(x)]:
        data_files.append((os.path.join(sys.exec_prefix, "share", "locale",
            os.path.split(mo)[1], "LC_MESSAGES"),
            [os.path.join(mo, "LC_MESSAGES", "mnemosyne.mo")]))

pixmap_path = os.path.join(base_path, "pixmaps")
util_path = os.path.join(base_path, "util")
doc_path = os.path.join(base_path, "docs")
build_path = os.path.join(base_path, "build")

setup_requires = []

# py2app (OS X).
py2app_options = {
    "argv_emulation": True,
    "includes": "sip,qt,cPickle,md5,logging,shutil,xml.sax,\
                  xml.sax.drivers2.drv_pyexpat",
    "resources": "mnemosyne",
    "iconfile": "pixmaps/mnemosyne.icns"
}
py2app_app = ["build/Mnemosyne.py"]
if "py2app" in sys.argv:
    setup_requires.append("py2app")
    # Create the application script.
    if not os.path.exists(build_path):
        os.mkdir(build_path)
    # Create a copy in build/ with name Mnemosyne.py, because py2app
    # needs a script that ends in .py.
    appscript = os.path.join(build_path, "Mnemosyne.py")
    source = os.path.join(base_path, "mnemosyne", "pyqt_ui", "mnemosyne")
    if os.path.exists(appscript):
        os.unlink(appscript)
    shutil.copyfile(source, appscript)

package_name = "mnemosyne"
packages = ["mnemosyne",
            "mnemosyne.pyqt_ui",
            "mnemosyne.libmnemosyne",
            "mnemosyne.libmnemosyne.translators",
            "mnemosyne.libmnemosyne.card_types",
            "mnemosyne.libmnemosyne.databases",
            "mnemosyne.libmnemosyne.file_formats",
            "mnemosyne.libmnemosyne.filters",
            "mnemosyne.libmnemosyne.loggers",
            "mnemosyne.libmnemosyne.plugins",
            "mnemosyne.libmnemosyne.renderers",
            "mnemosyne.libmnemosyne.render_chains",
            "mnemosyne.libmnemosyne.schedulers",
            "mnemosyne.libmnemosyne.controllers",
            "mnemosyne.libmnemosyne.ui_components",
            "mnemosyne.libmnemosyne.statistics_pages",
            "mnemosyne.libmnemosyne.review_controllers",
            "mnemosyne.libmnemosyne.criteria",
            "mnemosyne.libmnemosyne.upgrades",
            "mnemosyne.script",
            "mnemosyne.webserver",
            "openSM2sync",
            "openSM2sync.binary_formats",
            "openSM2sync.text_formats"
            ]

py2exe_options = {
    "packages": ["mnemosyne", "numpy", "sip", "xml.sax", "xml.etree"],
    "optimize": 2,
    "includes": ["numpy", "sip", "xml.sax", "xml.etree", "PyQt4.QtNetwork"],
    "excludes": ["_gtkagg", "_tkagg", "_agg2", "_cairo", "_cocoaagg",
                 "_fltkagg", "_gtk", "_gtkcairo", "tcl", "Tkconstants", "Tkinter",
                 "pydoc", "doctest", "test"],
    "dll_excludes": ["libgdk-win32-2.0-0.dll", "libgobject-2.0-0.dll",
                     "tcl84.dll", "tk84.dll"]
}

setup(name = "Mnemosyne",
      version = mnemosyne.version.version,
      author = "Peter Bienstman",
      author_email = "Peter.Bienstman@UGent.be",
      packages = packages,
      package_dir = {"mnemosyne": "mnemosyne"},
      data_files = data_files,
      scripts = ["mnemosyne/pyqt_ui/mnemosyne", "mnemosyne/webserver/mnemosyne-webserver"],
      # py2exe
      windows = [{#"console": "mnemosyne/webserver/mnemosyne-webserver",
                  "script": "mnemosyne/pyqt_ui/mnemosyne",
                  "icon_resources": [(1, "pixmaps/mnemosyne.ico")]}],
      cmdclass = {"py2exe": build_installer},
      # py2app
      setup_requires = setup_requires,
      options = {"py2app": py2app_options, "py2exe": py2exe_options},
      app = py2app_app
)