/[thuban]/branches/WIP-pyshapelib-bramz/setup.py
ViewVC logotype

Diff of /branches/WIP-pyshapelib-bramz/setup.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 8 by bh, Tue Aug 28 16:48:50 2001 UTC revision 18 by bh, Mon Sep 3 16:25:09 2001 UTC
# Line 16  __version__ = "$Revision$" Line 16  __version__ = "$Revision$"
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, change_root
25    
26  import distutils  import distutils
 print distutils.__file__  
27    
28  from string import split  from string import split
29  import string  import string
# Line 66  elif os.name == "nt": Line 68  elif os.name == "nt":
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
# Line 83  elif os.name == "nt": Line 90  elif os.name == "nt":
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
# Line 232  py_modules.append(ext_dir + "/pyprojecti Line 235  py_modules.append(ext_dir + "/pyprojecti
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  #  #
# Line 259  class InstallLocal(Command): Line 262  class InstallLocal(Command):
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    
# Line 267  class InstallLocal(Command): Line 269  class InstallLocal(Command):
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",
# Line 290  class InstallLocal(Command): Line 291  class InstallLocal(Command):
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    
# Line 348  class thuban_build_py(build_py): Line 349  class thuban_build_py(build_py):
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            # same as find_all_modules of the original build_py command
354            # (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    
# Line 357  class ThubanInstall(install): Line 374  class ThubanInstall(install):
374      Extend the standard install command to symlink the installed script      Extend the standard install command to symlink the installed script
375      to $prefix/bin/      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                if self.root:
419                    bindir = change_root(self.root, bindir)
420              binfile = os.path.join(bindir, "thuban")              binfile = os.path.join(bindir, "thuban")
421              self.mkpath(bindir)              self.mkpath(bindir)
422              self.copy_file(scriptfile, binfile, link="sym")              self.copy_file(scriptfile, binfile, link="sym")
423    
424        def get_outputs (self):
425            outputs = install.get_outputs(self)
426            for item in self.extra_files:
427                if type(item) == TupleType:
428                    src, dest = item
429                else:
430                    src = dest = item
431                outputs.append(os.path.join(self.root, convert_path(dest)))
432            return outputs
433    
434    class bdist_inno(Command):
435    
436        """Command to create a windows installer with Inno Setup"""
437    
438        description = "Create a windows installer with Inno Setup"
439    
440        user_options = [
441            ('skip-build', None, "skip the build steps"),
442            ('bdist-dir=', None,
443             "temporary directory for creating the distribution"),
444            ('run-inno', None,
445             "Run inno-setup to create the installer. On by default on nt"),
446            ('iss-name', None,
447             "The name of the iss file to generate. "
448             "Shouldn't contain directories"),
449    
450            # Parameters for the Inno Setup script
451            ('copyright', None, "Copyright notice for the Inno Setup file"),
452            ('default-dir-name', None,
453             "Default installation directory. Defaults to '{pf}\\<name>'"),
454            ('default-group-name', None,
455             "Default program group name. Defaults to <name>'"),
456            ("license-file", None, "File containing the license."),
457            ("output-basename", None,
458             "Base filename for the Inno Setup output "
459             "(defaults to <name>-<version>-<issrevision>)."),
460            ("iss-revision", None,
461             "revision of the generated installer of the package version"),
462    
463            ("icons-entries", None,
464             "List if InnoIconItems "
465             "(this can only be set from inside the setup.py script)"),
466            ]
467    
468        boolean_options = ["do-symlink"]
469    
470        def initialize_options(self):
471            self.skip_build = 0
472            self.bdist_dir = None
473            self.run_inno = None
474            self.iss_name = None
475            self.copyright = ""
476            self.default_dir_name = None
477            self.default_group_name = None
478            self.license_file = None
479            self.output_basename = None
480            self.iss_revision = None
481            self.icons_entries = []
482    
483        def finalize_options(self):
484            self.set_undefined_options("install",
485                                       ('skip_build', 'skip_build'))
486            if self.bdist_dir is None:
487                bdist_base = self.get_finalized_command('bdist').bdist_base
488                self.bdist_dir = os.path.join(bdist_base, 'inno')
489    
490            if self.run_inno is None:
491                self.run_inno = os.name == "nt"
492    
493            name = self.distribution.get_name()
494            if self.iss_name is None:
495                self.iss_name = name + '.iss'
496    
497            if self.default_dir_name is None:
498                self.default_dir_name = "{pf}\\" + name
499            if self.default_group_name is None:
500                self.default_group_name = name
501    
502            if self.iss_revision is None:
503                self.iss_revision = 0
504            if self.output_basename is None:
505                self.output_basename = "%s-%s-%d" \
506                                       % (name, self.distribution.get_version(),
507                                          self.iss_revision)
508    
509        def run(self, install_options = None):
510            """Execute the command. install_options if given, should be a
511            directory of additional options to set in the install step"""
512            # Obviously have to build before we can install
513            if not self.skip_build:
514                self.run_command('build')
515    
516            # Install in a temporary directory
517            install = self.reinitialize_command('install')
518            install.root = self.bdist_dir
519            if install_options is not None:
520                for key, value in install_options.items():
521                    setattr(install, key, value)
522            if os.name != 'nt':
523                # Must force install to use the 'nt' scheme;
524                install.select_scheme('nt')
525                # don't make a symlink because we're simulating windows, so
526                # that we can generate the iss-file even on Linux
527                install.do_symlink = 0
528    
529            self.announce("installing to %s" % self.bdist_dir)
530            install.ensure_finalized()
531            install.run()
532    
533            # Create the iss file
534            iss_file = os.path.join(self.bdist_dir, self.iss_name)
535            self.execute(write_file, (iss_file, self.generate_iss()),
536                         "Create Inno Setup script file %s" % iss_file)
537    
538            # and invoke
539            if self.run_inno:
540                self.spawn(["iscc", iss_file])
541    
542        def generate_iss(self):
543            """Return the contents of the iss file as list of strings, one
544            string per line"""
545    
546            # first, turn the icons entries into a more usable form
547            icons = {}
548            for item in self.icons_entries:
549                icons[item.filename] = item
550    
551            iss = []
552    
553            name = self.distribution.get_name()
554            iss.extend(["[Setup]",
555                        "AppName=" + name,
556                        "AppVerName=" + name + " "+self.distribution.get_version(),
557                        "DefaultDirName=" + self.default_dir_name,
558                        "DefaultGroupName=" + self.default_group_name,
559                        ])
560            if self.copyright:
561                iss.append("AppCopyright=" + self.copyright)
562            if self.license_file:
563                iss.append("LicenseFile=" + self.license_file)
564    
565            iss.append("OutputBasefilename=" + self.output_basename)
566    
567            iss.append("")
568            iss.append("[Files]")
569    
570            install = self.get_finalized_command("install")
571            install_scripts = self.get_finalized_command("install_scripts")
572            script_files = install_scripts.get_outputs()
573            prefixlen = len(self.bdist_dir) + len(os.sep)
574            for filename in install.get_outputs():
575                filename = filename[prefixlen:]
576                icon = icons.get(filename)
577                dirname = os.path.dirname(filename)
578                if os.name != "nt":
579                    # change the separators to \ on non-windos systems
580                    filename = string.join(string.split(filename, os.sep), "\\")
581                    dirname =  string.join(string.split(dirname, os.sep), "\\")
582                line = 'Source: "%s"' % filename
583                if icon is not None:
584                    # install it as defined in the icon object
585                    backslash = string.rfind(icon.install_name, "\\")
586                    if backslash >= 0:
587                        dirname = icon.install_name[:backslash]
588                        basename = icon.install_name[backslash + 1:]
589                    else:
590                        dirname = ""
591                        basename = icon.install_name
592                    line = '%s; DestDir: "%s"; DestName: "%s"' % (line, dirname,
593                                                                  basename)
594                else:
595                    line = line + '; DestDir: "{app}\\%s"' % (dirname)
596                iss.append(line)
597    
598            iss.append("")
599            iss.append("[Icons]")
600            for icon in self.icons_entries:
601                line = 'Name: "{group}\\%s"; Filename: "%s";' \
602                       % (icon.title, icon.install_name)
603                iss.append(line)
604                
605            return iss
606    
607    
608    class InnoIconItem:
609    
610        """Describe one item for he start menu for the Inno Setup installer"""
611    
612        def __init__(self, filename, title, install_name = None):
613            self.filename = filename
614            self.title = title
615            if install_name is not None:
616                self.install_name = install_name
617            else:
618                self.install_name = filename
619    
620    
621    class thuban_bdist_inno(bdist_inno):
622    
623        """Thuban specific Inno Setup stuff"""
624    
625        def run(self):
626            install_options = {
627                "prefix": ".",
628                "install_scripts": "$base",
629                "warn_dir": 0,
630                "extra_files": ["COPYING", "Lib/proj.dll"],
631                }
632            bdist_inno.run(self, install_options)
633        
634                
635    #
636    #   Run the script
637    #
638    
639    
640  long_description = """\  long_description = """\
641  Thuban is a viewer for geographic data written in Python  Thuban is a viewer for geographic data written in Python
642  """  """
643    
644  setup(name = "thuban",  setup(name = "Thuban",
645        version = "0.0.3",        version = "0.0.3",
646        description = "Geographic data viewer",        description = "Geographic data viewer",
647        long_description = long_description,        long_description = long_description,
# Line 394  setup(name = "thuban", Line 664  setup(name = "thuban",
664                    # same directory.                    # same directory.
665                    "install_lib": "$base/thuban",                    "install_lib": "$base/thuban",
666                    "install_scripts": "$base/thuban",                    "install_scripts": "$base/thuban",
667                    "install_data": "$base/thuban/",                    "install_data": "$base/thuban",
668    
669                    # Don't print warning messages about the lib dir not                    # Don't print warning messages about the lib dir not
670                    # being on Python's path. The libraries are Thuban                    # being on Python's path. The libraries are Thuban
671                    # specific and are installed just for Thuban. They'll                    # specific and are installed just for Thuban. They'll
672                    # be automatically on Python's path when Thuban is run                    # be automatically on Python's path when Thuban is run
673                    "warn_dir": 0,                    "warn_dir": 0,
674                    }},                    },
675                     "bdist_inno":
676                     {"icons_entries": [InnoIconItem(".\\thuban.py",
677                                                     "Start Thuban",
678                                                     "{app}\\thuban.pyw")],
679                      "license_file": "COPYING",
680                      }
681                     },
682        cmdclass = {"build_py": thuban_build_py,        cmdclass = {"build_py": thuban_build_py,
683                    "install_local": InstallLocal,                    "install_local": InstallLocal,
684                    "install": ThubanInstall})                    "install": ThubanInstall,
685                      "bdist_inno": thuban_bdist_inno
686                      })
687    
688    

Legend:
Removed from v.8  
changed lines
  Added in v.18

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26