py2exe vs. winPython
James J. Besemer
jb at cascade-sys.com
Tue Oct 8 15:49:57 EDT 2002
The rather trivial script, below, fails pitifully on a windows 98 system
with the following message:
findfonts > c:/temp/fontdata
Traceback (most recent call last):
File "<string>", line 31, in ?
pywintypes.api_error: (120, 'OpenThreadToken', 'This function is only valid in Win32 mode.')
I don't get it. Win98 is win32 based, right?
This was supposed to be a trivial little, knock-off script for a client
to catalog fonts on his computers. Far as I understood things, it
should just work. It DOES work fine on XP and NT 4.0.
I need the py2exe functionality, as it's not practical or at all
desirable for the client to install python on all his machines just to
gather these statistics.
Any and all help will be appreciated.
Code was built with Python 2.2.1 (#34, Apr 9 2002, 19:34:33) [ MSC 32
bit (Intel)] on win32
I'm using py2exe-0.3.3
------ py2exe command -------
python setup.py py2exe
----- begin setup.py for py2exe -------
from distutils.core import setup
import py2exe
setup(
name="findfonts",
scripts=["findfonts.py"]
)
----- begin findfonts.py script ------
import os, sys, os.path
import string
import re
import time
import win32api
import win32con
import win32gui
import win32ui
WINDIR = win32api.GetWindowsDirectory()
FONTDIR = os.path.join( WINDIR, "Fonts" )
maj, min, bld, pid, etc = win32api.GetVersionEx()
PlatformID = {
win32con.VER_PLATFORM_WIN32s: "Win32S",
win32con.VER_PLATFORM_WIN32_WINDOWS: "Win32",
win32con.VER_PLATFORM_WIN32_NT: "NT",
}
if pid in PlatformID.keys():
pid = PlatformID[ pid ]
else:
pid = "WinID#%d" % pid
Version = pid + " Ver. %d.%d, build %d, %s" % (maj, min, bld, etc)
timestamp = time.ctime()
domain = win32api.GetDomainName()
computer = win32api.GetComputerName()
drives = win32api.GetLogicalDriveStrings().split('\0' )
info = win32api.GetSystemInfo()
print timestamp
print Version
print "oemid:",info[0], "cpus:", info[5], "cpu:", info[6],
print "proc level", info[8][0], "rev:", info[8][1]
print domain, computer
print "drives:",
for d in drives:
print d,
print
if 1:
print "Registered Fonts:",
ifd = os.popen( "enumfonts.exe" )
fonts = ifd.readlines()
ifd.close()
print "[", len( fonts ), "fonts ]"
for font in fonts:
print " ", font.strip()
def listdir( dir ):
if not os.path.isdir( dir ):
print dir, "-- DOES NOT EXIST!"
else:
print dir + ":",
if dir.lower() == FONTDIR.lower():
print " [ SYSTEM DIR ]"
else:
print
files = os.listdir( dir )
for file in files:
print " ", file
# listdir( FONTDIR )
otherdirs = []
count = 0
def visit( arg, dirname, names ):
global count
def isfontdir( name ):
name = name.lower()
dirs = re.split( "[/\\\\]", name )
return "fonts" in dirs
def countfiles( names ):
count = 0
for name in names:
fn = os.path.join( dirname, name )
if os.path.isfile( fn ):
count += 1
return count
if isfontdir( dirname ):
fontcount = countfiles( names )
if fontcount:
print "\nFOUND:", dirname, "[", fontcount, "fonts ]"
otherdirs.append( dirname )
count += 1
if count % 10 == 0:
sys.stdout.write( "." )
os.path.walk( "C:\\", visit, 0 )
print
if 1:
for dir in otherdirs:
listdir( dir )
----- end script --------
--
James J. Besemer 503-280-0838 voice
2727 NE Skidmore St. 503-280-0375 fax
Portland, Oregon 97211-6557 mailto:jb at cascade-sys.com
http://cascade-sys.com
More information about the Python-list
mailing list