473,323 Members | 1,551 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

py2exe win32all: Can write, but not read FileVersion ...

Hi,
Python is really great, for small to big programs. For my colleagues and
some circumstances I sometimes need to "compile" a script using py2exe.

Cause I use Windows, I like to use the (Windows) ability, to add some
version infos, comments, etc to the exe file.

If I use explorer to check, these properties are visible and correct.
But if I use _win32api.GetFileVersion_ , I get nothing for the language
dependent resource...

At the end you may see my example source code, which is almost the
original code from win32all and py2exe. Just compile and start.

BTW: I found the same behavior for (most/all?) .pyd from win32all
and for PythonWin.exe.
Any idea?
Thanks in advance
Werner Merkl
Versions I use:
- Python 2.3.3
- win32all 163
- py2exe 0.5.0

Source code:
------------ getfileversion.py ----------------------------------
import os, win32api, sys

ver_strings=('Comments','InternalName','ProductNam e',
'CompanyName','LegalCopyright','ProductVersion',
'FileDescription','LegalTrademarks','PrivateBuild' ,
'FileVersion','OriginalFilename','SpecialBuild')
##fname = os.environ["comspec"]
fname = sys.argv[0]
d=win32api.GetFileVersionInfo(fname, '\\')
## backslash as parm returns dictionary of numeric info corresponding to
VS_FIXEDFILEINFO struc
for n, v in d.items():
print n, v

print "%s: %d.%d.%d.%d" % (fname,d['FileVersionMS'] / (256*256),
d['FileVersionMS'] % (256*256), d['FileVersionLS'] / (256*256),
d['FileVersionLS'] % (256*256))

pairs=win32api.GetFileVersionInfo(fname, '\\VarFileInfo\\Translation')
## \VarFileInfo\Translation returns list of available (language, codepage)
pairs that can be used to retreive string info
## any other must be of the form \StringfileInfo\%04X%04X\parm_name, middle
two are language/codepage pair returned from above
for lang, codepage in pairs:
print 'lang: ', lang, 'codepage:', codepage
for ver_string in ver_strings:
str_info=u'\\StringFileInfo\\%04X%04X\\%s' %(lang,codepage,ver_strin
g)
## print str_info
print ver_string, win32api.GetFileVersionInfo(fname, str_info)

------------ setup.py ----------------------------------
# A setup script showing advanced features.
#
# Note that for the NT service to build correctly, you need at least
# win32all build 161, for the COM samples, you need build 163.
# Requires wxPython, and Tim Golden's WMI module.

from distutils.core import setup
import py2exe
import sys

# If run without args, build executables, in quiet mode.
if len(sys.argv) == 1:
sys.argv.append("py2exe")
sys.argv.append("-q")

class Target:
def __init__(self, **kw):
self.__dict__.update(kw)
# for the versioninfo resources
self.version = "0.5.0"
self.company_name = "No Company"
self.copyright = "no copyright"
self.name = "py2exe sample files"

################################################## ##############
# A program using wxPython

# The manifest will be inserted as resource into test_wx.exe. This
# gives the controls the Windows XP appearance (if run on XP ;-)
#
# Another option would be to store it in a file named
# test_wx.exe.manifest, and copy it with the data_files option into
# the dist-dir.
#
manifest_template = '''
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity
version="5.0.0.0"
processorArchitecture="x86"
name="%(prog)s"
type="win32"
/>
<description>%(prog)s Program</description>
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="X86"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>
</assembly>
'''

RT_MANIFEST = 24

test_wx = Target(
# used for the versioninfo resource
description = "A sample GUI app",

# what to build
script = "test_wx.py",
other_resources = [(RT_MANIFEST, 1, manifest_template %
dict(prog="test_wx"))],
## icon_resources = [(1, "icon.ico")],
dest_base = "test_wx")

test_wx_console = Target(
# used for the versioninfo resource
description = "A sample GUI app with console",

# what to build
script = "test_wx.py",
other_resources = [(RT_MANIFEST, 1, manifest_template %
dict(prog="test_wx"))],
dest_base = "test_wx_console")

getfilever = Target(
# used for the versioninfo resource
description = "test version",

# what to build
script = "getfilever.py",
other_resources = [(RT_MANIFEST, 1, manifest_template %
dict(prog="getfilever"))],
dest_base = "getfilever")

################################################## ##############
# A program using early bound COM, needs the typelibs option below
test_wmi = Target(
description = "Early bound COM client example",
script = "test_wmi.py",
)

################################################## ##############
# a NT service, modules is required
myservice = Target(
# used for the versioninfo resource
description = "A sample Windows NT service",
# what to build. For a service, the module name (not the
# filename) must be specified!
modules = ["MyService"]
)

################################################## ##############
# a COM server (exe and dll), modules is required
#
# If you only want a dll or an exe, comment out one of the create_xxx
# lines below.

interp = Target(
description = "Python Interpreter as COM server module",
# what to build. For COM servers, the module name (not the
# filename) must be specified!
modules = ["win32com.servers.interp"],
## create_exe = False,
## create_dll = False,
)

################################################## ##############
# COM pulls in a lot of stuff which we don't want or need.

excludes = ["pywin", "pywin.debugger", "pywin.debugger.dbgcon",
"pywin.dialogs", "pywin.dialogs.list"]

setup(
options = {"py2exe": {"typelibs":
# typelib for WMI
[('{565783C6-CB41-11D1-8B02-00600806D9B6}', 0, 1,
2)],
# create a compressed zip archive
"compressed": 1,
"optimize": 2,
"packages": ["encodings"],
"excludes": excludes}},
# The lib directory contains everything except the executables and the
python dll.
# Can include a subdirectory name.
zipfile = "lib/shared.zip",

console = [getfilever]
## service = [myservice],
## com_server = [interp],
## console = [test_wx_console, test_wmi],
## windows = [test_wx],
)


Jul 18 '05 #1
3 5676
"Werner Merkl" <we**********@fujitsu-siemens.com> writes:
Hi,
Python is really great, for small to big programs. For my colleagues and
some circumstances I sometimes need to "compile" a script using py2exe.

Cause I use Windows, I like to use the (Windows) ability, to add some
version infos, comments, etc to the exe file.

If I use explorer to check, these properties are visible and correct.
But if I use _win32api.GetFileVersion_ , I get nothing for the language
dependent resource...

At the end you may see my example source code, which is almost the
original code from win32all and py2exe. Just compile and start.
This is a known (to me, at least) bug: the version info resources are
probably not correct - they also don't show up on win98. But I never
cared enough to fix that. It would be great if someone could do this,
the code is all in Python, in py2exe\resources\VersionInfo.py.
BTW: I found the same behavior for (most/all?) .pyd from win32all
and for PythonWin.exe.


That may, or may not, be related. I have no idea.

Thomas
Jul 18 '05 #2
The language and codepage are getting reversed in the resource created.
If you switch them in the call to GetFileVersionInfo, everything shows up.
Roger

"Thomas Heller" <th*****@python.net> wrote in message
news:ma**************************************@pyth on.org...
"Werner Merkl" <we**********@fujitsu-siemens.com> writes:
Hi,
Python is really great, for small to big programs. For my colleagues and
some circumstances I sometimes need to "compile" a script using py2exe.

Cause I use Windows, I like to use the (Windows) ability, to add some
version infos, comments, etc to the exe file.

If I use explorer to check, these properties are visible and correct.
But if I use _win32api.GetFileVersion_ , I get nothing for the language
dependent resource...

At the end you may see my example source code, which is almost the
original code from win32all and py2exe. Just compile and start.


This is a known (to me, at least) bug: the version info resources are
probably not correct - they also don't show up on win98. But I never
cared enough to fix that. It would be great if someone could do this,
the code is all in Python, in py2exe\resources\VersionInfo.py.
BTW: I found the same behavior for (most/all?) .pyd from win32all
and for PythonWin.exe.


That may, or may not, be related. I have no idea.

Thomas

Jul 18 '05 #3
[about version resources created by py2exe]

"Roger Upole" <ru****@hotmail.com> writes:
The language and codepage are getting reversed in the resource created.
If you switch them in the call to GetFileVersionInfo, everything shows up.
Roger


Cool. So it seems this fix to py2exe\resources\VersionInfo.py makes
everything fine: Replace this line
VarFileInfo(0x040904B0)])
with this:
VarFileInfo(0x04B00409)])

Thanks, Thomas
Jul 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: x-herbert | last post by:
Hi, I have a small test to "compile" al litle script as a WMI-Tester. The script include a wmi-wrapper and "insert" the Win32-modeles. here the code: my "WMI-Tester.py" ----- import wmi
2
by: Thomas Heller | last post by:
"Brad Clements" <bkc@murkworks.com> writes: > Once again I apologize for posting this py2exe question in the ctypes list. ;-) In the long run, this will be the wrong forum. I suggest...
1
by: Marc | last post by:
Hello, I've fiddled with this for quite a while and thought I had the problem solved. I had a version that would successfully compile and run. But then I had to change the code to use a...
10
by: achrist | last post by:
The py2exe says that a console app should have the --console option and a windows app should have the --windows option. What is the way to py2exe a python program that uses both console and...
5
by: Brian Hlubocky | last post by:
I'm have a fairly simple (in terms of COM) python program that pulls info from an Access database and creates Outlook contacts from that information. It uses wxPython for gui and works without...
10
by: Thomas Heller | last post by:
**py2exe 0.5.0** (finally) released =================================== py2exe is a Python distutils extension which converts python scripts into executable windows programs, able to run without...
1
by: klaus.roedel | last post by:
Hi @all, I've implementet a simple setup script for my application with py2exe. The setup.py works fine, but now I want to add version resources to my *.exe-file. But how can I do it? I've...
0
by: Durumdara | last post by:
Hi ! I have an application that I compile to exe. 1.) I want to compile main.ico into exe, or int zip. Can I do it ? 2.) Can I compile the result to my specified directory, not into the...
9
by: Isaac Rodriguez | last post by:
Hi, I am looking for feedback from people that has used or still uses Py2Exe. I love to program in python, and I would like to use it to write support tools for our development team, but I...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.