aboutsummaryrefslogtreecommitdiffstats
path: root/setup-files/windows/setup.py
blob: 0e013d3a9c409914c51952dd4487c4842e0cd716 (plain)
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
"""setup-windows.py -- setup script for windows

Usage:

"""
from distutils import log
from distutils.core import Command, setup
from glob import glob
import itertools
import os
import subprocess
import sys

import py2exe

from lvc import resources

env_path = os.path.abspath(os.path.dirname(os.path.dirname(sys.executable)))
nsis_path = os.path.join(env_path, 'nsis-2.46', 'makensis.exe')
scripts_path = os.path.join(env_path, 'Scripts')

packages = [
    'lvc',
    'lvc.widgets',
    'lvc.widgets.gtk',
    'lvc.ui',
    'lvc.resources',
    'lvc.windows',
    'lvc.qtfaststart',
]


def resources_dir():
    return os.path.dirname(resources.__file__)


def resource_data_files(subdir, globspec='*.*'):
    dest_dir = os.path.join("resources", subdir)
    dir_contents = glob(os.path.join(resources_dir(), subdir, globspec))
    return [(dest_dir, dir_contents)]


def ffmpeg_data_files():
    ffmpeg_dir = os.path.join(env_path, 'ffmpeg')
    return [
        ('ffmpeg',
         [os.path.join(ffmpeg_dir, 'ffmpeg.exe')]),
        # ('ffmpeg/presets',
        # glob(os.path.join(ffmpeg_dir, 'presets', '*.ffpreset'))),
    ]


def winsparkle_data_files():
    winsparkle_dll = os.path.join(env_path, 'WinSparkle-0.3',
                                  "WinSparkle.dll")
    return [
        ('', [winsparkle_dll]),
    ]


def gtk_theme_data_files():
    engine_path = os.path.join(env_path, 'gtk2-themes-2009-09-07-win32_bin',
                               'lib', 'gtk-2.0', '2.10.0', 'engines',
                               'libclearlooks.dll')
    gtkrc_path = os.path.join(resources_dir(), 'windows', 'gtkrc')
    return [
        ('etc/gtk-2.0', [gtkrc_path]),
        ('lib/gtk-2.0/2.10.0/engines', [engine_path])
    ]


def avconv_data_files():
    avconv_dir = os.path.join(env_path, 'avconv')
    return [
        ('avconv',
         glob(os.path.join(avconv_dir, '*.*'))),
    ]


def data_files():
    return list(itertools.chain(
        resource_data_files("images"),
        resource_data_files("converters", "*.py"),
        ffmpeg_data_files(),
        winsparkle_data_files(),
        gtk_theme_data_files(),
        # avconv_data_files(),
    ))


def gtk_includes():
    return ['gtk', 'gobject', 'atk', 'pango', 'pangocairo', 'gio']


def py2exe_includes():
    return gtk_includes()


class bdist_nsis(Command):
    description = "create MVC installer using NSIS"
    user_options = [
    ]

    def initialize_options(self):
        pass

    def finalize_options(self):
        pass

    def run(self):
        self.run_command('py2exe')
        self.dist_dir = self.get_finalized_command('py2exe').dist_dir

        log.info("building installer")

        nsis_source = os.path.join(SETUP_DIR, 'lvc.nsi')
        self.copy_file(nsis_source, self.dist_dir)
        for nsis_file in glob(os.path.join(resources_dir(), 'nsis', '*.*')):
            self.copy_file(nsis_file, self.dist_dir)

        plugins_dir = os.path.join(resources_dir(), 'nsis', 'plugins')
        script_path = os.path.join(self.dist_dir, 'lvc.nsi')
        nsis_defines = {
            'CONFIG_PLUGIN_DIR': plugins_dir,
        }
        cmd_line = [nsis_path]
        for name, value in nsis_defines.items():
            cmd_line.append("/D%s=%s" % (name, value))
        cmd_line.append(script_path)

        if subprocess.call(cmd_line) != 0:
            print "ERROR creating the 1 stage installer, quitting"
            return
setup(
    windows=[
        {'script': 'lvc/windows/exe_main.py',
         'dest_base': 'lvc',
         'company_name': 'Participatory Culture Foundation',
        },
    ],
    console=[
        {'script': 'lvc/windows/exe_main.py',
         'dest_base': 'lvcdebug',
         'company_name': 'Participatory Culture Foundation',
        },
    ],
    data_files=data_files(),
    cmdclass={
        'bdist_nsis': bdist_nsis,
        },
    options={
        'py2exe': {
            'includes': py2exe_includes(),
        },
    },
    **SETUP_ARGS
)