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 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright 2008-2009 Zuza Software Foundation
#
# This file is part of Virtaal.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
from distutils.core import setup, Distribution, Command
from virtaal.__version__ import ver as virtaal_version
from glob import glob
import os
import os.path as path
import sys
try:
import py2exe
build_exe = py2exe.build_exe.py2exe
Distribution = py2exe.Distribution
except ImportError:
py2exe = None
build_exe = Command
try:
import py2app
except ImportError:
py2app = None
PRETTY_NAME = "Virtaal"
SOURCE_DATA_DIR = 'share'
TARGET_DATA_DIR = 'share'
virtaal_description="A tool to create program translations."
classifiers = [
"Development Status :: 5 - Production/Stable",
"Environment :: Console",
"Intended Audience :: Developers",
"Intended Audience :: End Users/Desktop",
"Intended Audience :: Information Technology",
"License :: OSI Approved :: GNU General Public License (GPL)",
"Programming Language :: Python",
"Topic :: Software Development :: Localization",
"Topic :: Text Processing :: Linguistic"
"Operating System :: OS Independent",
"Operating System :: Microsoft :: Windows",
"Operating System :: Unix"
]
#TODO: add Natural Language classifiers
# Compile .mo files from available .po files
from translate.tools.pocompile import convertmo
mo_files = []
for lang in open(path.join('po', 'LINGUAS')):
lang = lang.rstrip()
po_filename = path.join('po', lang+'.po')
mo_filename = path.join('mo', lang, 'virtaal.mo')
if not path.exists(path.join('mo', lang)):
os.makedirs(path.join('mo', lang))
convertmo(open(po_filename), open(mo_filename, 'w'), None)
mo_files.append(
( path.join(TARGET_DATA_DIR, 'locale', lang, 'LC_MESSAGES'), [mo_filename])
)
# Build lite files as needed on Win32 and OS X
if os.name == 'nt' or sys.platform == 'darwin':
for lang in open(path.join('po', 'LINGUAS-lite')):
app, lang = lang.rstrip().split('/')
po_filename = path.join('po', 'lite', app, lang+'.po')
mo_filename = path.join('mo', lang, app+'.mo')
if not path.exists(path.join('mo', lang)):
os.makedirs(path.join('mo', lang))
convertmo(open(po_filename), open(mo_filename, 'w'), None)
mo_files.append(
( path.join(TARGET_DATA_DIR, 'locale', lang, 'LC_MESSAGES'), [mo_filename])
)
# Some of these depend on some files to be built externally before running
# setup.py, like the .xml and .desktop files
options = {
'data_files': [
(path.join(TARGET_DATA_DIR, "virtaal"), glob(path.join(SOURCE_DATA_DIR, "virtaal", "*.*"))),
(path.join(TARGET_DATA_DIR, "icons"), glob(path.join(SOURCE_DATA_DIR, "icons", "*.*"))),
] + mo_files,
'scripts': [
"bin/virtaal",
],
'packages': [
"virtaal",
"virtaal.common",
"virtaal.controllers",
"virtaal.models",
"virtaal.modes",
"virtaal.plugins",
"virtaal.plugins.lookup",
"virtaal.plugins.lookup.models",
"virtaal.plugins.terminology",
"virtaal.plugins.terminology.models",
"virtaal.plugins.terminology.models.localfile",
"virtaal.plugins.tm",
"virtaal.plugins.tm.models",
"virtaal.support",
"virtaal.support.libi18n",
"virtaal.views",
"virtaal.views.widgets"
],
}
# For innosetup and py2app, we need to treat the plug-ins as data files.
if os.name == 'nt' or sys.platform == 'darwin':
noplugins = []
for pkg in options['packages']:
if 'plugins' not in pkg:
noplugins.append(pkg)
options['packages'] = noplugins
plugin_src = path.join('virtaal', 'plugins')
plugin_dest = 'virtaal_plugins'
options['data_files'] += [
(plugin_dest, glob(path.join(plugin_src, '*.py'))),
(path.join(plugin_dest, 'lookup'), glob(path.join(plugin_src, 'lookup', '*.py'))),
(path.join(plugin_dest, 'lookup', 'models'), glob(path.join(plugin_src, 'lookup', 'models', '*.py'))),
(path.join(plugin_dest, 'terminology'), glob(path.join(plugin_src, 'terminology', '*.py'))),
(path.join(plugin_dest, 'terminology', 'models'), glob(path.join(plugin_src, 'terminology', 'models', '*.py'))),
(path.join(plugin_dest, 'terminology', 'models', 'localfile'), glob(path.join(plugin_src, 'terminology', 'models', 'localfile', '*.py'))),
(path.join(plugin_dest, 'tm'), glob(path.join(plugin_src, 'tm', '*.py'))),
(path.join(plugin_dest, 'tm', 'models'), glob(path.join(plugin_src, 'tm', 'models', '*.py'))),
]
no_install_files = [
['LICENSE', 'maketranslations', path.join('devsupport', 'virtaal_innosetup.bmp')]
]
no_install_dirs = ['po', 'share/virtaal/autocorr']
#############################
# WIN 32 specifics
def get_compile_command():
try:
import _winreg
compile_key = _winreg.OpenKey(_winreg.HKEY_CLASSES_ROOT, "innosetupscriptfile\\shell\\compile\\command")
compilecommand = _winreg.QueryValue(compile_key, "")
compile_key.Close()
except:
compilecommand = "compil32.exe"
return compilecommand
def chop(dist_dir, pathname):
"""returns the path relative to dist_dir"""
assert pathname.startswith(dist_dir)
return pathname[len(dist_dir):]
def create_inno_script(name, _lib_dir, dist_dir, exe_files, other_files, version = "1.0"):
if not dist_dir.endswith(os.sep):
dist_dir += os.sep
exe_files = [chop(dist_dir, p) for p in exe_files]
other_files = [chop(dist_dir, p) for p in other_files]
pathname = path.join(dist_dir, name + os.extsep + "iss")
# See http://www.jrsoftware.org/isfaq.php for more InnoSetup config options.
ofi = open(pathname, "w")
print >> ofi, r'''; WARNING: This script has been created by py2exe. Changes to this script
; will be overwritten the next time py2exe is run!
[Languages]
Name: "en"; MessagesFile: "compiler:Default.isl"
Name: "eu"; MessagesFile: "compiler:Languages\Basque.isl"
Name: "ca"; MessagesFile: "compiler:Languages\Catalan.isl"
Name: "cz"; MessagesFile: "compiler:Languages\Czech.isl"
Name: "da"; MessagesFile: "compiler:Languages\Danish.isl"
Name: "nl"; MessagesFile: "compiler:Languages\Dutch.isl"
Name: "fi"; MessagesFile: "compiler:Languages\Finnish.isl"
Name: "fr"; MessagesFile: "compiler:Languages\French.isl"
Name: "de"; MessagesFile: "compiler:Languages\German.isl"
Name: "he"; MessagesFile: "compiler:Languages\Hebrew.isl"
Name: "hu"; MessagesFile: "compiler:Languages\Hungarian.isl"
Name: "it"; MessagesFile: "compiler:Languages\Italian.isl"
Name: "nb"; MessagesFile: "compiler:Languages\Norwegian.isl"
Name: "pl"; MessagesFile: "compiler:Languages\Polish.isl"
Name: "pt_BR"; MessagesFile: "compiler:Languages\BrazilianPortuguese.isl"
Name: "pt"; MessagesFile: "compiler:Languages\Portuguese.isl"
Name: "ru"; MessagesFile: "compiler:Languages\Russian.isl"
Name: "sk"; MessagesFile: "compiler:Languages\Slovak.isl"
Name: "sl"; MessagesFile: "compiler:Languages\Slovenian.isl"
Name: "es"; MessagesFile: "compiler:Languages\Spanish.isl"
[Setup]
AppName=%(name)s
AppVerName=%(name)s %(version)s
AppPublisher=Zuza Software Foundation
AppPublisherURL=http://www.translate.org.za/
AppVersion=%(version)s
AppSupportURL=http://translate.sourceforge.net/
;AppComments=
;AppCopyright=Copyright (C) 2007-2009 Zuza Software Foundation
DefaultDirName={pf}\%(name)s
DefaultGroupName=%(name)s
LanguageDetectionMethod=locale
OutputBaseFilename=%(name)s-%(version)s-setup
ChangesAssociations=yes
SetupIconFile=%(icon_path)s
;WizardSmallImageFile=compiler:images\WizModernSmallImage13.bmp
WizardImageFile=%(wizard_image)s
[Files]''' % {
'name': name,
'version': version,
'icon_path': path.join(TARGET_DATA_DIR, "icons", "virtaal.ico"),
'wizard_image': path.join(os.pardir, "devsupport", "virtaal_innosetup.bmp")
}
for fpath in exe_files + other_files:
print >> ofi, r'Source: "%s"; DestDir: "{app}\%s"; Flags: ignoreversion' % (fpath, os.path.dirname(fpath))
print >> ofi, r'''
[Icons]
Name: "{group}\%(name)s Translation Editor"; Filename: "{app}\virtaal.exe";
Name: "{group}\%(name)s (uninstall)"; Filename: "{uninstallexe}"''' % {'name': name}
# For now we don't worry about install scripts
# if install_scripts:
# print >> ofi, r"[Run]"
#
# for fpath in install_scripts:
# print >> ofi, r'Filename: "{app}\%s"; WorkingDir: "{app}"; Parameters: "-install"' % fpath
#
# print >> ofi
# print >> ofi, r"[UninstallRun]"
#
# for fpath in install_scripts:
# print >> ofi, r'Filename: "{app}\%s"; WorkingDir: "{app}"; Parameters: "-remove"' % fpath
# File associations. Note the directive "ChangesAssociations=yes" above
# that causes the installer to tell Explorer to refresh associations.
# This part might cause the created installer to need administrative
# privileges. An alternative might be to rather write to
# HKCU\Software\Classes, but this won't be system usable then. Didn't
# see a way to test and alter the behaviour.
# For each file type we should have something like this:
#
#;File extension:
#Root: HKCR; Subkey: ".po"; ValueType: string; ValueName: ""; ValueData: "virtaal_po"; Flags: uninsdeletevalue
#;Description of the file type
#Root: HKCR; Subkey: "virtaal_po"; ValueType: string; ValueName: ""; ValueData: "Gettext PO"; Flags: uninsdeletekey
#;Icon to use in Explorer
#Root: HKCR; Subkey: "virtaal_po\DefaultIcon"; ValueType: string; ValueName: ""; ValueData: "{app}\share\icons\virtaal.ico"
#;The command to open the file
#Root: HKCR; Subkey: "virtaal_po\shell\open\command"; ValueType: string; ValueName: ""; ValueData: """{app}\virtaal.exe"" ""%1"""
print >> ofi, "[Registry]"
from translate.storage import factory
for description, extentions, _mimetypes in factory.supported_files():
# We skip those types where we depend on mime types, not extentions
if not extentions:
continue
# Form a key from the first extention for internal only
key = extentions[0]
# Associate each extention with the file type
for extention in extentions:
# We don't want to associate with all .txt or .pot (PowerPoint template) files, so let's skip it
if extention in ["txt", "pot", "csv"]:
continue
print >> ofi, r'Root: HKCR; Subkey: ".%(extention)s"; ValueType: string; ValueName: ""; ValueData: "virtaal_%(key)s"; Flags: uninsdeletevalue' % {'extention': extention, 'key': key}
print >> ofi, r'''Root: HKCR; Subkey: "virtaal_%(key)s"; ValueType: string; ValueName: ""; ValueData: "%(description)s"; Flags: uninsdeletekey
Root: HKCR; Subkey: "virtaal_%(key)s\DefaultIcon"; ValueType: string; ValueName: ""; ValueData: "{app}\share\icons\x-translation.ico"
Root: HKCR; Subkey: "virtaal_%(key)s\shell\open\command"; ValueType: string; ValueName: ""; ValueData: """{app}\virtaal.exe"" ""%%1"""''' % {'key': key, 'description': description}
# Show a "Launch Virtaal" checkbox on the last installer screen
print >> ofi, r'''
[Run]
Filename: "{app}\virtaal.exe"; Description: "{cm:LaunchProgram,%(name)s}"; Flags: nowait postinstall skipifsilent''' % {'name': name}
print >> ofi
ofi.close()
return pathname
def compile_inno_script(script_path):
"""compiles the script using InnoSetup"""
shell_compile_command = get_compile_command()
compile_command = shell_compile_command.replace('"%1"', script_path)
result = os.system(compile_command)
if result:
print "Error compiling iss file"
print "Opening iss file, use InnoSetup GUI to compile manually"
os.startfile(script_path)
class BuildWin32Installer(build_exe):
"""distutils class that first builds the exe file(s), then creates a Windows installer using InnoSetup"""
description = "create an executable installer for MS Windows using InnoSetup and py2exe"
user_options = getattr(build_exe, 'user_options', []) + \
[('install-script=', None,
"basename of installation script to be run after installation or before deinstallation")]
def initialize_options(self):
build_exe.initialize_options(self)
def run(self):
# First, let py2exe do it's work.
build_exe.run(self)
# create the Installer, using the files py2exe has created.
exe_files = self.windows_exe_files + self.console_exe_files
print "*** creating the inno setup script***"
script_path = create_inno_script(PRETTY_NAME, self.lib_dir, self.dist_dir, exe_files, self.lib_files,
version=self.distribution.metadata.version)
print "*** compiling the inno setup script***"
compile_inno_script(script_path)
# Note: By default the final setup.exe will be in an Output subdirectory.
def find_gtk_bin_directory():
GTK_NAME = "libgtk"
# Look for GTK in the user's Path as well as in some familiar locations
paths = os.environ['Path'].split(';') + [r'C:\GTK\bin', r'C:\Program Files\GTK\bin' r'C:\Program Files\GTK2-Runtime']
for p in paths:
if not os.path.exists(p):
continue
files = [path.join(p, f) for f in os.listdir(p) if path.isfile(path.join(p, f)) and f.startswith(GTK_NAME)]
if len(files) > 0:
return p
raise Exception("""Could not find the GTK runtime.
Please place bin directory of your GTK installation in the program path.""")
def find_gtk_files():
def parent(dir_path):
return path.abspath(path.join(path.abspath(dir_path), '..'))
def strip_leading_path(leadingPath, p):
return p[len(leadingPath) + 1:]
def wanted(data_file):
"""We don't want all the GTK files for the installer. Let's strip out a
few ones that are taking too much space."""
name = os.path.basename(data_file)
if name in no_package_names_dict:
return False
_base, ext = os.path.splitext(name)
if ext in no_package_extensions_dict:
return False
return True
#file names that we don't want
no_package_names = [
#We want some .mo files, but we won't use these ones
'libiconv.mo',
'iso_15924.mo',
'iso_3166_2.mo',
'iso_4217.mo',
'iso_639_3.mo',
'gtk20-properties.mo',
'gtkspell.mo', # This isn't picked up, so our code does the i18n
'gettext-tools.mo',
'gettext-runtime.mo',
'gtkspell.mo',
]
#extensions of files we don't want
no_package_extensions = [
'.log',
'.m4',
#package config
'.pc',
#man pages
'.1',
'.3',
'.5',
#source code
'.h',
'.c',
'.tcl',
#library files
'.a',
'.def',
'.lib',
#emacs files
'.el',
'.elc',
]
#Let's make some dictionaries so that we are not too slow
no_package_names_dict = {}
no_package_extensions_dict = {}
for name in no_package_names:
no_package_names_dict[name] = None
for extension in no_package_extensions:
no_package_extensions_dict[extension] = None
data_files = []
gtk_path = parent(find_gtk_bin_directory())
for dir_path in [path.join(gtk_path, p) for p in ('etc', 'share', 'lib')]:
for dir_name, _, files in os.walk(dir_path):
files = [path.abspath(path.join(dir_name, f)) for f in files if wanted(f)]
if len(files) > 0:
data_files.append((strip_leading_path(gtk_path, dir_name), files))
return data_files
def find_enchant_files():
data_files = []
import enchant
en = enchant.Dict('en')
# This should give us something like
# C:\Python25\Lib\site-packages\enchant\lib\enchant\libenchant_myspell.dll
data_files.append(('lib/enchant', [en.provider.file]))
# Our version of gtkspell expects libenchant.dll, but enchant itselfs needs
# libenchant-1.dll
libenchant = enchant.utils.get_resource_filename("libenchant.dll")
libenchant1 = enchant.utils.get_resource_filename("libenchant-1.dll")
data_files.append(('',[libenchant, libenchant1]))
return data_files
def find_langmodel_files():
from translate.misc.file_discovery import get_abs_data_filename
lmdir = path.abspath(get_abs_data_filename('langmodels'))
if not path.isdir(lmdir):
return []
return [(path.join(TARGET_DATA_DIR, 'langmodels'), glob(path.join(lmdir, '*.*')))]
def add_win32_options(options):
"""This function is responsible for finding data files and setting options necessary
to build executables and installers under Windows.
@return: A 2-tuple (data_files, options), where data_files is a list of Windows
specific data files (this would include the GTK binaries) and where
options are the options required by py2exe."""
if py2exe != None and ('py2exe' in sys.argv or 'innosetup' in sys.argv):
options['data_files'].extend(find_gtk_files())
options['data_files'].extend(find_enchant_files())
options['data_files'].extend(find_langmodel_files())
options['data_files'].extend([(
path.join(TARGET_DATA_DIR, "icons", "hicolor", "24x24", "mimetypes"),
[path.join(SOURCE_DATA_DIR, "icons", "hicolor", "24x24", "mimetypes", "x-translation.png")]
)])
#This depends on setup.py being run from a checkout with the translate
#toolkit in place.
options['scripts'].append("../translate/services/tmserver")
py2exe_options = {
# translate.lang and translate.storage contain classes that are
# imported dynamically, therefore we need to add them here,
# otherwise py2exe doesn't find them.
"packages": ["encodings", "translate.lang", "translate.storage._factory_classes", "virtaal"],
"compressed": True,
"excludes": ["PyLucene", "Tkconstants", "Tkinter", "tcl",
# strange things unnecessarily included with some versions of pyenchant:
"win32ui", "_win32sysloader", "win32pipe", "py2exe", "pywin", "isapi", "_tkinter", "win32api",
],
"dist_dir": "virtaal-win32",
"includes": [
# some of these are needed by plugins and are therefore not detected
"lxml", "lxml._elementpath", "psyco", "cairo", "pango",
"pangocairo", "atk", "gobject", "gtk.keysyms",
"gtkspell",
"tarfile",
"translate.storage.placeables.terminology", # terminology
"xmlrpclib", # Moses
],
"optimize": 2,
}
py2exe_options['includes'] += ["bsddb", "zipfile"] # Dependencies for the migration and auto-correction plug-ins, respectively.
innosetup_options = py2exe_options.copy()
options.update({
"windows": [
{
'script': 'bin/virtaal',
'icon_resources': [(1, path.join(SOURCE_DATA_DIR, "icons", "virtaal.ico"))],
},
{ 'script': "../translate/services/tmserver"}
],
'zipfile': "virtaal.zip",
"options": {
"py2exe": py2exe_options,
"innosetup": innosetup_options
},
'cmdclass': {
"py2exe": build_exe,
"innosetup": BuildWin32Installer
}
})
return options
def add_mac_options(options):
# http://svn.pythonmac.org/py2app/py2app/trunk/doc/index.html#tweaking-your-info-plist
# http://developer.apple.com/documentation/MacOSX/Conceptual/BPRuntimeConfig/Articles/PListKeys.html
if py2app is None:
return options
options['data_files'].extend([('share/OSX_Leopard_theme', glob(path.join('devsupport', 'OSX_Leopard_theme', '*')))])
options['data_files'].extend([('', ['devsupport/virtaal.icns'])])
# For some reason py2app can't handle bin/virtaal since it doesn't end in .py
import shutil
shutil.copy2('bin/virtaal', 'bin/run_virtaal.py')
from translate.storage import factory
options.update({
"app": ["bin/run_virtaal.py"],
"options": {
"py2app": {
"packages": ["CoreFoundation", "objc"],
"includes": ["lxml", "lxml._elementpath", "lxml.etree", "glib", "gio", "psyco", "cairo", "pango", "pangocairo", "atk", "gobject", "gtk.keysyms", "pycurl", "translate.services", "translate.services.tmclient", "translate.services.opentranclient", "CoreFoundation"],
#"semi_standalone": True,
"compressed": True,
"argv_emulation": True,
"plist": {
"CFBundleGetInfoString": virtaal_description,
"CFBundleName": PRETTY_NAME,
"CFBundleIconFile": "virtaal.icns",
"CFBundleShortVersionString": virtaal_version,
#"LSHasLocalizedDisplayName": "1",
#"LSMinimumSystemVersion": ???,
"NSHumanReadableCopyright": "Copyright (C) 2007-2009 Zuza Software Foundation",
"CFBundleDocumentTypes": [{
"CFBundleTypeExtensions": [extention.lstrip("*.") for extention in extentions],
"CFBundleTypeIconFile": "virtaal.icns",
"CFBundleTypeMIMETypes": mimetypes,
"CFBundleTypeName": description, #????
} for description, extentions, mimetypes in factory.supported_files()]
}
}
}})
return options
def add_freedesktop_options(options):
options['data_files'].extend([
(path.join(TARGET_DATA_DIR, "mime", "packages"), glob(path.join(SOURCE_DATA_DIR, "mime", "packages", "*.xml"))),
(path.join(TARGET_DATA_DIR, "applications"), glob(path.join(SOURCE_DATA_DIR, "applications", "*.desktop"))),
])
for dir in ("16x16", "24x24", "32x32", "48x48", "64x64", "128x128", "scalable"):
options['data_files'].extend([
(path.join(TARGET_DATA_DIR, "icons", "hicolor", dir, "mimetypes"),
glob(path.join(SOURCE_DATA_DIR, "icons", "hicolor", dir, "mimetypes", "*.*"))),
])
return options
#############################
# General functions
def add_platform_specific_options(options):
if sys.platform == 'win32':
return add_win32_options(options)
if sys.platform == 'darwin':
return add_mac_options(options)
return add_freedesktop_options(options)
def create_manifest(data_files, extra_files, extra_dirs):
f = open('MANIFEST.in', 'w+')
f.write("# informational files")
for infofile in ("README", "TODO", "ChangeLog", "COPYING", "LICENSE", "*.txt"):
f.write("global-include %s\n" % infofile)
for data_file_list in [d[1] for d in data_files] + extra_files:
if not data_file_list:
continue
f.write("include %s\n" % (" ".join( data_file_list )))
for dir in extra_dirs:
f.write("graft %s\n" % (dir))
f.close()
import distutils.command.install
class DepCheckInstall(distutils.command.install.install):
user_options = distutils.command.install.install.user_options + [
('nodepcheck', None, "don't check dependencies"),
]
def initialize_options(self):
distutils.command.install.install.initialize_options(self)
self.nodepcheck = False
def run(self, *args, **kwargs):
if not self.nodepcheck:
from virtaal.support import depcheck
failed = depcheck.check_dependencies()
if failed:
print 'Failed dependencies: %s' % (', '.join(failed))
print 'Use the --nodepcheck option to ignore dependencies.'
exit(1)
distutils.command.install.install.run(self, *args, **kwargs)
def main(options):
options = add_platform_specific_options(options)
if not 'cmdclass' in options:
options['cmdclass'] = {}
options['cmdclass']['install'] = DepCheckInstall
create_manifest(options['data_files'], no_install_files, no_install_dirs)
setup(name="virtaal",
version=virtaal_version,
license="GNU General Public License (GPL)",
description=virtaal_description,
long_description="""Virtaal is used to create program translations.
It uses the Translate Toolkit to get access to translation files and therefore
can edit a variety of files (including PO and XLIFF files).""",
author="Translate.org.za",
author_email="translate-devel@lists.sourceforge.net",
url="http://translate.sourceforge.net/wiki/virtaal/index",
download_url="http://sourceforge.net/project/showfiles.php?group_id=91920&package_id=270877",
platforms=["any"],
classifiers=classifiers,
**options)
if __name__ == '__main__':
main(options)
# For some reason, Resources/lib/python2.5/lib-dynload is not in the Python
# path. We need to get it in, therefore this hack.
if sys.platform == 'darwin':
f = open('dist/virtaal.app/Contents/Resources/__boot__.py', "r+")
s = f.read()
f.truncate(0)
s = s.replace("base = os.environ['RESOURCEPATH']", r"""
base = os.environ['RESOURCEPATH']
sys.path = [os.path.join(base, "lib", "python2.5", "lib-dynload")] + sys.path
sys.path = [os.path.join(base, "lib", "python2.5")] + sys.path
""")
f.seek(0)
f.write(s)
f.close()
# hdiutil create -imagekey zlib-level=9 -srcfolder dist/virtaal.app dist/virtaal.dmg
# hdiutil create -fs HFS+ -volname "RUR-PLE" -srcfolder dist dist_mac/RUR-PLE.dmg
|