16 |
# |
# |
17 |
|
|
18 |
import os |
import os |
19 |
|
from types import TupleType |
20 |
from distutils.core import setup, Extension, Command |
from distutils.core import setup, Extension, Command |
21 |
from distutils.command.install import install |
from distutils.command.install import install |
22 |
from distutils.command.build_py import build_py |
from distutils.command.build_py import build_py |
23 |
|
from distutils.file_util import write_file |
24 |
|
from distutils.util import convert_path |
25 |
|
|
26 |
import distutils |
import distutils |
|
print distutils.__file__ |
|
27 |
|
|
28 |
from string import split |
from string import split |
29 |
import string |
import string |
68 |
proj4_libdir = proj4_prefix |
proj4_libdir = proj4_prefix |
69 |
proj4_lib = "proj_i" |
proj4_lib = "proj_i" |
70 |
|
|
71 |
|
# Define include and lib directories for wxWindows and |
72 |
|
wx_prefix = r"D:\wx230" |
73 |
|
wx_inc = os.path.join(wx_prefix, "include") |
74 |
|
wx_lib = os.path.join(wx_prefix, "lib") |
75 |
|
|
76 |
# |
# |
77 |
# Unless you use a wxPython version other than 2.3.1, you probably |
# Unless you use a wxPython version other than 2.3.1, you probably |
78 |
# shouldn't have to modify anything below here |
# shouldn't have to modify anything below here |
90 |
# there's no config script. |
# there's no config script. |
91 |
wx_config_script = "" |
wx_config_script = "" |
92 |
|
|
|
# so we just define the flags manually |
|
|
wx_prefix = r"D:\wx230" |
|
|
wx_inc = os.path.join(wx_prefix, "include") |
|
|
wx_lib = os.path.join(wx_prefix, "lib") |
|
93 |
# the values of wx_defs and wx_libs. copied from the wxPython |
# the values of wx_defs and wx_libs. copied from the wxPython |
94 |
# setup.py |
# setup.py |
95 |
wx_defs = [ ('WIN32', None), # Some of these are no longer |
wx_defs = [ ('WIN32', None), # Some of these are no longer |
235 |
data_files = [] |
data_files = [] |
236 |
|
|
237 |
# bitmaps |
# bitmaps |
238 |
dir = "Resources/Bitmaps/" |
dir = "Resources/Bitmaps" |
239 |
bitmaps = [] |
bitmaps = [] |
240 |
for file in os.listdir(os.path.join("Resources", "Bitmaps")): |
for file in os.listdir(os.path.join("Resources", "Bitmaps")): |
241 |
if string.lower(file[-4:]) == ".xpm": |
if string.lower(file[-4:]) == ".xpm": |
242 |
bitmaps.append(dir + file) |
bitmaps.append(dir + '/' + file) |
243 |
data_files.append((dir, bitmaps)) |
data_files.append((dir, bitmaps)) |
244 |
|
|
245 |
# |
# |
262 |
"Create some symlink so you can run thubanfrom the source directory" |
"Create some symlink so you can run thubanfrom the source directory" |
263 |
|
|
264 |
user_options = [ |
user_options = [ |
|
('debug', 'g', "compile/link with debugging information"), |
|
265 |
('skip-build', None, "skip the build steps"), |
('skip-build', None, "skip the build steps"), |
266 |
] |
] |
267 |
|
|
269 |
self.extensions = None |
self.extensions = None |
270 |
self.build_dir = None |
self.build_dir = None |
271 |
self.skip_build = None |
self.skip_build = None |
|
self.debug = None |
|
272 |
|
|
273 |
def finalize_options (self): |
def finalize_options (self): |
274 |
self.set_undefined_options("install", |
self.set_undefined_options("install", |
291 |
def link_dir(self, src, dest): |
def link_dir(self, src, dest): |
292 |
"""Create a symbolic link dest pointing to src""" |
"""Create a symbolic link dest pointing to src""" |
293 |
if self.verbose: |
if self.verbose: |
294 |
print "symlinking %s -> %s" % (src, dest) |
self.announce("symlinking %s -> %s" % (src, dest)) |
295 |
if self.dry_run: |
if self.dry_run: |
296 |
return |
return |
297 |
|
|
310 |
class thuban_build_py(build_py): |
class thuban_build_py(build_py): |
311 |
|
|
312 |
""" |
""" |
313 |
A new build_py that can deal with both packages and modules in |
A new build_py that can deal with both packages and modules in one |
314 |
one distribution. |
distribution. |
315 |
""" |
""" |
316 |
|
|
317 |
def run(self): |
def run(self): |
318 |
"""The same the as teh original in build_py revision 1.33 except |
"""The same the as the original in build_py revision 1.33 except |
319 |
that this allows both packages and modules to be in one |
that this allows both packages and modules to be in one |
320 |
distribution |
distribution |
321 |
""" |
""" |
349 |
modules.append(("Lib", module_base, module_file)) |
modules.append(("Lib", module_base, module_file)) |
350 |
return modules |
return modules |
351 |
|
|
352 |
# |
def find_all_modules (self): |
353 |
# Extend the standard install command to symlink the installed script to |
# same as find_all_modules of the original build_py command |
354 |
# $prefix/bin/ |
# (rev. 1.33) but handle installations with both modules and |
355 |
# |
# packages. Needed here so tha the get_outputs works correctly |
356 |
|
modules = [] |
357 |
|
if self.py_modules: |
358 |
|
modules.extend(self.find_modules()) |
359 |
|
if self.packages: |
360 |
|
for package in self.packages: |
361 |
|
package_dir = self.get_package_dir(package) |
362 |
|
m = self.find_package_modules(package, package_dir) |
363 |
|
modules.extend(m) |
364 |
|
|
365 |
|
return modules |
366 |
|
|
367 |
|
|
368 |
|
|
369 |
class ThubanInstall(install): |
class ThubanInstall(install): |
370 |
|
|
371 |
|
""" |
372 |
|
Thuban specific install command. |
373 |
|
|
374 |
|
Extend the standard install command to symlink the installed script |
375 |
|
to $prefix/bin/ |
376 |
|
""" |
377 |
|
|
378 |
|
user_options = install.user_options[:] |
379 |
|
user_options.extend([("do-symlink", None, |
380 |
|
"Create a symlink to the script in <prefix>/bin." |
381 |
|
"(default on posix systems and only relevant there)"), |
382 |
|
|
383 |
|
("extra-files", None, |
384 |
|
"List of filenames or (src, dest) pairs describing " |
385 |
|
" extra files to install " |
386 |
|
"(can only be set from witin setup.py"), |
387 |
|
]) |
388 |
|
|
389 |
|
boolean_options = install.boolean_options[:] |
390 |
|
boolean_options.append("do-symlink") |
391 |
|
|
392 |
|
def initialize_options(self): |
393 |
|
self.do_symlink = None |
394 |
|
self.extra_files = [] |
395 |
|
install.initialize_options(self) |
396 |
|
|
397 |
|
def finalize_options(self): |
398 |
|
if self.do_symlink is None: |
399 |
|
if os.name == "posix": |
400 |
|
self.do_symlink = 1 |
401 |
|
else: |
402 |
|
self.do_symlink = 0 |
403 |
|
install.finalize_options(self) |
404 |
|
|
405 |
def run(self): |
def run(self): |
406 |
install.run(self) |
install.run(self) |
407 |
if os.name == "posix": |
for item in self.extra_files: |
408 |
|
if type(item) == TupleType: |
409 |
|
src, dest = item |
410 |
|
else: |
411 |
|
src = dest = item |
412 |
|
self.copy_file(convert_path(src), |
413 |
|
os.path.join(self.root, convert_path(dest))) |
414 |
|
|
415 |
|
if os.name == "posix" and self.do_symlink: |
416 |
scriptfile = os.path.join(self.install_scripts, "thuban.py") |
scriptfile = os.path.join(self.install_scripts, "thuban.py") |
417 |
bindir = os.path.join(self.prefix, "bin") |
bindir = os.path.join(self.prefix, "bin") |
418 |
binfile = os.path.join(bindir, "thuban") |
binfile = os.path.join(bindir, "thuban") |
419 |
self.mkpath(bindir) |
self.mkpath(bindir) |
420 |
self.copy_file(scriptfile, binfile, link="sym") |
self.copy_file(scriptfile, binfile, link="sym") |
421 |
|
|
422 |
|
def get_outputs (self): |
423 |
|
outputs = install.get_outputs(self) |
424 |
|
for item in self.extra_files: |
425 |
|
if type(item) == TupleType: |
426 |
|
src, dest = item |
427 |
|
else: |
428 |
|
src = dest = item |
429 |
|
outputs.append(os.path.join(self.root, convert_path(dest))) |
430 |
|
return outputs |
431 |
|
|
432 |
|
class bdist_inno(Command): |
433 |
|
|
434 |
|
"""Command to create a windows installer with Inno Setup""" |
435 |
|
|
436 |
|
description = "Create a windows installer with Inno Setup" |
437 |
|
|
438 |
|
user_options = [ |
439 |
|
('skip-build', None, "skip the build steps"), |
440 |
|
('bdist-dir=', None, |
441 |
|
"temporary directory for creating the distribution"), |
442 |
|
('run-inno', None, |
443 |
|
"Run inno-setup to create the installer. On by default on nt"), |
444 |
|
('iss-name', None, |
445 |
|
"The name of the iss file to generate. " |
446 |
|
"Shouldn't contain directories"), |
447 |
|
|
448 |
|
# Parameters for the Inno Setup script |
449 |
|
('copyright', None, "Copyright notice for the Inno Setup file"), |
450 |
|
('default-dir-name', None, |
451 |
|
"Default installation directory. Defaults to '{pf}\\<name>'"), |
452 |
|
('default-group-name', None, |
453 |
|
"Default program group name. Defaults to <name>'"), |
454 |
|
("license-file", None, "File containing the license."), |
455 |
|
("output-basename", None, |
456 |
|
"Base filename for the Inno Setup output " |
457 |
|
"(defaults to <name>-<version>-<issrevision>)."), |
458 |
|
("iss-revision", None, |
459 |
|
"revision of the generated installer of the package version"), |
460 |
|
|
461 |
|
("icons-entries", None, |
462 |
|
"List if InnoIconItems " |
463 |
|
"(this can only be set from inside the setup.py script)"), |
464 |
|
] |
465 |
|
|
466 |
|
boolean_options = ["do-symlink"] |
467 |
|
|
468 |
|
def initialize_options(self): |
469 |
|
self.skip_build = 0 |
470 |
|
self.bdist_dir = None |
471 |
|
self.run_inno = None |
472 |
|
self.iss_name = None |
473 |
|
self.copyright = "" |
474 |
|
self.default_dir_name = None |
475 |
|
self.default_group_name = None |
476 |
|
self.license_file = None |
477 |
|
self.output_basename = None |
478 |
|
self.iss_revision = None |
479 |
|
self.icons_entries = [] |
480 |
|
|
481 |
|
def finalize_options(self): |
482 |
|
self.set_undefined_options("install", |
483 |
|
('skip_build', 'skip_build')) |
484 |
|
if self.bdist_dir is None: |
485 |
|
bdist_base = self.get_finalized_command('bdist').bdist_base |
486 |
|
self.bdist_dir = os.path.join(bdist_base, 'inno') |
487 |
|
|
488 |
|
if self.run_inno is None: |
489 |
|
self.run_inno = os.name == "nt" |
490 |
|
|
491 |
|
name = self.distribution.get_name() |
492 |
|
if self.iss_name is None: |
493 |
|
self.iss_name = name + '.iss' |
494 |
|
|
495 |
|
if self.default_dir_name is None: |
496 |
|
self.default_dir_name = "{pf}\\" + name |
497 |
|
if self.default_group_name is None: |
498 |
|
self.default_group_name = name |
499 |
|
|
500 |
|
if self.iss_revision is None: |
501 |
|
self.iss_revision = 0 |
502 |
|
if self.output_basename is None: |
503 |
|
self.output_basename = "%s-%s-%d" \ |
504 |
|
% (name, self.distribution.get_version(), |
505 |
|
self.iss_revision) |
506 |
|
|
507 |
|
def run(self, install_options = None): |
508 |
|
"""Execute the command. install_options if given, should be a |
509 |
|
directory of additional options to set in the install step""" |
510 |
|
# Obviously have to build before we can install |
511 |
|
if not self.skip_build: |
512 |
|
self.run_command('build') |
513 |
|
|
514 |
|
# Install in a temporary directory |
515 |
|
install = self.reinitialize_command('install') |
516 |
|
install.root = self.bdist_dir |
517 |
|
if install_options is not None: |
518 |
|
for key, value in install_options.items(): |
519 |
|
setattr(install, key, value) |
520 |
|
if os.name != 'nt': |
521 |
|
# Must force install to use the 'nt' scheme; |
522 |
|
install.select_scheme('nt') |
523 |
|
# don't make a symlink because we're simulating windows, so |
524 |
|
# that we can generate the iss-file even on Linux |
525 |
|
install.do_symlink = 0 |
526 |
|
|
527 |
|
self.announce("installing to %s" % self.bdist_dir) |
528 |
|
install.ensure_finalized() |
529 |
|
install.run() |
530 |
|
|
531 |
|
# Create the iss file |
532 |
|
iss_file = os.path.join(self.bdist_dir, self.iss_name) |
533 |
|
self.execute(write_file, (iss_file, self.generate_iss()), |
534 |
|
"Create Inno Setup script file %s" % iss_file) |
535 |
|
|
536 |
|
# and invoke |
537 |
|
if self.run_inno: |
538 |
|
self.spawn(["iscc", iss_file]) |
539 |
|
|
540 |
|
def generate_iss(self): |
541 |
|
"""Return the contents of the iss file as list of strings, one |
542 |
|
string per line""" |
543 |
|
|
544 |
|
# first, turn the icons entries into a more usable form |
545 |
|
icons = {} |
546 |
|
for item in self.icons_entries: |
547 |
|
icons[item.filename] = item |
548 |
|
|
549 |
|
iss = [] |
550 |
|
|
551 |
|
name = self.distribution.get_name() |
552 |
|
iss.extend(["[Setup]", |
553 |
|
"AppName=" + name, |
554 |
|
"AppVerName=" + name + " "+self.distribution.get_version(), |
555 |
|
"DefaultDirName=" + self.default_dir_name, |
556 |
|
"DefaultGroupName=" + self.default_group_name, |
557 |
|
]) |
558 |
|
if self.copyright: |
559 |
|
iss.append("AppCopyright=" + self.copyright) |
560 |
|
if self.license_file: |
561 |
|
iss.append("LicenseFile=" + self.license_file) |
562 |
|
|
563 |
|
iss.append("OutputBasefilename=" + self.output_basename) |
564 |
|
|
565 |
|
iss.append("") |
566 |
|
iss.append("[Files]") |
567 |
|
|
568 |
|
install = self.get_finalized_command("install") |
569 |
|
install_scripts = self.get_finalized_command("install_scripts") |
570 |
|
script_files = install_scripts.get_outputs() |
571 |
|
prefixlen = len(self.bdist_dir) + len(os.sep) |
572 |
|
for filename in install.get_outputs(): |
573 |
|
filename = filename[prefixlen:] |
574 |
|
icon = icons.get(filename) |
575 |
|
dirname = os.path.dirname(filename) |
576 |
|
if os.name != "nt": |
577 |
|
# change the separators to \ on non-windos systems |
578 |
|
filename = string.join(string.split(filename, os.sep), "\\") |
579 |
|
dirname = string.join(string.split(dirname, os.sep), "\\") |
580 |
|
line = 'Source: "%s"' % filename |
581 |
|
if icon is not None: |
582 |
|
# install it as defined in the icon object |
583 |
|
backslash = string.rfind(icon.install_name, "\\") |
584 |
|
if backslash >= 0: |
585 |
|
dirname = icon.install_name[:backslash] |
586 |
|
basename = icon.install_name[backslash + 1:] |
587 |
|
else: |
588 |
|
dirname = "" |
589 |
|
basename = icon.install_name |
590 |
|
line = '%s; DestDir: "%s"; DestName: "%s"' % (line, dirname, |
591 |
|
basename) |
592 |
|
else: |
593 |
|
line = line + '; DestDir: "{app}\\%s"' % (dirname) |
594 |
|
iss.append(line) |
595 |
|
|
596 |
|
iss.append("") |
597 |
|
iss.append("[Icons]") |
598 |
|
for icon in self.icons_entries: |
599 |
|
line = 'Name: "{group}\\%s"; Filename: "%s";' \ |
600 |
|
% (icon.title, icon.install_name) |
601 |
|
iss.append(line) |
602 |
|
|
603 |
|
return iss |
604 |
|
|
605 |
|
|
606 |
|
class InnoIconItem: |
607 |
|
|
608 |
|
"""Describe one item for he start menu for the Inno Setup installer""" |
609 |
|
|
610 |
|
def __init__(self, filename, title, install_name = None): |
611 |
|
self.filename = filename |
612 |
|
self.title = title |
613 |
|
if install_name is not None: |
614 |
|
self.install_name = install_name |
615 |
|
else: |
616 |
|
self.install_name = filename |
617 |
|
|
618 |
|
|
619 |
|
class thuban_bdist_inno(bdist_inno): |
620 |
|
|
621 |
|
"""Thuban specific Inno Setup stuff""" |
622 |
|
|
623 |
|
def run(self): |
624 |
|
install_options = { |
625 |
|
"prefix": ".", |
626 |
|
"install_scripts": "$base", |
627 |
|
"warn_dir": 0, |
628 |
|
"extra_files": ["COPYING", "Lib/proj.dll"], |
629 |
|
} |
630 |
|
bdist_inno.run(self, install_options) |
631 |
|
|
632 |
|
|
633 |
|
# |
634 |
|
# Run the script |
635 |
|
# |
636 |
|
|
637 |
|
|
638 |
long_description = """\ |
long_description = """\ |
639 |
Thuban is a viewer for geographic data written in Python |
Thuban is a viewer for geographic data written in Python |
640 |
""" |
""" |
641 |
|
|
642 |
setup(name = "thuban", |
setup(name = "Thuban", |
643 |
version = "0.0.3", |
version = "0.0.3", |
644 |
description = "Geographic data viewer", |
description = "Geographic data viewer", |
645 |
long_description = long_description, |
long_description = long_description, |
662 |
# same directory. |
# same directory. |
663 |
"install_lib": "$base/thuban", |
"install_lib": "$base/thuban", |
664 |
"install_scripts": "$base/thuban", |
"install_scripts": "$base/thuban", |
665 |
"install_data": "$base/thuban/", |
"install_data": "$base/thuban", |
666 |
|
|
667 |
# Don't print warning messages about the lib dir not |
# Don't print warning messages about the lib dir not |
668 |
# being on Python's path. The libraries are Thuban |
# being on Python's path. The libraries are Thuban |
669 |
# specific and are installed just for Thuban. They'll |
# specific and are installed just for Thuban. They'll |
670 |
# be automatically on Python's path when Thuban is run |
# be automatically on Python's path when Thuban is run |
671 |
"warn_dir": 0, |
"warn_dir": 0, |
672 |
}}, |
}, |
673 |
|
"bdist_inno": |
674 |
|
{"icons_entries": [InnoIconItem(".\\thuban.py", |
675 |
|
"Start Thuban", |
676 |
|
"{app}\\thuban.pyw")], |
677 |
|
"license_file": "COPYING", |
678 |
|
} |
679 |
|
}, |
680 |
cmdclass = {"build_py": thuban_build_py, |
cmdclass = {"build_py": thuban_build_py, |
681 |
"install_local": InstallLocal, |
"install_local": InstallLocal, |
682 |
"install": ThubanInstall}) |
"install": ThubanInstall, |
683 |
|
"bdist_inno": thuban_bdist_inno |
684 |
|
}) |
685 |
|
|
686 |
|
|