コード例 #1
0
ファイル: win32verstamp.py プロジェクト: snhynb/Pywin32
def stamp(pathname, options):
    # For some reason, the API functions report success if the file is open
    # but doesnt work!  Try and open the file for writing, just to see if it is
    # likely the stamp will work!
    try:
        f = open(pathname, "a+b")
        f.close()
    except IOError as why:
        print("WARNING: File %s could not be opened - %s" % (pathname, why))

    ver = options.version
    try:
        bits = [int(i) for i in ver.split(".")]
        vmaj, vmin, vsub, vbuild = bits
    except (IndexError, TypeError, ValueError):
        raise ValueError("--version must be a.b.c.d (all integers) - got %r" %
                         ver)

    ifn = options.internal_name
    if not ifn:
        ifn = os.path.basename(pathname)
    ofn = options.original_filename
    if not ofn:
        ofn = os.path.basename(pathname)

    sdata = {
        'Comments': options.comments,
        'CompanyName': options.company,
        'FileDescription': options.description,
        'FileVersion': ver,
        'InternalName': ifn,
        'LegalCopyright': options.copyright,
        'LegalTrademarks': options.trademarks,
        'OriginalFilename': ofn,
        'ProductName': options.product,
        'ProductVersion': ver,
    }
    vdata = {
        'Translation': struct.pack('hh', 0x409, 1252),
    }
    is_dll = options.dll
    if is_dll is None:
        is_dll = os.path.splitext(pathname)[1].lower() in '.dll .pyd'.split()
    is_debug = options.debug
    if is_debug is None:
        is_debug = os.path.splitext(pathname)[0].lower().endswith("_d")
    # convert None to blank strings
    for k, v in list(sdata.items()):
        if v is None:
            sdata[k] = ""
    vs = VS_VERSION_INFO(vmaj, vmin, vsub, vbuild, sdata, vdata, is_debug,
                         is_dll)

    h = BeginUpdateResource(pathname, 0)
    UpdateResource(h, 16, 1, vs)
    EndUpdateResource(h, 0)

    if options.verbose:
        print("Stamped:", pathname)
コード例 #2
0
    def fs_strip_windows_manifest(self, aFile ):
        try:
            from win32api import BeginUpdateResource, UpdateResource, EndUpdateResource

            data = None
            handle = BeginUpdateResource( aFile, 0 )
            UpdateResource( handle, 24, 1, data, 1033 )
            EndUpdateResource( handle, 0 )
        except:
            pass
コード例 #3
0
    }
    is_dll = options.dll
    if is_dll is None:
        is_dll = os.path.splitext(pathname)[1].lower() in '.dll .pyd'.split()
    is_debug = options.debug
    if is_debug is None:
        is_debug = os.path.splitext(pathname)[0].lower().endswith("_d")
    # convert None to blank strings
    for k, v in sdata.items():
        if v is None:
            sdata[k] = ""
    vs = VS_VERSION_INFO(vmaj, vmin, vsub, vbuild, sdata, vdata, is_debug,
                         is_dll)

    h = BeginUpdateResource(pathname, 0)
    UpdateResource(h, 16, 1, vs)
    EndUpdateResource(h, 0)

    if options.verbose:
        print "Stamped:", pathname


if __name__ == '__main__':
    parser = optparse.OptionParser("%prog [options] filespec ...",
                                   description=__doc__)

    parser.add_option("-q",
                      "--quiet",
                      action="store_false",
                      dest="verbose",
                      default=True,