Re: comparing alternatives to py2exe

2009-11-04 Thread Rüdiger Ranft
Maxim Khitrov schrieb:

 1. I don't think cx_freeze supports single exe. I haven't even been
 able to get it to append the generated library.zip file to the
 executable using documented options. Other things like .pyd files
 always seem to be separate. At the same time, singe executables
 generated by py2exe do not always work. I have a program that works
 fine on Windows XP, Vista, and 7 if it is built under XP. However, if
 I build the exact same program under Windows 7, it no longer works on
 Vista or XP. I'm sure it has something to do with SxS or other dll
 issues.

I had similar issues with under Vista generated programs not running
under 2K (unfortunately I have to support it). This behavior came from
the .dll dependency tracking of py2exe, which included a OS .dll into
the dist output.

These are the steps I toke to find the offending .dll
* generated a flat directory (the .dll's not packed into library.zip)
  with options = { [...], 'bundle_files': 3 }
* extracted the not loadable extension from library.zip
* examined the dependencies of this module with Microsoft's
  Dependency Walker (you can find it somewhere in the MSDN)
* added the superfluous .dll to the
  options = { [...], 'dll_excludes': ['offending.dll'] } parameter

HTH
Rudi
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Win XP: How to hide command window for sub processes?

2009-11-04 Thread Rüdiger Ranft
klausfpga schrieb:
 On Oct 29, 11:25 am, Rüdiger Ranft _r...@web.de wrote:

 Thanks Ruediger,
 
 I'll try that immediately tomorrow, when working again on a windows
 host.
 
 Good to know, that the Python API supports this.
 though this feature was not that easy to be found in the doc.

Well, getting the point from subproces.py was easy. Finding the
documentation about STARTUPINFO in the MSDN was not. I better stop here
before this post turns into a rant about Mircosofts use of javascript.

bye
Rudi
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Win XP: How to hide command window for sub processes?

2009-10-29 Thread Rüdiger Ranft
klausfpga schrieb:
 Hi,
 
 I have a Python script which wants to start a subprocess and wait for
 it to finish.
 
 However I would like to have NO command window popping up during
 execution.

You need to specify the hide parameter for windows.

import subprocess
kwargs = {}
if subprocess.mswindows:
su = subprocess.STARTUPINFO()
su.dwFlags |= subprocess.STARTF_USESHOWWINDOW
su.wShowWindow = subprocess.SW_HIDE
kwargs['startupinfo'] = su
process = subprocess.Popen( (r'c:\python25\python.exe',
r'd:\projekte\bar.py'), **kwargs )

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: user authorization (with one time login) in a Python desktop application ?

2009-09-30 Thread Rüdiger Ranft
Stef Mientki schrieb:

 By making use of the one time login on windows,
 I'm not sure, but I guess the user environment variable USER  should
 hold the vald user,
 which has probably a one-to-one relation with the SID
Environment variables are *very* easy to forge. But since you use
windows, you can let windows do all the security stuff for you. Since u
use sqlite, I guess that the database is stored on a file on a disk. You
can use the file permission to give access only to the users permitted
to access the file.

But when you want to separate access at dataset/column/row level, then
sqlite is not the best tool, since every user can open the database file
with an other sqlite tool. Encryption will only take more time for rogue
users, since the key needs to be stored in your application, and can be
read by the user. I would recommend a real database server in this
case, so the permission checks are out of the reach of the users. When u
have a kerberos or active directory environment, some servers even can
use kerberos to get the user name from the client.

bye
Rudi
-- 
http://mail.python.org/mailman/listinfo/python-list


Weird lambda behavior

2009-04-22 Thread Rüdiger Ranft
Hi all,

I want to generate some methods in a class using setattr and lambda.
Within each generated function a name parameter to the function is
replaced by a string constant, to keep trail which function was called.
The problem I have is, that the substituted name parameter is not
replaced by the correct name of the function, but by the last name the
for loop has seen.

import unittest

class WidgetDummy:
'''This class records all calls to methods to an outer list'''

def __init__( self, name, calls ):
'''name is the name of the object, which gets included into a
call record. calls is the list where the calls are appended.'''
self.name = name
self.calls = calls
for fn in ( 'Clear', 'Append', 'foobar' ):
func = lambda *y,**z: self.__callFn__( fn, y, z )
setattr( self, fn, func )

def __callFn__( self, fnName, *args ):
'''Add the function call to the call list'''
self.calls.append( ( self.name, fnName, args ) )

class Testcase( unittest.TestCase ):
def testFoo( self ):
calls = []
wd = WidgetDummy( 'foo', calls )
wd.Append( 23 )
self.assertEqual( [ ( 'foo', 'Append', ( 23, {} ) ) ], calls )

unittest.main()

-- 
GPG encrypted mails preferred.
GPG verschlüsselte Mails bevorzugt.
--- http://chaosradio.ccc.de/media/ds/ds085.pdf Seite 20 
--
http://mail.python.org/mailman/listinfo/python-list


Re: Re: Weird lambda behavior

2009-04-22 Thread Rüdiger Ranft
Chris Rebert schrieb:
 On Wed, Apr 22, 2009 at 4:50 AM, Rüdiger Ranft _r...@web.de wrote:
 Hi all,

 I want to generate some methods in a class using setattr and lambda.
 Within each generated function a name parameter to the function is
 replaced by a string constant, to keep trail which function was called.
 The problem I have is, that the substituted name parameter is not
 replaced by the correct name of the function, but by the last name the
 for loop has seen.

 import unittest

 class WidgetDummy:
'''This class records all calls to methods to an outer list'''

def __init__( self, name, calls ):
'''name is the name of the object, which gets included into a
call record. calls is the list where the calls are appended.'''
self.name =ame
self.calls =alls
for fn in ( 'Clear', 'Append', 'foobar' ):
func =ambda *y,**z: self.__callFn__( fn, y, z )
setattr( self, fn, func )
 
 Common wart to run into as of late. fn (in the lambda) doesn't get
 evaluated until the call-time of the lambda, by which point the loop
 has finished and the loop variable has been changed to its final
 value, which is used by the lambda.

Doh! I wasn't aware of the point when the lambda expression is evaluated.

 Workaround:
 #exact syntax may vary with your version of Python, but you should be
 able to get the idea
 func =ambda *y,**z, fn=fn: self.__callFn__( fn, y, z )
 
 The default argument value gets evaluated at definition-time, thus
 forcing the right value of fn within the function.

Thank you, I replaced the direct assignment with a proxy function call,
and now it works.

def __init__( self, name, calls ):
self.name = name
self.calls = calls

def forceEval(x):
setattr( self, fn, lambda *y,**z: self.__callFn__(x, y, z) )

for fn in ( 'Clear', 'Append', 'foobar' ):
forceEval(fn)

-- 
GPG encrypted mails preferred.
GPG verschlüsselte Mails bevorzugt.
--- http://chaosradio.ccc.de/media/ds/ds085.pdf Seite 20 

--
http://mail.python.org/mailman/listinfo/python-list


get text from rogramms runn by subprocess.Popen immediatetly

2009-04-16 Thread Rüdiger Ranft
Hi all,

I need to call some programms and catch their stdout and stderr streams.
While the Popen class from subprocess handles the call, I get the
results of the programm not until the programm finishes. Since the
output of the programm is used to generate a progress indicator, I need
a way to acces the values written to stdout/stderr as fast as possible.

Beneath is a test which shows what I did

TIA
Rudi

8---8---8-- iodummy.cpp -8---8---
#include iostream
#include unistd.h

int main()
{
for( int i = 0; i  10; i++ )
{
std::cerr  i  std::endl;
sleep(2);
}
}

from subprocess import Popen, PIPE
from time import sleep

p = Popen('./iodummy',stdin=PIPE, stdout=PIPE, stderr=PIPE)
sleep(3)
# now I expect '0\n1\n' in stderr, but read() blocks until
# the end of iodummy.
print p.stderr.read()
p.wait()

-- 
GPG encrypted mails preferred.
GPG verschlüsselte Mails bevorzugt.
--- http://chaosradio.ccc.de/media/ds/ds085.pdf Seite 20 



signature.asc
Description: OpenPGP digital signature
--
http://mail.python.org/mailman/listinfo/python-list


Re: Re: get text from rogramms runn by subprocess.Popen immediatetly

2009-04-16 Thread Rüdiger Ranft
Diez B. Roggisch schrieb:
 Rüdiger Ranft schrieb:
 Hi all,

 I need to call some programms and catch their stdout and stderr streams.
 While the Popen class from subprocess handles the call, I get the
 results of the programm not until the programm finishes. Since the
 output of the programm is used to generate a progress indicator, I need
 a way to acces the values written to stdout/stderr as fast as possible.
 
 Use the communicate()-method of Popen-objects.

It gives the same behavior, the first call to communicate gets all text,
the second gives a closed handle error :(. I also tried
p.communicate(''), which gives the same as p.communicate(None) result.

bye
Rudi

cat run.py
from subprocess import Popen, PIPE
from time import sleep

p = Popen('./iodummy',stdin=PIPE, stdout=PIPE, stderr=PIPE, bufsize=2)
sleep(3)
# now I expect '0\n1\n' in stderr
print 'Point1:', p.communicate(None)
sleep(3)
print 'Point2:', p.communicate(None)
p.wait()

python run.py
Point1: ('', '0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n')
Point2:
Traceback (most recent call last):
  File run.py, line 9, in ?
print 'Point2:', p.communicate('')
  File /usr/lib/python2.4/subprocess.py, line 1028, in communicate
self.stdin.flush()
ValueError: I/O operation on closed file

-- 
GPG encrypted mails preferred.
GPG verschlüsselte Mails bevorzugt.
--- http://chaosradio.ccc.de/media/ds/ds085.pdf Seite 20 
--
http://mail.python.org/mailman/listinfo/python-list