示例#1
0
def pyinstMakespec(scripts, noupx=False, strip=False, console=True,
                   icon_file=None, pathex=[], specpath=None):
    '''
    An interface for direct access to PyInstaller's makespec function

    @author: Eric Ball
    @param scripts: A list of python scripts to make a specfile for
    @param noupx: Do not use UPX even if it is available
    @param strip: Apply a symbol-table strip to the executable and shared libs
    @param console: Open a console window for standard i/o
    @param icon_file: icon to be used for the completed program
    @param pathex: A path to search for imports (like using PYTHONPATH)
    @param specpath: Folder to store the generated spec file (default: CWD)
    @return: Output of PyInstaller.makespec
    @note: PyInstaller.makespec accepts further options,
           which may need to be added in future versions
    '''
    # specpath default cannot be reliably set here; os.getcwd() will return dir
    # of macbuildlib, not necessarily the current working dir of the calling
    # script. Therefore, if it is not specified, leave blank and let
    # PyInstaller set default.
    try:
        if specpath:
            return makespec.main(scripts, noupx=noupx, strip=strip,
                                 console=console, icon_file=icon_file,
                                 pathex=pathex, specpath=specpath)
        else:
            return makespec.main(scripts, noupx=noupx, strip=strip,
                                 console=console, icon_file=icon_file,
                                 pathex=pathex)
    except Exception:
        raise
示例#2
0
def create(scripts, debug, verbose, workdir, ascii=0):
    infos = []  # (path, module, klasses)
    for script in scripts:
        infos.append(analscriptname(script))
    if not os.path.exists(workdir):
        os.makedirs(workdir)
    outfnm = 'drive%s.py' % infos[0][1]
    outfnm = os.path.join(workdir, outfnm)
    outf = open(outfnm, 'w')
    klassspecs = []
    modimports = []
    flags = 'debug=%s, quiet=%s' % (debug, not verbose)
    paths = []
    for path, module, klasses in infos:
        if path:
            paths.append(path)
        modimports.append("import %s" % (module,))
        for klass in klasses:
            klassspecs.append("%s.%s" % (module, klass))
    for i in range(len(paths)):
        path = paths[i]
        paths[i] = win32api.GetShortPathName(os.path.normpath(path))
    modimports = '\n'.join(modimports)
    klassspecs = ', '.join(klassspecs)
    d = { 'modules':modimports,
          'klasses':klassspecs,
          }
    outf.write( tmplt % d )
    outf.close()
    print "**********************************"
    print "Driver script %s created" % outfnm
    specfnm = makespec.main([outfnm], console=debug, debug=debug,
                            workdir=workdir, pathex=paths, comserver=1, ascii=ascii)
    print "Spec file %s created" % specfnm
示例#3
0
    def run_makespec(opts, args):
        # Split pathex by using the path separator
        temppaths = opts.pathex[:]
        opts.pathex = []
        for p in temppaths:
            opts.pathex.extend(p.split(os.pathsep))

        spec_file = _pyi_makespec.main(args, **opts.__dict__)
        log.info('wrote %s' % spec_file)
示例#4
0
    def run_makespec(opts, args):
        # Split pathex by using the path separator
        temppaths = opts.pathex[:]
        opts.pathex = []
        for p in temppaths:
            opts.pathex.extend(p.split(os.pathsep))

        spec_file = _pyi_makespec.main(args, **opts.__dict__)
        log.info('wrote %s' % spec_file)
示例#5
0
def pyinstMakespec(scripts,
                   noupx=False,
                   strip=False,
                   console=True,
                   icon_file=None,
                   pathex=[],
                   specpath=None):
    '''
    An interface for direct access to PyInstaller's makespec function

    @author: Eric Ball
    @param scripts: A list of python scripts to make a specfile for
    @param noupx: Do not use UPX even if it is available
    @param strip: Apply a symbol-table strip to the executable and shared libs
    @param console: Open a console window for standard i/o
    @param icon_file: icon to be used for the completed program
    @param pathex: A path to search for imports (like using PYTHONPATH)
    @param specpath: Folder to store the generated spec file (default: CWD)
    @return: Output of PyInstaller.makespec
    @note: PyInstaller.makespec accepts further options,
           which may need to be added in future versions
    '''
    # specpath default cannot be reliably set here; os.getcwd() will return dir
    # of macbuildlib, not necessarily the current working dir of the calling
    # script. Therefore, if it is not specified, leave blank and let
    # PyInstaller set default.
    try:
        if specpath:
            return makespec.main(scripts,
                                 noupx=noupx,
                                 strip=strip,
                                 console=console,
                                 icon_file=icon_file,
                                 pathex=pathex,
                                 specpath=specpath)
        else:
            return makespec.main(scripts,
                                 noupx=noupx,
                                 strip=strip,
                                 console=console,
                                 icon_file=icon_file,
                                 pathex=pathex)
    except Exception:
        raise
示例#6
0
def pack(
        scripts        = [],
        import_base    = None,
        hiddenimports  = [],
        hookspath      = [],
        name           = None,
        out_path       = None,
        force          = True,
        datas          = []
):
    curr_path = os.getcwd()

    if out_path is None:
        out_path = curr_path

    for i in range(len(hookspath)):
        hookspath[i] = os.path.abspath(hookspath[i])

    for i in range(len(scripts)):
        scripts[i] = os.path.abspath(scripts[i])

    for i in range(len(datas)):
        datas[i] = os.path.abspath(datas[i])

    out_path    = os.path.abspath(out_path)
    import_base = os.path.abspath(import_base)

    REMOVE_DIR(os.path.join(out_path,'build'))
    REMOVE_DIR(os.path.join(out_path,'dist'))

    specfnm = makespec.main(
        scripts        = scripts,
        name           = name       ,
        onefile        = 0          ,
        console        = True       ,
        debug          = False      ,
        strip          = 0          ,
        noupx          = 0          ,
        comserver      = 0          ,
        workdir        = out_path   ,
        pathex         = [ import_base, out_path, curr_path ],
        version_file   = None       ,
        icon_file      = None       ,
        manifest       = None       ,
        resources      = []         ,
        crypt          = None       ,
        hiddenimports  = hiddenimports,
        hookspath      = hookspath
    )
    print specfnm
    __add_datas(specfnm,datas)

    sys.argv = ['myself']
    sys.argv.append(r'--buildpath="%s"' % os.path.join(out_path,'build'))
    sys.argv.append(specfnm)

    #import PyInstaller
    #import utils.Build

    builder = os.path.join(PYINSTALLER_PATH,'pyinstaller.py')
    cmd = r'python "%s" --buildpath="%s" "%s"' % (builder,os.path.join(out_path,'build'),specfnm)
    print cmd
    if os.system(cmd) == 0:
        print "== ok ======================="