| 1 | #!/usr/bin/env python |
|---|
| 2 | |
|---|
| 3 | # Un petit outil pour aranger des boites |
|---|
| 4 | # Copyright (C) 2009 Luper ROUCH <luper.rouch@gmail.com> |
|---|
| 5 | # |
|---|
| 6 | # This program is free software: you can redistribute it and/or modify |
|---|
| 7 | # it under the terms of the GNU General Public License as published by |
|---|
| 8 | # the Free Software Foundation, either version 3 of the License, or |
|---|
| 9 | # any later version. |
|---|
| 10 | # |
|---|
| 11 | # This program is distributed in the hope that it will be useful, |
|---|
| 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 14 | # GNU General Public License for more details. |
|---|
| 15 | # |
|---|
| 16 | # You should have received a copy of the GNU General Public License |
|---|
| 17 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|---|
| 18 | |
|---|
| 19 | import sys |
|---|
| 20 | import os |
|---|
| 21 | from os.path import join, basename, splitext, getmtime, dirname |
|---|
| 22 | from setuptools import setup, find_packages |
|---|
| 23 | from boxsort import version |
|---|
| 24 | from pyflu.setuptools.base import CommandBase |
|---|
| 25 | from pyflu.setuptools.qt import CompilePyQtCommand |
|---|
| 26 | from pyflu.path import sub_path |
|---|
| 27 | from pyflu.command import run_script |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | class CompileNsisCommand(CommandBase): |
|---|
| 31 | |
|---|
| 32 | user_options = [ |
|---|
| 33 | ("nsis-template", None, "NSIS Installer template file."), |
|---|
| 34 | ("nsis-compiler", None, "NSIS compiler path."), |
|---|
| 35 | ("script-output", None, "Compiled script file."), |
|---|
| 36 | ] |
|---|
| 37 | |
|---|
| 38 | defaults = { |
|---|
| 39 | "nsis_compiler": "makensis.exe", |
|---|
| 40 | "script_output": "installer.nsi", |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | input = [ ] |
|---|
| 44 | """ |
|---|
| 45 | List of input directories. |
|---|
| 46 | |
|---|
| 47 | Each entry is a tuple: (type, input, output_dir) |
|---|
| 48 | |
|---|
| 49 | ``type`` is a string indicating the entry type : 'd' for a directory, 'f' |
|---|
| 50 | for a file. ``input`` is the file or directory input and ``output_dir`` |
|---|
| 51 | the output directory, relative to the installation directory. |
|---|
| 52 | """ |
|---|
| 53 | |
|---|
| 54 | def run(self): |
|---|
| 55 | script_file = open(self.script_output, "w") |
|---|
| 56 | template_file = open(self.nsis_template, "r") |
|---|
| 57 | data = { |
|---|
| 58 | "version": version(), |
|---|
| 59 | } |
|---|
| 60 | # Build input files list |
|---|
| 61 | files = [] |
|---|
| 62 | for etype, input, output in self.input: |
|---|
| 63 | if etype == "d": |
|---|
| 64 | self.append_tree(input, output, files) |
|---|
| 65 | elif etype == "f": |
|---|
| 66 | print basename(input), output |
|---|
| 67 | files.append((join(output, basename(input)), input)) |
|---|
| 68 | data["install_files"] = "\n".join([ |
|---|
| 69 | 'SetOutPath "$INSTDIR\%s"\nFile "%s"' % |
|---|
| 70 | (dirname(e[0]), e[1]) for e in files]) |
|---|
| 71 | data["uninstall_files"] = "\n".join( |
|---|
| 72 | ['Delete "$INSTDIR\%s"' % e[0] for e in files]) |
|---|
| 73 | # Render template |
|---|
| 74 | script_file.write(template_file.read() % data) |
|---|
| 75 | script_file.close() |
|---|
| 76 | # Compile |
|---|
| 77 | run_script("%s %s" % (self.nsis_compiler, self.script_output)) |
|---|
| 78 | |
|---|
| 79 | def append_tree(self, dir, output, files_list): |
|---|
| 80 | for base, dirs, files in os.walk(dir): |
|---|
| 81 | sub_dir = sub_path(base, dir) |
|---|
| 82 | for file in files: |
|---|
| 83 | files_list.append((join(output, sub_dir, file), |
|---|
| 84 | join(base, file))) |
|---|
| 85 | |
|---|
| 86 | |
|---|
| 87 | class BoxSortNsisCommand(CompileNsisCommand): |
|---|
| 88 | defaults = { |
|---|
| 89 | "nsis_template": "installer-template.nsi", |
|---|
| 90 | } |
|---|
| 91 | |
|---|
| 92 | input = [ |
|---|
| 93 | ("d", "dist", ""), |
|---|
| 94 | ] |
|---|
| 95 | |
|---|
| 96 | |
|---|
| 97 | class BoxSortCompilePyQtCommand(CompilePyQtCommand): |
|---|
| 98 | defaults = { |
|---|
| 99 | "ui_dirs": "files/gui", |
|---|
| 100 | "output_dir": "boxsort/gui/ui", |
|---|
| 101 | "widgets_dir": "boxsort/gui/widgets", |
|---|
| 102 | "dialogs_dir": "boxsort/gui/dialogs", |
|---|
| 103 | "default_dir": "boxsort/gui", |
|---|
| 104 | } |
|---|
| 105 | |
|---|
| 106 | |
|---|
| 107 | dependencies = ["pyflu"] |
|---|
| 108 | packages = find_packages(exclude=["boxsort.bin", "tests", "files"]) |
|---|
| 109 | |
|---|
| 110 | |
|---|
| 111 | setup_opts = dict( |
|---|
| 112 | name = "BoxSort", |
|---|
| 113 | version = version(), |
|---|
| 114 | author = "Luper Rouch", |
|---|
| 115 | author_email = "luper.rouch@gmail.com", |
|---|
| 116 | |
|---|
| 117 | install_requires = dependencies, |
|---|
| 118 | |
|---|
| 119 | packages = packages, |
|---|
| 120 | |
|---|
| 121 | scripts = [ |
|---|
| 122 | "boxsort/bin/boxsort-gui.py", |
|---|
| 123 | ], |
|---|
| 124 | test_suite = "tests.test_suite", |
|---|
| 125 | cmdclass = { |
|---|
| 126 | "qtcompile": BoxSortCompilePyQtCommand, |
|---|
| 127 | "makeinstaller": BoxSortNsisCommand, |
|---|
| 128 | }, |
|---|
| 129 | ) |
|---|
| 130 | |
|---|
| 131 | if sys.platform == "win32": |
|---|
| 132 | # py2exe settings |
|---|
| 133 | import py2exe |
|---|
| 134 | setup_opts["windows"] = ["boxsort/bin/boxsort-gui.py"] |
|---|
| 135 | setup_opts["options"] = { |
|---|
| 136 | "py2exe": { |
|---|
| 137 | "compressed": 1, |
|---|
| 138 | "optimize": 2, |
|---|
| 139 | "includes": ["sip", "pyflu"], |
|---|
| 140 | "excludes": ["tcl"], |
|---|
| 141 | } |
|---|
| 142 | } |
|---|
| 143 | elif sys.platform == "darwin": |
|---|
| 144 | # py2app settings |
|---|
| 145 | setup_opts["app"] = ["boxsort/bin/boxsort-gui.py"] |
|---|
| 146 | setup_opts["options"] = { |
|---|
| 147 | "py2app": { |
|---|
| 148 | "optimize": 2, |
|---|
| 149 | "includes": ["sip", "pyflu"], |
|---|
| 150 | "excludes": ["tcl"], |
|---|
| 151 | } |
|---|
| 152 | } |
|---|
| 153 | |
|---|
| 154 | setup(**setup_opts) |
|---|