Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Static Public Attributes
distutils.command.bdist_wininst.bdist_wininst Class Reference
Inheritance diagram for distutils.command.bdist_wininst.bdist_wininst:
Inheritance graph
[legend]
Collaboration diagram for distutils.command.bdist_wininst.bdist_wininst:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def initialize_options
def finalize_options
def run
def get_inidata
def create_exe
def get_installer_filename
def get_exe_bytes

Public Attributes

 bdist_dir
 plat_name
 keep_temp
 no_target_compile
 no_target_optimize
 target_version
 dist_dir
 bitmap
 title
 skip_build
 install_script
 pre_install_script
 user_access_control

Static Public Attributes

string description = "create an executable installer for MS Windows"
list user_options
list boolean_options

Detailed Description

Definition at line 14 of file bdist_wininst.py.


Member Function Documentation

def distutils.command.bdist_wininst.bdist_wininst.create_exe (   self,
  arcname,
  fullname,
  bitmap = None 
)

Definition at line 239 of file bdist_wininst.py.

00239 
00240     def create_exe(self, arcname, fullname, bitmap=None):
00241         import struct
00242 
00243         self.mkpath(self.dist_dir)
00244 
00245         cfgdata = self.get_inidata()
00246 
00247         installer_name = self.get_installer_filename(fullname)
00248         self.announce("creating %s" % installer_name)
00249 
00250         if bitmap:
00251             bitmapdata = open(bitmap, "rb").read()
00252             bitmaplen = len(bitmapdata)
00253         else:
00254             bitmaplen = 0
00255 
00256         file = open(installer_name, "wb")
00257         file.write(self.get_exe_bytes())
00258         if bitmap:
00259             file.write(bitmapdata)
00260 
00261         # Convert cfgdata from unicode to ascii, mbcs encoded
00262         if isinstance(cfgdata, str):
00263             cfgdata = cfgdata.encode("mbcs")
00264 
00265         # Append the pre-install script
00266         cfgdata = cfgdata + b"\0"
00267         if self.pre_install_script:
00268             # We need to normalize newlines, so we open in text mode and
00269             # convert back to bytes. "latin1" simply avoids any possible
00270             # failures.
00271             with open(self.pre_install_script, "r",
00272                 encoding="latin1") as script:
00273                 script_data = script.read().encode("latin1")
00274             cfgdata = cfgdata + script_data + b"\n\0"
00275         else:
00276             # empty pre-install script
00277             cfgdata = cfgdata + b"\0"
00278         file.write(cfgdata)
00279 
00280         # The 'magic number' 0x1234567B is used to make sure that the
00281         # binary layout of 'cfgdata' is what the wininst.exe binary
00282         # expects.  If the layout changes, increment that number, make
00283         # the corresponding changes to the wininst.exe sources, and
00284         # recompile them.
00285         header = struct.pack("<iii",
00286                              0x1234567B,       # tag
00287                              len(cfgdata),     # length
00288                              bitmaplen,        # number of bytes in bitmap
00289                              )
00290         file.write(header)
00291         file.write(open(arcname, "rb").read())

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 74 of file bdist_wininst.py.

00074 
00075     def finalize_options(self):
00076         self.set_undefined_options('bdist', ('skip_build', 'skip_build'))
00077 
00078         if self.bdist_dir is None:
00079             if self.skip_build and self.plat_name:
00080                 # If build is skipped and plat_name is overridden, bdist will
00081                 # not see the correct 'plat_name' - so set that up manually.
00082                 bdist = self.distribution.get_command_obj('bdist')
00083                 bdist.plat_name = self.plat_name
00084                 # next the command will be initialized using that name
00085             bdist_base = self.get_finalized_command('bdist').bdist_base
00086             self.bdist_dir = os.path.join(bdist_base, 'wininst')
00087 
00088         if not self.target_version:
00089             self.target_version = ""
00090 
00091         if not self.skip_build and self.distribution.has_ext_modules():
00092             short_version = get_python_version()
00093             if self.target_version and self.target_version != short_version:
00094                 raise DistutilsOptionError(
00095                       "target version can only be %s, or the '--skip-build'" \
00096                       " option must be specified" % (short_version,))
00097             self.target_version = short_version
00098 
00099         self.set_undefined_options('bdist',
00100                                    ('dist_dir', 'dist_dir'),
00101                                    ('plat_name', 'plat_name'),
00102                                   )
00103 
00104         if self.install_script:
00105             for script in self.distribution.scripts:
00106                 if self.install_script == os.path.basename(script):
00107                     break
00108             else:
00109                 raise DistutilsOptionError(
00110                       "install_script '%s' not found in scripts"
00111                       % self.install_script)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 305 of file bdist_wininst.py.

00305 
00306     def get_exe_bytes(self):
00307         from distutils.msvccompiler import get_build_version
00308         # If a target-version other than the current version has been
00309         # specified, then using the MSVC version from *this* build is no good.
00310         # Without actually finding and executing the target version and parsing
00311         # its sys.version, we just hard-code our knowledge of old versions.
00312         # NOTE: Possible alternative is to allow "--target-version" to
00313         # specify a Python executable rather than a simple version string.
00314         # We can then execute this program to obtain any info we need, such
00315         # as the real sys.version string for the build.
00316         cur_version = get_python_version()
00317         if self.target_version and self.target_version != cur_version:
00318             # If the target version is *later* than us, then we assume they
00319             # use what we use
00320             # string compares seem wrong, but are what sysconfig.py itself uses
00321             if self.target_version > cur_version:
00322                 bv = get_build_version()
00323             else:
00324                 if self.target_version < "2.4":
00325                     bv = 6.0
00326                 else:
00327                     bv = 7.1
00328         else:
00329             # for current version - use authoritative check.
00330             bv = get_build_version()
00331 
00332         # wininst-x.y.exe is in the same directory as this file
00333         directory = os.path.dirname(__file__)
00334         # we must use a wininst-x.y.exe built with the same C compiler
00335         # used for python.  XXX What about mingw, borland, and so on?
00336 
00337         # if plat_name starts with "win" but is not "win32"
00338         # we want to strip "win" and leave the rest (e.g. -amd64)
00339         # for all other cases, we don't want any suffix
00340         if self.plat_name != 'win32' and self.plat_name[:3] == 'win':
00341             sfix = self.plat_name[3:]
00342         else:
00343             sfix = ''
00344 
00345         filename = os.path.join(directory, "wininst-%.1f%s.exe" % (bv, sfix))
00346         f = open(filename, "rb")
00347         try:
00348             return f.read()
00349         finally:
00350             f.close()

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 193 of file bdist_wininst.py.

00193 
00194     def get_inidata(self):
00195         # Return data describing the installation.
00196         lines = []
00197         metadata = self.distribution.metadata
00198 
00199         # Write the [metadata] section.
00200         lines.append("[metadata]")
00201 
00202         # 'info' will be displayed in the installer's dialog box,
00203         # describing the items to be installed.
00204         info = (metadata.long_description or '') + '\n'
00205 
00206         # Escape newline characters
00207         def escape(s):
00208             return s.replace("\n", "\\n")
00209 
00210         for name in ["author", "author_email", "description", "maintainer",
00211                      "maintainer_email", "name", "url", "version"]:
00212             data = getattr(metadata, name, "")
00213             if data:
00214                 info = info + ("\n    %s: %s" % \
00215                                (name.capitalize(), escape(data)))
00216                 lines.append("%s=%s" % (name, escape(data)))
00217 
00218         # The [setup] section contains entries controlling
00219         # the installer runtime.
00220         lines.append("\n[Setup]")
00221         if self.install_script:
00222             lines.append("install_script=%s" % self.install_script)
00223         lines.append("info=%s" % escape(info))
00224         lines.append("target_compile=%d" % (not self.no_target_compile))
00225         lines.append("target_optimize=%d" % (not self.no_target_optimize))
00226         if self.target_version:
00227             lines.append("target_version=%s" % self.target_version)
00228         if self.user_access_control:
00229             lines.append("user_access_control=%s" % self.user_access_control)
00230 
00231         title = self.title or self.distribution.get_fullname()
00232         lines.append("title=%s" % escape(title))
00233         import time
00234         import distutils
00235         build_info = "Built %s with distutils-%s" % \
00236                      (time.ctime(time.time()), distutils.__version__)
00237         lines.append("build_info=%s" % build_info)
00238         return "\n".join(lines)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 292 of file bdist_wininst.py.

00292 
00293     def get_installer_filename(self, fullname):
00294         # Factored out to allow overriding in subclasses
00295         if self.target_version:
00296             # if we create an installer for a specific python version,
00297             # it's better to include this in the name
00298             installer_name = os.path.join(self.dist_dir,
00299                                           "%s.%s-py%s.exe" %
00300                                            (fullname, self.plat_name, self.target_version))
00301         else:
00302             installer_name = os.path.join(self.dist_dir,
00303                                           "%s.%s.exe" % (fullname, self.plat_name))
00304         return installer_name

Here is the caller graph for this function:

Definition at line 58 of file bdist_wininst.py.

00058 
00059     def initialize_options(self):
00060         self.bdist_dir = None
00061         self.plat_name = None
00062         self.keep_temp = 0
00063         self.no_target_compile = 0
00064         self.no_target_optimize = 0
00065         self.target_version = None
00066         self.dist_dir = None
00067         self.bitmap = None
00068         self.title = None
00069         self.skip_build = None
00070         self.install_script = None
00071         self.pre_install_script = None
00072         self.user_access_control = None
00073 

Definition at line 112 of file bdist_wininst.py.

00112 
00113     def run(self):
00114         if (sys.platform != "win32" and
00115             (self.distribution.has_ext_modules() or
00116              self.distribution.has_c_libraries())):
00117             raise DistutilsPlatformError \
00118                   ("distribution contains extensions and/or C libraries; "
00119                    "must be compiled on a Windows 32 platform")
00120 
00121         if not self.skip_build:
00122             self.run_command('build')
00123 
00124         install = self.reinitialize_command('install', reinit_subcommands=1)
00125         install.root = self.bdist_dir
00126         install.skip_build = self.skip_build
00127         install.warn_dir = 0
00128         install.plat_name = self.plat_name
00129 
00130         install_lib = self.reinitialize_command('install_lib')
00131         # we do not want to include pyc or pyo files
00132         install_lib.compile = 0
00133         install_lib.optimize = 0
00134 
00135         if self.distribution.has_ext_modules():
00136             # If we are building an installer for a Python version other
00137             # than the one we are currently running, then we need to ensure
00138             # our build_lib reflects the other Python version rather than ours.
00139             # Note that for target_version!=sys.version, we must have skipped the
00140             # build step, so there is no issue with enforcing the build of this
00141             # version.
00142             target_version = self.target_version
00143             if not target_version:
00144                 assert self.skip_build, "Should have already checked this"
00145                 target_version = sys.version[0:3]
00146             plat_specifier = ".%s-%s" % (self.plat_name, target_version)
00147             build = self.get_finalized_command('build')
00148             build.build_lib = os.path.join(build.build_base,
00149                                            'lib' + plat_specifier)
00150 
00151         # Use a custom scheme for the zip-file, because we have to decide
00152         # at installation time which scheme to use.
00153         for key in ('purelib', 'platlib', 'headers', 'scripts', 'data'):
00154             value = key.upper()
00155             if key == 'headers':
00156                 value = value + '/Include/$dist_name'
00157             setattr(install,
00158                     'install_' + key,
00159                     value)
00160 
00161         log.info("installing to %s", self.bdist_dir)
00162         install.ensure_finalized()
00163 
00164         # avoid warning of 'install_lib' about installing
00165         # into a directory not in sys.path
00166         sys.path.insert(0, os.path.join(self.bdist_dir, 'PURELIB'))
00167 
00168         install.run()
00169 
00170         del sys.path[0]
00171 
00172         # And make an archive relative to the root of the
00173         # pseudo-installation tree.
00174         from tempfile import mktemp
00175         archive_basename = mktemp()
00176         fullname = self.distribution.get_fullname()
00177         arcname = self.make_archive(archive_basename, "zip",
00178                                     root_dir=self.bdist_dir)
00179         # create an exe containing the zip-file
00180         self.create_exe(arcname, fullname, self.bitmap)
00181         if self.distribution.has_ext_modules():
00182             pyversion = get_python_version()
00183         else:
00184             pyversion = 'any'
00185         self.distribution.dist_files.append(('bdist_wininst', pyversion,
00186                                              self.get_installer_filename(fullname)))
00187         # remove the zip-file again
00188         log.debug("removing temporary file '%s'", arcname)
00189         os.remove(arcname)
00190 
00191         if not self.keep_temp:
00192             remove_tree(self.bdist_dir, dry_run=self.dry_run)

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 59 of file bdist_wininst.py.

Definition at line 66 of file bdist_wininst.py.

Initial value:
['keep-temp', 'no-target-compile', 'no-target-optimize',
                       'skip-build']

Definition at line 55 of file bdist_wininst.py.

string distutils.command.bdist_wininst.bdist_wininst.description = "create an executable installer for MS Windows" [static]

Definition at line 16 of file bdist_wininst.py.

Definition at line 65 of file bdist_wininst.py.

Definition at line 69 of file bdist_wininst.py.

Definition at line 61 of file bdist_wininst.py.

Definition at line 62 of file bdist_wininst.py.

Definition at line 63 of file bdist_wininst.py.

Definition at line 60 of file bdist_wininst.py.

Definition at line 70 of file bdist_wininst.py.

Definition at line 68 of file bdist_wininst.py.

Definition at line 64 of file bdist_wininst.py.

Definition at line 67 of file bdist_wininst.py.

Definition at line 71 of file bdist_wininst.py.

Definition at line 18 of file bdist_wininst.py.


The documentation for this class was generated from the following file: