<s> """<STR_LIT>""" <EOL> __revision__ = "<STR_LIT>" <EOL> import sys , os , string <EOL> from distutils . core import Command <EOL> from distutils . util import get_platform <EOL> from distutils . dir_util import create_tree , remove_tree <EOL> from distutils . errors import * <EOL> from distutils . sysconfig import get_python_version <EOL> from distutils import log <EOL> class bdist_wininst ( Command ) : <EOL> description = "<STR_LIT>" <EOL> user_options = [ ( '<STR_LIT>' , None , <EOL> "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:k>' , <EOL> "<STR_LIT>" + <EOL> "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , None , <EOL> "<STR_LIT>" + <EOL> "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:c>' , <EOL> "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:o>' , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:d>' , <EOL> "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:b>' , <EOL> "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:t>' , <EOL> "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , None , <EOL> "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , None , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , None , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) , <EOL> ] <EOL> boolean_options = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ] <EOL> def initialize_options ( self ) : <EOL> self . bdist_dir = None <EOL> self . keep_temp = <NUM_LIT:0> <EOL> self . no_target_compile = <NUM_LIT:0> <EOL> self . no_target_optimize = <NUM_LIT:0> <EOL> self . target_version = None <EOL> self . dist_dir = None <EOL> self . bitmap = None <EOL> self . title = None <EOL> self . skip_build = <NUM_LIT:0> <EOL> self . install_script = None <EOL> self . pre_install_script = None <EOL> def finalize_options ( self ) : <EOL> if self . bdist_dir is None : <EOL> bdist_base = self . get_finalized_command ( '<STR_LIT>' ) . bdist_base <EOL> self . bdist_dir = os . path . join ( bdist_base , '<STR_LIT>' ) <EOL> if not self . target_version : <EOL> self . target_version = "<STR_LIT>" <EOL> if not self . skip_build and self . distribution . has_ext_modules ( ) : <EOL> short_version = get_python_version ( ) <EOL> if self . target_version and self . target_version != short_version : <EOL> raise DistutilsOptionError , "<STR_LIT>" "<STR_LIT>" % ( short_version , ) <EOL> self . target_version = short_version <EOL> self . set_undefined_options ( '<STR_LIT>' , ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> if self . install_script : <EOL> for script in self . distribution . scripts : <EOL> if self . install_script == os . path . basename ( script ) : <EOL> break <EOL> else : <EOL> raise DistutilsOptionError , "<STR_LIT>" % self . install_script <EOL> def run ( self ) : <EOL> if ( sys . platform != "<STR_LIT:win32>" and <EOL> ( self . distribution . has_ext_modules ( ) or <EOL> self . distribution . has_c_libraries ( ) ) ) : <EOL> raise DistutilsPlatformError ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> if not self . skip_build : <EOL> self . run_command ( '<STR_LIT>' ) <EOL> install = self . reinitialize_command ( '<STR_LIT>' , reinit_subcommands = <NUM_LIT:1> ) <EOL> install . root = self . bdist_dir <EOL> install . skip_build = self . skip_build <EOL> install . warn_dir = <NUM_LIT:0> <EOL> install_lib = self . reinitialize_command ( '<STR_LIT>' ) <EOL> install_lib . compile = <NUM_LIT:0> <EOL> install_lib . optimize = <NUM_LIT:0> <EOL> if self . distribution . has_ext_modules ( ) : <EOL> target_version = self . target_version <EOL> if not target_version : <EOL> assert self . skip_build , "<STR_LIT>" <EOL> target_version = sys . version [ <NUM_LIT:0> : <NUM_LIT:3> ] <EOL> plat_specifier = "<STR_LIT>" % ( get_platform ( ) , target_version ) <EOL> build = self . get_finalized_command ( '<STR_LIT>' ) <EOL> build . build_lib = os . path . join ( build . build_base , <EOL> '<STR_LIT>' + plat_specifier ) <EOL> for key in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:data>' ) : <EOL> value = string . upper ( key ) <EOL> if key == '<STR_LIT>' : <EOL> value = value + '<STR_LIT>' <EOL> setattr ( install , <EOL> '<STR_LIT>' + key , <EOL> value ) <EOL> log . info ( "<STR_LIT>" , self . bdist_dir ) <EOL> install . ensure_finalized ( ) <EOL> sys . path . insert ( <NUM_LIT:0> , os . path . join ( self . bdist_dir , '<STR_LIT>' ) ) <EOL> install . run ( ) <EOL> del sys . path [ <NUM_LIT:0> ] <EOL> from tempfile import mktemp <EOL> archive_basename = mktemp ( ) <EOL> fullname = self . distribution . get_fullname ( ) <EOL> arcname = self . make_archive ( archive_basename , "<STR_LIT>" , <EOL> root_dir = self . bdist_dir ) <EOL> self . create_exe ( arcname , fullname , self . bitmap ) <EOL> if self . distribution . has_ext_modules ( ) : <EOL> pyversion = get_python_version ( ) <EOL> else : <EOL> pyversion = '<STR_LIT>' <EOL> self . distribution . dist_files . append ( ( '<STR_LIT>' , pyversion , <EOL> self . get_installer_filename ( fullname ) ) ) <EOL> log . debug ( "<STR_LIT>" , arcname ) <EOL> os . remove ( arcname ) <EOL> if not self . keep_temp : <EOL> remove_tree ( self . bdist_dir , dry_run = self . dry_run ) <EOL> def get_inidata ( self ) : <EOL> lines = [ ] <EOL> metadata = self . distribution . metadata <EOL> lines . append ( "<STR_LIT>" ) <EOL> info = ( metadata . long_description or '<STR_LIT>' ) + '<STR_LIT:\n>' <EOL> def escape ( s ) : <EOL> return string . replace ( s , "<STR_LIT:\n>" , "<STR_LIT>" ) <EOL> for name in [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:description>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT:name>" , "<STR_LIT:url>" , "<STR_LIT:version>" ] : <EOL> data = getattr ( metadata , name , "<STR_LIT>" ) <EOL> if data : <EOL> info = info + ( "<STR_LIT>" % ( string . capitalize ( name ) , escape ( data ) ) ) <EOL> lines . append ( "<STR_LIT>" % ( name , escape ( data ) ) ) <EOL> lines . append ( "<STR_LIT>" ) <EOL> if self . install_script : <EOL> lines . append ( "<STR_LIT>" % self . install_script ) <EOL> lines . append ( "<STR_LIT>" % escape ( info ) ) <EOL> lines . append ( "<STR_LIT>" % ( not self . no_target_compile ) ) <EOL> lines . append ( "<STR_LIT>" % ( not self . no_target_optimize ) ) <EOL> if self . target_version : <EOL> lines . append ( "<STR_LIT>" % self . target_version ) <EOL> title = self . title or self . distribution . get_fullname ( ) <EOL> lines . append ( "<STR_LIT>" % escape ( title ) ) <EOL> import time <EOL> import distutils <EOL> build_info = "<STR_LIT>" % ( time . ctime ( time . time ( ) ) , distutils . __version__ ) <EOL> lines . append ( "<STR_LIT>" % build_info ) <EOL> return string . join ( lines , "<STR_LIT:\n>" ) <EOL> def create_exe ( self , arcname , fullname , bitmap = None ) : <EOL> import struct <EOL> self . mkpath ( self . dist_dir ) <EOL> cfgdata = self . get_inidata ( ) <EOL> installer_name = self . get_installer_filename ( fullname ) <EOL> self . announce ( "<STR_LIT>" % installer_name ) <EOL> if bitmap : <EOL> bitmapdata = open ( bitmap , "<STR_LIT:rb>" ) . read ( ) <EOL> bitmaplen = len ( bitmapdata ) <EOL> else : <EOL> bitmaplen = <NUM_LIT:0> <EOL> file = open ( installer_name , "<STR_LIT:wb>" ) <EOL> file . write ( self . get_exe_bytes ( ) ) <EOL> if bitmap : <EOL> file . write ( bitmapdata ) <EOL> try : <EOL> unicode <EOL> except NameError : <EOL> pass <EOL> else : <EOL> if isinstance ( cfgdata , unicode ) : <EOL> cfgdata = cfgdata . encode ( "<STR_LIT>" ) <EOL> cfgdata = cfgdata + "<STR_LIT>" <EOL> if self . pre_install_script : <EOL> script_data = open ( self . pre_install_script , "<STR_LIT:r>" ) . read ( ) <EOL> cfgdata = cfgdata + script_data + "<STR_LIT>" <EOL> else : <EOL> cfgdata = cfgdata + "<STR_LIT>" <EOL> file . write ( cfgdata ) <EOL> header = struct . pack ( "<STR_LIT>" , <EOL> <NUM_LIT> , <EOL> len ( cfgdata ) , <EOL> bitmaplen , <EOL> ) <EOL> file . write ( header ) <EOL> file . write ( open ( arcname , "<STR_LIT:rb>" ) . read ( ) ) <EOL> def get_installer_filename ( self , fullname ) : <EOL> if self . target_version : <EOL> installer_name = os . path . join ( self . dist_dir , <EOL> "<STR_LIT>" % <EOL> ( fullname , self . target_version ) ) <EOL> else : <EOL> installer_name = os . path . join ( self . dist_dir , <EOL> "<STR_LIT>" % fullname ) <EOL> return installer_name <EOL> def get_exe_bytes ( self ) : <EOL> from distutils . msvccompiler import get_build_version <EOL> cur_version = get_python_version ( ) <EOL> if self . target_version and self . target_version != cur_version : <EOL> if self . target_version > cur_version : <EOL> bv = get_build_version ( ) <EOL> else : <EOL> if self . target_version < "<STR_LIT>" : <EOL> bv = "<STR_LIT>" <EOL> else : <EOL> bv = "<STR_LIT>" <EOL> else : <EOL> bv = get_build_version ( ) <EOL> directory = os . path . dirname ( __file__ ) <EOL> filename = os . path . join ( directory , "<STR_LIT>" % bv ) <EOL> return open ( filename , "<STR_LIT:rb>" ) . read ( ) </s>
