473,721 Members | 2,254 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.GetFi leVersion_ , 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=('C omments','Inter nalName','Produ ctName',
'CompanyName',' LegalCopyright' ,'ProductVersio n',
'FileDescriptio n','LegalTradem arks','PrivateB uild',
'FileVersion',' OriginalFilenam e','SpecialBuil d')
##fname = os.environ["comspec"]
fname = sys.argv[0]
d=win32api.GetF ileVersionInfo( fname, '\\')
## backslash as parm returns dictionary of numeric info corresponding to
VS_FIXEDFILEINF O 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. GetFileVersionI nfo(fname, '\\VarFileInfo\ \Translation')
## \VarFileInfo\Tr anslation 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'\\St ringFileInfo\\% 04X%04X\\%s' %(lang,codepage ,ver_strin
g)
## print str_info
print ver_string, win32api.GetFil eVersionInfo(fn ame, 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__.u pdate(kw)
# for the versioninfo resources
self.version = "0.5.0"
self.company_na me = "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.man ifest, and copy it with the data_files option into
# the dist-dir.
#
manifest_templa te = '''
<?xml version="1.0" encoding="UTF-8" standalone="yes "?>
<assembly xmlns="urn:sche mas-microsoft-com:asm.v1" manifestVersion ="1.0">
<assemblyIdenti ty
version="5.0.0. 0"
processorArchit ecture="x86"
name="%(prog)s"
type="win32"
/>
<description>%( prog)s Program</description>
<dependency>
<dependentAssem bly>
<assemblyIdenti ty
type="win32"
name="Microsoft .Windows.Common-Controls"
version="6.0.0. 0"
processorArchit ecture="X86"
publicKeyToken= "6595b64144ccf1 df"
language="*"
/>
</dependentAssemb ly>
</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_templa te %
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_templa te %
dict(prog="test _wx"))],
dest_base = "test_wx_consol e")

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

# what to build
script = "getfilever.py" ,
other_resources = [(RT_MANIFEST, 1, manifest_templa te %
dict(prog="getf ilever"))],
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.p y",
)

############### ############### ############### ############### ####
# 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.serve rs.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 5721
"Werner Merkl" <we**********@f ujitsu-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.GetFi leVersion_ , 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\resource s\VersionInfo.p y.
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 GetFileVersionI nfo, everything shows up.
Roger

"Thomas Heller" <th*****@python .net> wrote in message
news:ma******** *************** *************** @python.org...
"Werner Merkl" <we**********@f ujitsu-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.GetFi leVersion_ , 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\resource s\VersionInfo.p y.
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 GetFileVersionI nfo, everything shows up.
Roger


Cool. So it seems this fix to py2exe\resource s\VersionInfo.p y makes
everything fine: Replace this line
VarFileInfo(0x0 40904B0)])
with this:
VarFileInfo(0x0 4B00409)])

Thanks, Thomas
Jul 18 '05 #4

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

Similar topics

2
17708
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
3671
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 comp.lang.python (or should a py2exe mailing list be created?). And I'm cc'ing to python-list. > > I need to ship a Windows service in py2exe, but I also want a
1
3870
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 different module, and now it will compile but not run again. I know that functionality in this area is not fully supported yet, but there has to be someone out there that has got this to work. I am using Python2.3, with py2exe 0.4.2, and win32all 159....
10
4024
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 windows gui? TIA Al
5
3979
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 problems. I want to be able to distribute this program using py2exe, but I am having some problems. I am using a simple setup.py like in the documentation for the py2exe tool and everything compiles ok, except that when I run the exe, I get an...
10
2263
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 requiring a python installation. News Python 2.3 is required, because the new zipimport feature is used.
1
2562
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 tested it with the setup.cfg, but that doesn't work. I alwayse became the errormessage: error: error in setup.cfg: command 'py2exe' has no such option 'version_legalcopyright' until I've deleted all options.
0
1560
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 dist ? I want to structure my projects like this:
9
3639
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 cannot require everyone to install python in their machines, so I was thinking that Py2Exe would help on that. The support tools I write are mostly command line driven (no GUI), but in the future, I would like to write some expert applications that...
0
8840
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9367
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9215
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9131
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9064
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6669
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4484
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4753
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2130
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.