Exemple #1
0
    def BuildTargetClass(self, configuration, project, customCode, postCompile):
        """ Builds the bbFreeze compilation script file, returning it as a string. """

        # A couple of dictionaries to populate the setup string        
        setupDict, importDict = {}, {}
        configuration = dict(configuration)
        # Delete the keys we don't need
        distChoice = self.distChoice.GetValue()
        del configuration["dist_dir_choice"]

        # Loop over all the keys, values of the configuration dictionary        
        for key, item in configuration.items():
            if isinstance(self.FindWindowByName(key), wx.CheckBox):
                item = bool(int(item))

            if key in ["create_manifest_file", "multipleexe"]:
                # Skip these 2 options, we'll take care of them later...
                continue

            if isinstance(item, basestring) and key != "compress":
                if key == "dist_dir" and (item == "" or not distChoice):
                    item = "'dist'"
                    if distChoice:
                        self.MainFrame.SendMessage(1, _('Empty dist_dir option. Using default value "dist"'))
                else:
                    item = "r'%s'"%item

            if type(item) == ListType:
                # Terrible hack to setup correctly the string to be included
                # in the setup file
                item = setupString(key, item)

            setupDict[key] = item

        targetclass = ""
        for indx in xrange(self.multipleExe.GetItemCount()):
            # Add the target classes
            gui_only = self.multipleExe.GetItem(indx, 1).GetText()
            scriptFile = self.multipleExe.GetItem(indx, 2).GetText()            
            gui = (gui_only == "windows" and [True] or [False])[0]

            targetclass += _bbFreeze_class%{"gui_only": gui, "script": 'r"%s"'%scriptFile}
            buildDir, scriptFile = os.path.split(scriptFile)
            
        # Add the custom code (if any)
        setupDict["customcode"] = (customCode and [customCode.strip()] or ["# No custom code added"])[0]

        # Add the post-compilation code (if any)
        setupDict["postcompilecode"] = (postCompile and [postCompile.strip()] or ["# No post-compilation code added"])[0]

        setupDict["executables"] = targetclass
        # Include the GUI2Exe version in the setup script
        importDict["gui2exever"] = self.MainFrame.GetVersion()

        # Populate the "import" section
        setupScript = _bbFreeze_imports % importDict

        # Populate the main section of the setup script            
        setupScript += _bbFreeze_target % setupDict
        
        # Send a message to out fancy bottom log window
        transdict = dict(projectName=project.GetName())
        self.MainFrame.SendMessage(0, _('Setup script for "%(projectName)s" succesfully created')%transdict)
        return setupScript, buildDir
    def BuildTargetClass(self, configuration, project, manifestFile, customCode, postCompile):
        """ Builds the PyInstaller compilation script file, returning it as a string. """

        # A couple of dictionaries to populate the setup string        
        setupDict, importDict = {}, {}
        configuration = dict(configuration)

        pyFile = self.scriptsList.GetItem(0, 1).GetText()
        buildDir = os.path.split(pyFile)[0]

        includeTk = self.includeTkCheck.GetValue()
        oneDir = self.oneDirRadio.GetValue()
        ascii = self.asciiCheck.GetValue()
        normpath = os.path.normpath

        useRelPath = self.MainFrame.relativePaths
        scriptFile = pyFile
        
        # Loop over all the keys, values of the configuration dictionary        
        for key, item in configuration.items():
            if key.startswith("option"):
                continue
            if isinstance(self.FindWindowByName(key), wx.CheckBox):
                item = bool(int(item))

            if key == "create_manifest_file":
                continue
            
            if type(item) == ListType and item:
                # Terrible hack to setup correctly the string to be included
                # in the setup file
                if key not in ["hookspath", "scripts", "excludes", "pathex"]:
                    tmp = []
                    for data in item:
                        data = data + (_pyInstallerTOC[key],)
                        tmp.append(data)
                    item = tmp
                elif key == "pathex":
                    if buildDir not in item:
                        item.append(buildDir)
                elif key == "scripts":
                    continue

                item = setupString(key, item, True, useRelPath=useRelPath, mainScript=scriptFile)

            if key == "exename" and not item.strip() and not oneDir:
                item = os.path.splitext(os.path.split(pyFile)[1])[0] + ".exe"
            if key == "dist_dir" and not item.strip() and oneDir:
                item = normpath(os.path.split(pyFile)[0] + "/dist")
            if key in ["icon", "version"]:
                if not item.strip():
                    item = None
                else:
                    if useRelPath:
                        item = 'r"%s"'%(relpath(item, os.path.split(scriptFile)[0]))
                    else:
                        item = "r'%s'"%item
            
            setupDict[key] = item

        # Set up the obscure options
        otherOptions = []
        for indx, checks in enumerate(self.optionsCheckBoxes):
            if checks.GetValue():
                otherOptions.append(_pyInstallerOptions[indx])

        setupDict["options"] = otherOptions

        # Depending on the various choices in the interface, PyInstaller
        # includes/excludes some Python source file located in
        # PyInstaller_Path/support/

        pyInstallerPath = self.MainFrame.GetPyInstallerPath()
        if not pyInstallerPath or pyInstallerPath == "None":
            msg = _("PyInstaller path has not been set.\n\nPlease set the PyInstaller" \
                    "path using the menu Options ==> Set PyInstaller path.")
            self.MainFrame.RunError(2, msg)
            return

        items = configuration["scripts"][:]
        pyInstallerPath += "/support/"

        if setupDict["level"] != "0":
            # Include zlib as user wants compression
            items.append(normpath(pyInstallerPath + "_mountzlib.py").encode())
        
        if includeTk:
            # That's a bit of a mess, but PyInstaller is not exactly user-friendly...
            if oneDir:
                items.append(normpath(pyInstallerPath + "useTK.py").encode())
            else:
                items.extend([normpath(pyInstallerPath + "unpackTK.py").encode(),
                              normpath(pyInstallerPath + "useTK.py").encode(),
                              normpath(pyInstallerPath + "removeTK.py").encode()])

        if not ascii:
            # Using unicode
            items.append(normpath(pyInstallerPath + "useUnicode.py").encode())
            
        items.append(items[0])
        items.pop(0)
        
        setupDict["scripts"] = setupString("scripts", items, True)
        
        # Add the custom code (if any)
        setupDict["customcode"] = (customCode and [customCode.strip()] or ["# No custom code added"])[0]

        # Add the post-compilation code (if any)
        setupDict["postcompilecode"] = (postCompile and [postCompile.strip()] or ["# No post-compilation code added"])[0]
        
        # Include the GUI2Exe version in the setup script
        importDict["gui2exever"] = self.MainFrame.GetVersion()

        # Populate the "import" section
        setupScript = _pyInstaller_imports % importDict

        if oneDir:
            target = _pyInstaller_target_onedir
            if includeTk:
                setupDict["TkPKG"] = "TkTree(),"
            else:
                setupDict["TkPKG"] = ""
        else:
            target = _pyInstaller_target_onefile
            if includeTk:
                setupDict["TkPKG"] = "TkPKG(),"
            else:
                setupDict["TkPKG"] = ""
            
        # Populate the main section of the setup script            
        setupScript += target % setupDict

        # Send a message to out fancy bottom log window
        transdict = dict(projectName=project.GetName())
        self.MainFrame.SendMessage(0, _('Setup script for "%(projectName)s" succesfully created')%transdict)
        return setupScript, buildDir
    def BuildTargetClass(self, configuration, project, customCode, postCompile):
        """ Builds the cx_Freeze compilation script file, returning it as a string. """

        # A couple of dictionaries to populate the setup string
        setupDict, importDict = {}, {}
        configuration = dict(configuration)
        # Delete the keys we don't need
        distChoice = self.distChoice.GetValue()
        del configuration["dist_dir_choice"]

        extension = ""
        if wx.Platform == "__WXMSW__":
            extension = ".exe"

        useRelPath = self.MainFrame.relativePaths
        scriptFile = self.multipleExe.GetItem(0, 2).GetText()

        # Loop over all the keys, values of the configuration dictionary
        for key, item in configuration.items():
            if key == "initScript" and not item:
                # I don't know how often this option is used
                item = ""

            elif isinstance(self.FindWindowByName(key), wx.CheckBox):
                item = bool(int(item))

            if key in ["create_manifest_file", "multipleexe"]:
                # Skip these 2 options, we'll take care of them later...
                continue

            if isinstance(item, basestring) and key != "compress":
                if key == "dist_dir":
                    if not item.strip() or not distChoice:
                        item = "dist"
                        if distChoice:
                            self.MainFrame.SendMessage(1, _('Empty dist_dir option. Using default value "dist"'))
                if not item.strip():
                    item = None
                else:
                    if useRelPath and key in ["initScript", "icon"]:
                        item = 'r"%s"' % (relpath(item, os.path.split(scriptFile)[0]))
                    else:
                        item = 'r"%s"' % item

            if type(item) == ListType:
                # Terrible hack to setup correctly the string to be included
                # in the setup file
                item = setupString(key, item, useRelPath=useRelPath, mainScript=scriptFile)

            setupDict[key] = item

        baseName = "GUI2Exe_Target_%d"
        targetclass = ""
        executables = "["

        # Loop over all the Python scripts used
        for indx in xrange(self.multipleExe.GetItemCount()):
            # Add the target class
            tupleMultiple = (baseName % (indx + 1),)
            scriptFile = self.multipleExe.GetItem(indx, 2).GetText()
            buildDir, scriptFile = os.path.split(scriptFile)
            # Add the Python script file
            tupleMultiple += (scriptFile,)
            # Add the init script
            tupleMultiple += (setupDict["initScript"],)
            consoleOrWindows = self.multipleExe.GetItem(indx, 1).GetText()
            # Check if it is a GUI app and if it runs on Windows
            if consoleOrWindows == "windows" and sys.platform == "win32":
                tupleMultiple += ("'Win32GUI'",)
            else:
                tupleMultiple += (None,)
            # Add the distribution directory
            tupleMultiple += (setupDict["dist_dir"],)
            targetName = self.multipleExe.GetItem(indx, 3).GetText()

            if not targetName.strip():
                # Missing executable name? Use the Python script file name
                targetName = os.path.splitext(scriptFile)[0]
                self.MainFrame.SendMessage(1, _("Empty Executable Name option. Using Python script name"))

            # Add the executable name
            tupleMultiple += (targetName + extension,)
            # Add the remaining keys
            tupleMultiple += (
                bool(setupDict["compress"]),
                setupDict["copy_dependent_files"],
                setupDict["append_script_toexe"],
                setupDict["append_script_tolibrary"],
                setupDict["icon"],
            )

            # Build the target classes
            targetclass += _cx_Freeze_class % tupleMultiple
            # Save the executables in a list to be processed by cx_Freeze
            executables += tupleMultiple[0] + ", "

        keys = setupDict.keys()
        for key in keys:
            # Remove the keys we have already used
            if key not in ["includes", "excludes", "packages", "path"]:
                setupDict.pop(key)

        # Add the custom code (if any)
        setupDict["customcode"] = (customCode and [customCode.strip()] or ["# No custom code added"])[0]

        # Add the post-compilation code (if any)
        setupDict["postcompilecode"] = (postCompile and [postCompile.strip()] or ["# No post-compilation code added"])[
            0
        ]

        # Add the target classes and the executables list
        setupDict["targetclasses"] = targetclass
        setupDict["executables"] = executables.rstrip(", ") + "]"

        # Include the GUI2Exe version in the setup script
        importDict["gui2exever"] = self.MainFrame.GetVersion()

        # Populate the "import" section
        setupScript = _cx_Freeze_imports % importDict

        globalSetup = ["version", "description", "author", "name"]
        for col in xrange(4, self.multipleExe.GetColumnCount()):
            item = self.multipleExe.GetItem(indx, col).GetText()
            setupDict[globalSetup[col - 4]] = '"%s"' % item.strip()

        # Populate the main section of the setup script
        setupScript += _cx_Freeze_target % setupDict

        # Send a message to out fancy bottom log window
        transdict = dict(projectName=project.GetName())
        self.MainFrame.SendMessage(0, _('Setup script for "%(projectName)s" succesfully created') % transdict)
        return setupScript, buildDir
Exemple #4
0
    def BuildTargetClass(self, configuration, project, customCode,
                         postCompile):
        """ Builds the cx_Freeze compilation script file, returning it as a string. """

        # A couple of dictionaries to populate the setup string
        setupDict, importDict = {}, {}
        configuration = dict(configuration)
        # Delete the keys we don't need
        distChoice = self.distChoice.GetValue()
        del configuration["dist_dir_choice"]

        extension = ""
        if wx.Platform == "__WXMSW__":
            extension = ".exe"

        useRelPath = self.MainFrame.relativePaths
        scriptFile = self.multipleExe.GetItem(0, 2).GetText()

        # Loop over all the keys, values of the configuration dictionary
        for key, item in configuration.items():
            if key == "initScript" and not item:
                # I don't know how often this option is used
                item = ""

            elif isinstance(self.FindWindowByName(key), wx.CheckBox):
                item = bool(int(item))

            if key in ["create_manifest_file", "multipleexe"]:
                # Skip these 2 options, we'll take care of them later...
                continue

            if isinstance(item, basestring) and key != "compress":
                if key == "dist_dir":
                    if not item.strip() or not distChoice:
                        item = "dist"
                        if distChoice:
                            self.MainFrame.SendMessage(
                                1,
                                _('Empty dist_dir option. Using default value "dist"'
                                  ))
                if not item.strip():
                    item = None
                else:
                    if useRelPath and key in ["initScript", "icon"]:
                        item = 'r"%s"' % (relpath(
                            item,
                            os.path.split(scriptFile)[0]))
                    else:
                        item = 'r"%s"' % item

            if type(item) == ListType:
                # Terrible hack to setup correctly the string to be included
                # in the setup file
                item = setupString(key,
                                   item,
                                   useRelPath=useRelPath,
                                   mainScript=scriptFile)

            setupDict[key] = item

        baseName = "GUI2Exe_Target_%d"
        targetclass = ""
        executables = "["

        # Loop over all the Python scripts used
        for indx in xrange(self.multipleExe.GetItemCount()):
            # Add the target class
            tupleMultiple = (baseName % (indx + 1), )
            scriptFile = self.multipleExe.GetItem(indx, 2).GetText()
            buildDir, scriptFile = os.path.split(scriptFile)
            # Add the Python script file
            tupleMultiple += (scriptFile, )
            # Add the init script
            tupleMultiple += (setupDict["initScript"], )
            consoleOrWindows = self.multipleExe.GetItem(indx, 1).GetText()
            # Check if it is a GUI app and if it runs on Windows
            if consoleOrWindows == "windows" and sys.platform == "win32":
                tupleMultiple += ("'Win32GUI'", )
            else:
                tupleMultiple += (None, )
            # Add the distribution directory
            tupleMultiple += (setupDict["dist_dir"], )
            targetName = self.multipleExe.GetItem(indx, 3).GetText()

            if not targetName.strip():
                # Missing executable name? Use the Python script file name
                targetName = os.path.splitext(scriptFile)[0]
                self.MainFrame.SendMessage(
                    1,
                    _('Empty Executable Name option. Using Python script name')
                )

            # Add the executable name
            tupleMultiple += (targetName + extension, )
            # Add the remaining keys
            tupleMultiple += (bool(setupDict["compress"]),
                              setupDict["copy_dependent_files"],
                              setupDict["append_script_toexe"],
                              setupDict["append_script_tolibrary"],
                              setupDict["icon"])

            # Build the target classes
            targetclass += _cx_Freeze_class % tupleMultiple
            # Save the executables in a list to be processed by cx_Freeze
            executables += tupleMultiple[0] + ", "

        keys = setupDict.keys()
        for key in keys:
            # Remove the keys we have already used
            if key not in ["includes", "excludes", "packages", "path"]:
                setupDict.pop(key)

        # Add the custom code (if any)
        setupDict["customcode"] = (customCode and [customCode.strip()]
                                   or ["# No custom code added"])[0]

        # Add the post-compilation code (if any)
        setupDict["postcompilecode"] = (
            postCompile and [postCompile.strip()]
            or ["# No post-compilation code added"])[0]

        # Add the target classes and the executables list
        setupDict["targetclasses"] = targetclass
        setupDict["executables"] = executables.rstrip(", ") + "]"

        # Include the GUI2Exe version in the setup script
        importDict["gui2exever"] = self.MainFrame.GetVersion()

        # Populate the "import" section
        setupScript = _cx_Freeze_imports % importDict

        globalSetup = ["version", "description", "author", "name"]
        for col in xrange(4, self.multipleExe.GetColumnCount()):
            item = self.multipleExe.GetItem(indx, col).GetText()
            setupDict[globalSetup[col - 4]] = '"%s"' % item.strip()

        # Populate the main section of the setup script
        setupScript += _cx_Freeze_target % setupDict

        # Send a message to out fancy bottom log window
        transdict = dict(projectName=project.GetName())
        self.MainFrame.SendMessage(
            0,
            _('Setup script for "%(projectName)s" succesfully created') %
            transdict)
        return setupScript, buildDir
Exemple #5
0
    def BuildTargetClass(self, configuration, project, manifestFile, customCode, postCompile):
        """ Builds the py2app compilation script file, returning it as a string. """

        # A couple of dictionaries to populate the setup string        
        setupDict, importDict = {}, {}
        configuration = dict(configuration)
        distChoice = self.distChoice.GetValue()

        pListChoice = self.pListChoice.GetValue()
        usePListFile = True
        pListCode = {}
        
        if pListChoice:
            if "plist_code" in configuration:
                # Get the existing PList code (if any)
                pListCode = configuration["plist_code"]
                if pListCode:
                    usePListFile = False
                    plist_code = "plist_code = " + pprint.pformat(pListCode, width=100)

        # Loop over all the keys, values of the configuration dictionary        
        for key, item in configuration.items():
            if key == "dist_dir_choice":
                continue
            if key == "script":
                buildDir, scriptFile = os.path.split(item)
                item = "r'%s'"%item
            elif key == "dist_dir":
                if not item.strip() or not distChoice:
                    item = "dist"
                    if distChoice:
                        self.MainFrame.SendMessage(1, _('Empty dist_dir option. Using default value "dist"'))
            elif key in ["iconfile", "plist"]:
                if key == "plist" and not usePListFile:
                    item = "plist_code"
                else:
                    if not item.strip():
                        item = None
                    else:
                        item = "r'%s'"%item
                    
            if isinstance(self.FindWindowByName(key), wx.CheckBox):
                item = bool(int(item))

            if type(item) == ListType:
                # Terrible hack to setup correctly the string to be included
                # in the setup file
                item = setupString(key, item, True)
                
            setupDict[key] = item

        if not usePListFile:
            setupDict["plist_code"] = plist_code
        else:
            setupDict["plist_code"] = "# No code for PList"

        # Add the custom code (if any)
        setupDict["customcode"] = (customCode and [customCode.strip()] or ["# No custom code added"])[0]

        # Add the post-compilation code (if any)
        setupDict["postcompilecode"] = (postCompile and [postCompile.strip()] or ["# No post-compilation code added"])[0]
        
        # Include the GUI2Exe version in the setup script
        importDict["gui2exever"] = self.MainFrame.GetVersion()

        # Populate the "import" section
        setupScript = _py2app_imports % importDict

        # Populate the main section of the setup script            
        setupScript += _py2app_target % setupDict
        
        # Send a message to out fancy bottom log window
        transdict = dict(projectName=project.GetName())
        self.MainFrame.SendMessage(0, _('Setup script for "%(projectName)s" succesfully created')%transdict)
        return setupScript, buildDir
Exemple #6
0
    def BuildTargetClass(self, configuration, project, manifestFile,
                         customCode, postCompile):
        """ Builds the py2exe compilation script file, returning it as a string. """

        # A couple of dictionaries to populate the setup string
        setupDict, importDict = {}, {}
        configuration = dict(configuration)
        # Delete the keys we don't need
        zipChoice, distChoice = self.zipfileChoice.GetValue(
        ), self.distChoice.GetValue()
        createExe, createDll = self.createExeCheck.GetValue(
        ), self.createDllCheck.GetValue()

        del configuration["zipfile_choice"], configuration["dist_dir_choice"]
        if "create_exe" in configuration:
            del configuration["create_exe"]
        if "create_dll" in configuration:
            del configuration["create_dll"]

        useRelPath = self.MainFrame.relativePaths
        scriptFile = self.multipleExe.GetItem(0, 2).GetText()

        # Loop over all the keys, values of the configuration dictionary
        for key, item in configuration.items():
            if key == "custom_boot_script":
                # I don't know how often this option is used
                if not item:
                    item = "''"
                else:
                    item = "r'%s'" % item
            elif isinstance(self.FindWindowByName(key), wx.CheckBox):
                item = bool(int(item))

            if type(item) == ListType and key != "multipleexe":
                # Terrible hack to setup correctly the string to be included
                # in the setup file
                item = setupString(key,
                                   item,
                                   useRelPath=useRelPath,
                                   mainScript=scriptFile)

            if key == "zipfile":
                if item and item.strip() and zipChoice:
                    if (os.path.splitext(item)[1]).lower() != ".zip":
                        self.MainFrame.SendMessage(
                            1, _('zipfile does not have ".zip" extension'))
                    item = "r'%s'" % item
                else:
                    item = None
            elif key == "dist_dir":
                if item and item.strip() and distChoice:
                    item = r'%s' % item
                else:
                    item = "dist"
                    if distChoice:
                        self.MainFrame.SendMessage(
                            1,
                            _('Empty dist_dir option. Using default value "dist"'
                              ))

            setupDict[key] = item

        targetclass = ""
        baseName = "GUI2Exe_Target_%d"
        console, windows, service, com_server, ctypes_com_server = "console = [", "windows = [", \
                                                                   "service = [", "com_server = [", \
                                                                   "ctypes_com_server = ["

        for indx in xrange(self.multipleExe.GetItemCount()):

            tupleMultiple = (baseName % (indx + 1), )
            consoleOrWindows = self.multipleExe.GetItem(indx, 1).GetText()
            scriptFile = self.multipleExe.GetItem(indx, 2).GetText()
            buildDir, scriptFile = os.path.split(scriptFile)

            isSpecial = False
            realScript = scriptFile

            if consoleOrWindows in [
                    "service", "com_server", "ctypes_com_server"
            ]:
                # These things accept module *names*, not file names...
                realScript = os.path.splitext(scriptFile)[0]
                isSpecial = True

            if consoleOrWindows == "console":
                console += tupleMultiple[0] + ", "
            elif consoleOrWindows == "windows":
                windows += tupleMultiple[0] + ", "
            elif consoleOrWindows == "service":
                service += tupleMultiple[0] + ", "
            elif consoleOrWindows == "com_server":
                com_server += tupleMultiple[0] + ", "
            else:
                ctypes_com_server += tupleMultiple[0] + ", "

            tupleMultiple += (realScript, )

            for col in xrange(3, self.multipleExe.GetColumnCount()):
                item = self.multipleExe.GetItem(indx, col)
                text = item.GetText()
                if not text.strip():
                    text = os.path.splitext(scriptFile)[0]
                    self.MainFrame.SendMessage(
                        1,
                        _('Empty targetName option. Using Python script name'))
                if col == 3:
                    programName = text.strip()
                elif col == 4:
                    versionNumber = text.strip()

                tupleMultiple += (text, )

            extraKeywords = self.multipleExe.GetExtraKeywords(indx)
            if isSpecial:
                tupleMultiple += (extraKeywords +
                                  "\n    create_exe = %s, create_dll = %s" %
                                  (bool(createExe), bool(createDll)), )
            else:
                tupleMultiple += (extraKeywords, )

            if isSpecial:
                # services, com_servers and ctypes_com_server require a "modules" keyword
                py2exe_class = _py2exe_class.replace("    script = ",
                                                     "    modules = ")
            else:
                py2exe_class = _py2exe_class

            targetclass += py2exe_class % tupleMultiple

        # Add the custom code (if any)
        setupDict["customcode"] = (customCode and [customCode.strip()]
                                   or ["# No custom code added"])[0]
        # Look if the user wants to remove the "build" directory
        removeBuild = (self.MainFrame.deleteBuild and \
                       ['# Remove the build folder\nshutil.rmtree("build", ignore_errors=True)\n'] or [""])[0]

        importDict["remove_build"] = removeBuild
        # Include the GUI2Exe version in the setup script
        importDict["gui2exever"] = self.MainFrame.GetVersion()

        # Add the post-compilation code (if any)
        setupDict["postcompilecode"] = (
            postCompile and [postCompile.strip()]
            or ["# No post-compilation code added"])[0]

        # Populate the "import" section
        setupScript = _py2exe_imports % importDict

        if manifestFile:
            # Embed the manifest file
            setupDict["other_resources"] = setupDict["other_resources"] % ""
            setupScript += _manifest_template % dict(prog=programName)

        setupDict["targetclasses"] = targetclass
        setupDict["console"] = console.rstrip(", ") + "]"
        setupDict["windows"] = windows.rstrip(", ") + "]"
        setupDict["service"] = service.rstrip(", ") + "]"
        setupDict["com_server"] = com_server.rstrip(", ") + "]"
        setupDict["ctypes_com_server"] = ctypes_com_server.rstrip(", ") + "]"

        upx, inno = project.GetUseUPX("py2exe"), project.GetBuildInno("py2exe")

        if upx or inno:
            upxinno = _upx_inno % (upx, inno, programName, versionNumber)
            setupDict["upx_inno"] = upxinno
            setupDict["use_upx_inno"] = 'cmdclass = {"py2exe": Py2exe},'
        else:
            setupDict[
                "upx_inno"] = "# No custom class for UPX compression or Inno Setup script"
            setupDict["use_upx_inno"] = "# No UPX or Inno Setup"

        # Populate the main section of the setup script
        setupScript += _py2exe_target % setupDict

        if manifestFile:
            # Substitute a dummy line with the real one
            setupScript = setupScript.replace("'manifest_template'",
                                              "manifest_template")

        # Send a message to out fancy bottom log window
        transdict = dict(projectName=project.GetName())
        self.MainFrame.SendMessage(
            0,
            _('Setup script for "%(projectName)s" succesfully created') %
            transdict)
        return setupScript, buildDir
    def BuildTargetClass(self, configuration, project, manifestFile, customCode, postCompile):
        """ Builds the py2exe compilation script file, returning it as a string. """

        # A couple of dictionaries to populate the setup string        
        setupDict, importDict = {}, {}
        configuration = dict(configuration)
        # Delete the keys we don't need
        zipChoice, distChoice = self.zipfileChoice.GetValue(), self.distChoice.GetValue()
        createExe, createDll = self.createExeCheck.GetValue(), self.createDllCheck.GetValue()
        
        del configuration["zipfile_choice"], configuration["dist_dir_choice"]
        if "create_exe" in configuration:
            del configuration["create_exe"]
        if "create_dll" in configuration:
            del configuration["create_dll"]

        useRelPath = self.MainFrame.relativePaths
        scriptFile = self.multipleExe.GetItem(0, 2).GetText()
        
        # Loop over all the keys, values of the configuration dictionary        
        for key, item in configuration.items():
            if key == "custom_boot_script":
                # I don't know how often this option is used
                if not item:
                    item = "''"
                else:
                    item = "r'%s'"%item
            elif isinstance(self.FindWindowByName(key), wx.CheckBox):
                item = bool(int(item))

            if type(item) == ListType and key != "multipleexe":
                # Terrible hack to setup correctly the string to be included
                # in the setup file
                item = setupString(key, item, useRelPath=useRelPath, mainScript=scriptFile)

            if key == "zipfile":
                if item and item.strip() and zipChoice:
                    if (os.path.splitext(item)[1]).lower() != ".zip":
                        self.MainFrame.SendMessage(1, _('zipfile does not have ".zip" extension'))
                    item = "r'%s'"%item
                else:
                    item = None
            elif key == "dist_dir":
                if item and item.strip() and distChoice:
                    item = r'%s'%item
                else:
                    item = "dist"
                    if distChoice:
                        self.MainFrame.SendMessage(1, _('Empty dist_dir option. Using default value "dist"'))
            
            setupDict[key] = item

        targetclass = ""
        baseName = "GUI2Exe_Target_%d"
        console, windows, service, com_server, ctypes_com_server = "console = [", "windows = [", \
                                                                   "service = [", "com_server = [", \
                                                                   "ctypes_com_server = ["

        for indx in xrange(self.multipleExe.GetItemCount()):

            tupleMultiple = (baseName%(indx+1), )
            consoleOrWindows = self.multipleExe.GetItem(indx, 1).GetText()
            scriptFile = self.multipleExe.GetItem(indx, 2).GetText()
            buildDir, scriptFile = os.path.split(scriptFile)

            isSpecial = False
            realScript = scriptFile

            if consoleOrWindows in ["service", "com_server", "ctypes_com_server"]:
                # These things accept module *names*, not file names...
                realScript = os.path.splitext(scriptFile)[0]
                isSpecial = True
                
            if consoleOrWindows == "console":
                console += tupleMultiple[0] + ", "
            elif consoleOrWindows == "windows":
                windows += tupleMultiple[0] + ", "
            elif consoleOrWindows == "service":
                service += tupleMultiple[0] + ", "
            elif consoleOrWindows == "com_server":
                com_server += tupleMultiple[0] + ", "
            else:
                ctypes_com_server += tupleMultiple[0] + ", "

            tupleMultiple += (realScript, )
            
            for col in xrange(3, self.multipleExe.GetColumnCount()):
                item = self.multipleExe.GetItem(indx, col)
                text = item.GetText()
                if not text.strip():
                    text = os.path.splitext(scriptFile)[0]
                    self.MainFrame.SendMessage(1, _('Empty targetName option. Using Python script name'))
                if col == 3:
                    programName = text.strip()
                elif col == 4:
                    versionNumber = text.strip()
                    
                tupleMultiple += (text, )

            extraKeywords = self.multipleExe.GetExtraKeywords(indx)
            if isSpecial:
                tupleMultiple += (extraKeywords + "\n    create_exe = %s, create_dll = %s"%(bool(createExe), bool(createDll)), )
            else:
                tupleMultiple += (extraKeywords, )

            if isSpecial:
                # services, com_servers and ctypes_com_server require a "modules" keyword
                py2exe_class = _py2exe_class.replace("    script = ", "    modules = ")
            else:
                py2exe_class = _py2exe_class
                
            targetclass += py2exe_class%tupleMultiple
                

        # Add the custom code (if any)
        setupDict["customcode"] = (customCode and [customCode.strip()] or ["# No custom code added"])[0]
        # Look if the user wants to remove the "build" directory
        removeBuild = (self.MainFrame.deleteBuild and \
                       ['# Remove the build folder\nshutil.rmtree("build", ignore_errors=True)\n'] or [""])[0]
        
        importDict["remove_build"] = removeBuild
        # Include the GUI2Exe version in the setup script
        importDict["gui2exever"] = self.MainFrame.GetVersion()

        # Add the post-compilation code (if any)
        setupDict["postcompilecode"] = (postCompile and [postCompile.strip()] or ["# No post-compilation code added"])[0]
        
        # Populate the "import" section
        setupScript = _py2exe_imports % importDict

        if manifestFile:
            # Embed the manifest file                
            setupDict["other_resources"] = setupDict["other_resources"]%""
            setupScript += _manifest_template % dict(prog=programName)

        setupDict["targetclasses"] = targetclass
        setupDict["console"] = console.rstrip(", ") + "]"
        setupDict["windows"] = windows.rstrip(", ") + "]"
        setupDict["service"] = service.rstrip(", ") + "]"
        setupDict["com_server"] = com_server.rstrip(", ") + "]"
        setupDict["ctypes_com_server"] = ctypes_com_server.rstrip(", ") + "]"

        upx, inno = project.GetUseUPX("py2exe"), project.GetBuildInno("py2exe")

        if upx or inno:
            upxinno = _upx_inno%(upx, inno, programName, versionNumber)
            setupDict["upx_inno"] = upxinno
            setupDict["use_upx_inno"] = 'cmdclass = {"py2exe": Py2exe},'
        else:
            setupDict["upx_inno"] = "# No custom class for UPX compression or Inno Setup script"
            setupDict["use_upx_inno"] = "# No UPX or Inno Setup"
        
        # Populate the main section of the setup script            
        setupScript += _py2exe_target % setupDict
        
        if manifestFile:
            # Substitute a dummy line with the real one
            setupScript = setupScript.replace("'manifest_template'", "manifest_template")

        # Send a message to out fancy bottom log window
        transdict = dict(projectName=project.GetName())
        self.MainFrame.SendMessage(0, _('Setup script for "%(projectName)s" succesfully created')% transdict)
        return setupScript, buildDir