srcanamdw/codescanner/pyinstaller/Makespec.py
author noe\swadi
Thu, 18 Feb 2010 12:29:02 +0530
changeset 1 22878952f6e2
permissions -rw-r--r--
Committing the CodeScanner Core tool This component has been moved from the StaticAnaApps package. BUG : 5889 (http://developer.symbian.org/webbugs/show_bug.cgi?id=5889).
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
     1
#! /usr/bin/env/python
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
     2
# Automatically build spec files containing a description of the project
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
     3
# Copyright (C) 2005, Giovanni Bajo
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
     4
# Based on previous work under copyright (c) 2002 McMillan Enterprises, Inc.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
     5
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
     6
# This program is free software; you can redistribute it and/or
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
     7
# modify it under the terms of the GNU General Public License
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
     8
# as published by the Free Software Foundation; either version 2
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
     9
# of the License, or (at your option) any later version.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    10
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    11
# This program is distributed in the hope that it will be useful,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    14
# GNU General Public License for more details.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    15
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    16
# You should have received a copy of the GNU General Public License
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    17
# along with this program; if not, write to the Free Software
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    18
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    19
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    20
import sys, os, string
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    21
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    22
# For Python 1.5 compatibility
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    23
try:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    24
    True
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    25
except:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    26
    True,False = 1,0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    27
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    28
freezetmplt = """\
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    29
a = Analysis(%(scripts)s,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    30
             pathex=%(pathex)s)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    31
pyz = PYZ(a.pure)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    32
exe = EXE(%(tkpkg)s pyz,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    33
          a.scripts,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    34
          a.binaries,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    35
          name='%(exename)s',
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    36
          debug=%(debug)s,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    37
          strip=%(strip)s,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    38
          upx=%(upx)s,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    39
          console=%(console)s %(exe_options)s)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    40
""" # pathex scripts exename tkpkg debug console
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    41
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    42
collecttmplt = """\
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    43
a = Analysis(%(scripts)s,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    44
             pathex=%(pathex)s)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    45
pyz = PYZ(a.pure)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    46
exe = EXE(pyz,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    47
          a.scripts,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    48
          exclude_binaries=1,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    49
          name='%(builddir)s/%(exename)s',
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    50
          debug=%(debug)s,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    51
          strip=%(strip)s,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    52
          upx=%(upx)s,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    53
          console=%(console)s %(exe_options)s)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    54
coll = COLLECT(%(tktree)s exe,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    55
               a.binaries,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    56
               strip=%(strip)s,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    57
               upx=%(upx)s,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    58
               name='%(distdir)s')
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    59
""" # scripts pathex, exename, debug, console tktree distdir
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    60
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    61
comsrvrtmplt = """\
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    62
a = Analysis(%(scripts)s,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    63
             pathex=%(pathex)s)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    64
pyz = PYZ(a.pure)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    65
exe = EXE(pyz,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    66
          a.scripts,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    67
          exclude_binaries=1,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    68
          name='%(builddir)s/%(exename)s',
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    69
          debug=%(debug)s,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    70
          strip=%(strip)s,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    71
          upx=%(upx)s,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    72
          console=%(console)s %(exe_options)s)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    73
dll = DLL(pyz,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    74
          a.scripts,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    75
          exclude_binaries=1,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    76
          name='%(builddir)s/%(dllname)s',
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    77
          debug=%(debug)s)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    78
coll = COLLECT(exe, dll,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    79
               a.binaries,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    80
               strip=%(strip)s,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    81
               upx=%(upx)s,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    82
               name='%(distdir)s')
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    83
""" # scripts pathex, exename, debug, console tktree distdir
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    84
HOME = os.path.dirname(sys.argv[0])
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    85
if HOME == '':
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    86
    HOME = os.getcwd()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    87
if not os.path.isabs(HOME):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    88
    HOME = os.path.abspath(HOME)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    89
iswin = sys.platform[:3] == "win"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    90
cygwin = sys.platform == "cygwin"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    91
try:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    92
    config = eval(open(os.path.join(HOME, 'config.dat'), 'r').read())
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    93
except IOError:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    94
    print "You must run Configure.py before building!"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    95
    sys.exit(1)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    96
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    97
if config['pythonVersion'] != sys.version:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    98
    print "The current version of Python is not the same with which PyInstaller was configured."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    99
    print "Please re-run Configure.py with this version."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   100
    sys.exit(1)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   101
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   102
def quote_win_filepath( path ):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   103
    # quote all \ with another \ after using normpath to clean up the path
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   104
    return string.join( string.split( os.path.normpath( path ), '\\' ), '\\\\' )
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   105
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   106
# Support for trying to avoid hard-coded paths in the .spec files.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   107
# Eg, all files rooted in the Installer directory tree will be
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   108
# written using "HOMEPATH", thus allowing this spec file to
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   109
# be used with any Installer installation.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   110
# Same thing could be done for other paths too.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   111
path_conversions = (
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   112
    (HOME, "HOMEPATH"),
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   113
    # Add Tk etc?
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   114
    )
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   115
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   116
def make_variable_path(filename, conversions = path_conversions):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   117
    for (from_path, to_name) in conversions:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   118
        assert os.path.abspath(from_path)==from_path, \
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   119
            "path '%s' should already be absolute" % (from_path,)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   120
        if filename[:len(from_path)] == from_path:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   121
            rest = filename[len(from_path):]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   122
            if rest[0] in "\\/":
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   123
                rest = rest[1:]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   124
            return to_name, rest
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   125
    return None, filename
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   126
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   127
# An object used in place of a "path string" which knows how to repr()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   128
# itself using variable names instead of hard-coded paths.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   129
class Path:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   130
    def __init__(self, *parts):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   131
        self.path = apply(os.path.join, parts)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   132
        self.variable_prefix = self.filename_suffix = None
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   133
    def __repr__(self):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   134
        if self.filename_suffix is None:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   135
            self.variable_prefix, self.filename_suffix = make_variable_path(self.path)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   136
        if self.variable_prefix is None:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   137
            return repr(self.path)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   138
        return "os.path.join(" + self.variable_prefix + "," + repr(self.filename_suffix) + ")"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   139
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   140
def main(scripts, name=None, tk=0, freeze=0, console=1, debug=0, strip=0, upx=0,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   141
         comserver=0, ascii=0, workdir=None, pathex=[], version_file=None, icon_file=None):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   142
    if name is None:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   143
        name = os.path.splitext(os.path.basename(scripts[0]))[0]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   144
    distdir = "dist%s" % name
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   145
    builddir = "build%s" % name
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   146
    pathex = pathex[:]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   147
    if workdir is None:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   148
        workdir = os.getcwd()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   149
        pathex.append(workdir)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   150
    else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   151
        pathex.append(os.getcwd())
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   152
    if workdir == HOME:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   153
        workdir = os.path.join(HOME, name)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   154
    if not os.path.exists(workdir):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   155
        os.makedirs(workdir)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   156
    exe_options = ''
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   157
    if version_file:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   158
        exe_options = "%s, version='%s'" % (exe_options, quote_win_filepath(version_file))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   159
    if icon_file:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   160
        exe_options = "%s, icon='%s'" % (exe_options, quote_win_filepath(icon_file))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   161
    if not ascii and config['hasUnicode']:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   162
        scripts.insert(0, os.path.join(HOME, 'support', 'useUnicode.py'))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   163
    for i in range(len(scripts)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   164
        scripts[i] = Path(scripts[i]) # Use relative path in specfiles
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   165
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   166
    d = {'tktree':'',
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   167
         'tkpkg' :'',
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   168
         'scripts':scripts,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   169
         'pathex' :pathex,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   170
         'exename': '',
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   171
         'distdir': distdir,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   172
         'builddir': builddir,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   173
         'debug': debug,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   174
         'strip': strip,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   175
         'upx' : upx,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   176
         'console': console or debug,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   177
         'exe_options': exe_options}
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   178
    if tk:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   179
        d['tktree'] = "TkTree(),"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   180
        if freeze:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   181
            scripts.insert(0, Path(HOME, 'support', 'useTK.py'))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   182
            scripts.insert(0, Path(HOME, 'support', 'unpackTK.py'))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   183
            scripts.append(Path(HOME, 'support', 'removeTK.py'))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   184
            d['tkpkg'] = "TkPKG(),"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   185
        else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   186
            scripts.insert(0, Path(HOME, 'support', 'useTK.py'))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   187
    scripts.insert(0, Path(HOME, 'support', '_mountzlib.py'))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   188
    if iswin or cygwin:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   189
        d['exename'] = name+'.exe'
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   190
        d['dllname'] = name+'.dll'
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   191
    else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   192
        d['exename'] = name
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   193
        d['console'] = 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   194
    specfnm = os.path.join(workdir, name+'.spec')
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   195
    specfile = open(specfnm, 'w')
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   196
    if freeze:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   197
        specfile.write(freezetmplt % d)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   198
    elif comserver:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   199
        specfile.write(comsrvrtmplt % d)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   200
    else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   201
        specfile.write(collecttmplt % d)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   202
    specfile.close()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   203
    return specfnm
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   204
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   205
if __name__ == '__main__':
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   206
    import optparse
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   207
    p = optparse.OptionParser(
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   208
        usage="python %prog [opts] <scriptname> [<scriptname> ...]"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   209
    )
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   210
    p.add_option("-F", "--onefile", dest="freeze",
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   211
                 action="store_true", default=False,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   212
                 help="create a single file deployment")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   213
    p.add_option("-D", "--onedir", dest="freeze", action="store_false",
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   214
                 help="create a single directory deployment (default)")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   215
    p.add_option("-w", "--windowed", "--noconsole", dest="console",
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   216
                 action="store_false", default=True,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   217
                 help="use a Windows subsystem executable (Windows only)")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   218
    p.add_option("-c", "--nowindowed", "--console", dest="console",
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   219
                 action="store_true",
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   220
                 help="use a console subsystem executable (Windows only) "
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   221
                      "(default)")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   222
    p.add_option("-a", "--ascii", action="store_true", default=False,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   223
                 help="do NOT include unicode encodings "
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   224
                      "(default: included if available)")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   225
    p.add_option("-d", "--debug", action="store_true", default=False,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   226
                 help="use the debug (verbose) build of the executable")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   227
    p.add_option("-s", "--strip", action="store_true", default=False,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   228
                 help="strip the exe and shared libs "
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   229
                      "(don't try this on Windows)")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   230
    p.add_option("-X", "--upx", action="store_true", default=False,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   231
                 help="use UPX if available (works differently between "
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   232
                      "Windows and *nix)")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   233
    p.add_option("-K", "--tk", default=False, action="store_true",
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   234
                 help="include TCL/TK in the deployment")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   235
    p.add_option("-o", "--out", type="string", default=None,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   236
                 dest="workdir", metavar="DIR",
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   237
                 help="generate the spec file in the specified directory")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   238
    p.add_option("-n", "--name", type="string", default=None,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   239
                 help="name to assign to the project, from which the spec file "
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   240
                      "name is generated. (default: use the basename of the "
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   241
                      "(first) script)")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   242
    p.add_option("-p", "--paths", type="string", default=[], dest="pathex",
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   243
                 metavar="DIR", action="append",
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   244
                 help="set base path for import (like using PYTHONPATH). "
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   245
                      "Multiple directories are allowed, separating them "
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   246
                      "with %s, or using this option multiple times"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   247
                      % repr(os.pathsep))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   248
    p.add_option("-v", "--version", type="string",
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   249
                 dest="version_file", metavar="FILE",
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   250
                 help="add a version resource from FILE to the exe "
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   251
                      "(Windows only)")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   252
    p.add_option("--icon", type="string", dest="icon_file",
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   253
                 metavar="FILE.ICO or FILE.EXE,ID",
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   254
                 help="If FILE is an .ico file, add the icon to the final "
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   255
                      "executable. Otherwise, the syntax 'file.exe,id' to "
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   256
                      "extract the icon with the specified id "
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   257
                      "from file.exe and add it to the final executable")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   258
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   259
    opts,args = p.parse_args()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   260
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   261
    # Split pathex by using the path separator
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   262
    temppaths = opts.pathex[:]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   263
    opts.pathex = []
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   264
    for p in temppaths:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   265
        opts.pathex.extend(string.split(p, os.pathsep))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   266
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   267
    if not args:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   268
        p.print_help()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   269
        sys.exit(1)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   270
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   271
    nm = apply(main, (args,), opts.__dict__)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   272
    print "wrote %s" % nm
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   273
    print "now run Build.py to build the executable"