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, 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 ofn is None:
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 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
评论列表
文章目录