Re: [Zope] external method and forms
At last I find and change everything.Now it looks like this: --MY DTML DOCUMENT- form action= method=postbr / pbr KULLANICI ADI br input type=text name=name pbr SIFREbr input type=text name=sifre pbr SIFRE YENIDENbr input type=text name=sifret input type=submit name=formParams:action value=degistir /form MY EXTERNAL PYTHON METHOD-- import crypt import MySQLdb def formParams(self,name,sifre,sifret): conn = MySQLdb.connect(host=localhost, user = , passwd = , db = xxxzzz) cursor = conn.cursor() self.name=name self.sifre=sifre self.sifret=sifret if sifre == sifret: cryp = crypt.crypt(sifre,'mysecret') cursor.execute(update mytable set PASS_WORD=%s where USERNAME=%s,(cryp,name)) return BASARI ILE DEGISTIRILDI else: return Sifreler uyusmadi.Tekrar deneyiniz. cursor=conn.close() On Mon, Jan 7, 2013 at 11:16 PM, Mike Cullerton pl...@bakednotfried.comwrote: It looks like you missed some quotes. this line cryp = crypt.crypt(sifre,'mysecret') should probably be cryp = crypt.crypt('sifre','mysecret') Mike On Jan 7, 2013, at 1:33 PM, murat bilal murat.bi...@gmail.com wrote: Hi, I try to make a simple paswd recovery page for my site.Username and password stored in mysql db.My DTML document is: form action=deg method=POST h2Şifre değiştirme sayfasına hoşgeldinizh2 br KULLANICI ADI: brinput type=text name=name:ignore_empty/br pbr ŞİFRE: br input type=text name=sifre:ignore_empty/br pbr ŞİFRE TEKRAR: br input type=text name=sifret:ignore_empty/br pbr input type=submit value=yenile align=center dtml-var deg(REQUEST) /form and my external python method is as follows: import crypt import MySQLdb conn = MySQLdb.connect(host=localhost, user = r, passwd = , db = ) cursor = conn.cursor() #return context.responseMessage() def deg(self): cryp = crypt.crypt(sifre,'mysecret') if request.form[sifre] == request.form[sifret]: cursor.execute(update mytable set PASS_WORD=%s where USERNAME=%s,(cryp,name)) print SUCCESS else: print please try again! cursor=conn.close() But when i tested from DTML Document I got this error *Error Type: NameError* *Error Value: global name 'sifre' is not defined* Can anybody help me? Regards MuratB ___ Zope maillist - Zope@zope.org https://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - https://mail.zope.org/mailman/listinfo/zope-announce https://mail.zope.org/mailman/listinfo/zope-dev ) ___ Zope maillist - Zope@zope.org https://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - https://mail.zope.org/mailman/listinfo/zope-announce https://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] external method
Garry Saddington wrote: I have the following external method to back up a postgres database, using the following software versions. Why on earth would you not just do this in a cron job?! Chris -- Simplistix - Content Management, Zope Python Consulting - http://www.simplistix.co.uk ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] external method
Chris Withers wrote: Garry Saddington wrote: I have the following external method to back up a postgres database, using the following software versions. Why on earth would you not just do this in a cron job?! Chris Because I want the backup to be done manually, through the web from anywhere. Regards Garry ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] external method
Garry Saddington wrote: Because I want the backup to be done manually, That doesn't seem like such a hot idea. Something that's easilly forgotten. Chris -- Simplistix - Content Management, Zope Python Consulting - http://www.simplistix.co.uk ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] external method
Garry Saddington wrote: Chris Withers wrote: Garry Saddington wrote: Because I want the backup to be done manually, That doesn't seem like such a hot idea. Something that's easilly forgotten. Thanks, I've sorted it. Turns out that pg_dump was being run by SYSTEM and not by the Zope effective user as I thought. Changed the command to include -U scholarpack and all works fine. Thanks for help. Regards Garry ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] external method
Zope is running as user scholarpack who is an administrator on win server 2008. / usar scholarpack have rights to access postgres? are you see the logs from postgres? new conecctions? or logs from zope? ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] External Method in Zope
--On 7. April 2008 13:15:04 +0530 vaibhav pol [EMAIL PROTECTED] wrote: hi, I am using Zope-2.8.1-final and also added zoperl-1.0.beta5 for perl support . I wrote a Perl module which edit files the file access permission is only to root and i want to invoking the module as onther user . by some way i want to invoke the perl interpreter as root for my user. and i also want to know how the zope call external method. This has also little to do with Zope. You could use 'sudo' for starting other command within an other user context. -aj pgpetMO2p6UEv.pgp Description: PGP signature ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] External Method in Zope
On Apr 7, 2008, at 11:23 , vaibhav pol wrote: Thanks alot but i am not using command but i using perl function to modify the passwd and shadow file. in my module that's why i want to invoke that module as root There's a few things seriously wrong with your plan: - you want to create a way to manipulate a system's password/shadow files through the web by a web application. That's insane to begin with. Just don't do it. Have you ever thought about the security implications? - doing Perl methods or external methods in Zope has been deprecated years and years ago. You will have a hard time finding anyone to support that. jens ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] External Method in Zope
Thanks alot but i am not using command but i using perl function to modify the passwd and shadow file. in my module that's why i want to invoke that module as root On Mon, Apr 7, 2008 at 1:19 PM, Andreas Jung [EMAIL PROTECTED] wrote: --On 7. April 2008 13:15:04 +0530 vaibhav pol [EMAIL PROTECTED] wrote: hi, I am using Zope-2.8.1-final and also added zoperl-1.0.beta5 for perl support . I wrote a Perl module which edit files the file access permission is only to root and i want to invoking the module as onther user . by some way i want to invoke the perl interpreter as root for my user. and i also want to know how the zope call external method. This has also little to do with Zope. You could use 'sudo' for starting other command within an other user context. -aj ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] External Method in Zope
Jens Vagelpohl wrote: - doing Perl methods or external methods in Zope has been deprecated years and years ago. You will have a hard time finding anyone to support that. I'm guessing you mean perl external methods rather than all external methods in general? ;-) Chris -- Simplistix - Content Management, Zope Python Consulting - http://www.simplistix.co.uk ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] External Method in Zope
On Apr 7, 2008, at 12:18 , Chris Withers wrote: Jens Vagelpohl wrote: - doing Perl methods or external methods in Zope has been deprecated years and years ago. You will have a hard time finding anyone to support that. I'm guessing you mean perl external methods rather than all external methods in general? ;-) I mean the Perl Methods and Perl External Methods that were part of the old Zope-Perl package from eons ago. jens ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] External Method in Zope
If you absolutely have to, look at Paramiko a python ssh/sftp library which is easy to use but as mentioned already there are critical security issues. with paramiko you don't have to directly edit the files but within an ssh connection run the commands needed that actually make the changes. You may have to put in time.sleep(x) commands to give the response time to come back, where x is an integer. Thomas On Monday 07 April 2008 03:45, vaibhav pol wrote: hi, I am using Zope-2.8.1-final and also added zoperl-1.0.beta5 for perl support . I wrote a Perl module which edit files the file access permission is only to root and i want to invoking the module as onther user . by some way i want to invoke the perl interpreter as root for my user. and i also want to know how the zope call external method. please help me!! -- Thomas McMillan Grant Bennett Appalachian State University Operations Systems AnalystP O Box 32026 University Library Boone, North Carolina 28608 (828) 262 6587 ... using OpenOffice.org, and save them back to disk automatically, in MS Word format. They surf the Web, check e-mail, do instant messsaging, view YouTube videos, visit their Facebook pages, learn touch-typing skills and lots more. Our public library has been offering these Linux public stations for the past three years. - Phil Shapiro Linux Journal January 2008 Library Systems Help Desk: https://www.library.appstate.edu/help/ ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] External Method unable to run Java jar executable using os.system()
--On 12. Februar 2007 07:34:09 -0800 Ridzwan Aminuddin [EMAIL PROTECTED] wrote: java -jar /var/lib/zope2.8/instance/plone-site/Extensions/test.jar it works perfectly But using the external method given above just gives me a blank output. I've also tried popen2: from popen2 import popen2 outputTGT, inputTGT = popen2(command) print outputTGT.readline() and still the jar is simply skipped and not executed. You should see error messages on the console. Ensure you are running Zope in the foreground (zopectl fg). -aj pgpnJqWSVyfcU.pgp Description: PGP signature ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] External Method importing modules
--On 13. Februar 2007 12:53:25 + Alan [EMAIL PROTECTED] wrote: Dear List, I have an external method and now I developed I new module in a separated file and then I am trying to make my external method to import it but I am failing here. Where should place my module file in order to be found by my external method? I tried to place it in the same folder of my external method, but no success. Since the module must be importable, it must be available in some location as defined through sys.path or $PYTHONPATH. Check the Python docs for additional info on that topic. -aj pgpQcuB0jgR9M.pgp Description: PGP signature ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] External Method importing modules
Thanks Andreas, I am trying with: if sys.path.count(myPath) == 0: sys.path.insert(0, myPath) where myPath should be '[Zope installation folder]/instance/import'. So my question now is: is there a variable inside Zope which can returns the 'import' path? Many thanks in advance. Cheers, Alan On 13/02/07, Andreas Jung [EMAIL PROTECTED] wrote: --On 13. Februar 2007 12:53:25 + Alan [EMAIL PROTECTED] wrote: Dear List, I have an external method and now I developed I new module in a separated file and then I am trying to make my external method to import it but I am failing here. Where should place my module file in order to be found by my external method? I tried to place it in the same folder of my external method, but no success. Since the module must be importable, it must be available in some location as defined through sys.path or $PYTHONPATH. Check the Python docs for additional info on that topic. -aj -- Alan Wilter S. da Silva, D.Sc. - CCPN Research Associate Department of Biochemistry, University of Cambridge. 80 Tennis Court Road, Cambridge CB2 1GA, UK. http://www.bio.cam.ac.uk/~awd28 ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] External Method importing modules
--On 13. Februar 2007 13:10:17 + Alan [EMAIL PROTECTED] wrote: Thanks Andreas, I am trying with: if sys.path.count(myPath) == 0: sys.path.insert(0, myPath) What's the sense of this code? sys.path is usually *never* empty. You should really look at the Python docs and learn where Python is looking by default for modules. Is is perfectly documented - python.org - documentation. In addition you would like to check for the existence of an item in sys.path using if myPath in sys.path: -aj pgp96jJNlbS0E.pgp Description: PGP signature ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] External Method importing modules
- Original Message - From: Alan [EMAIL PROTECTED] To: Andreas Jung [EMAIL PROTECTED] Cc: zope@zope.org Sent: Tuesday, February 13, 2007 8:10 AM Subject: Re: [Zope] External Method importing modules Thanks Andreas, I am trying with: if sys.path.count(myPath) == 0: sys.path.insert(0, myPath) where myPath should be '[Zope installation folder]/instance/import'. So my question now is: is there a variable inside Zope which can returns the 'import' path? You can easily check what's in your sys.path by having your external method return it. Typically, the Extensions directory (where your external methods live) are not in the default path and need to be added to sys.path.(warning: be careful on how you do this or everytime your external method gets called it will add to the sys.path and will eventually cause you grief!). Jonathan ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] External Method importing modules
Well, I did it: from App.config import getConfiguration extPath = getConfiguration().instancehome+'/Extensions' if sys.path.count(extPath) == 0: sys.path.insert(0, extPath) And it worked for what I wanted. On 13/02/07, Alan [EMAIL PROTECTED] wrote: On 13/02/07, Andreas Jung [EMAIL PROTECTED] wrote: What's the sense of this code? sys.path is usually *never* empty. You should really look at the Python docs and learn where Python is looking by default for modules. Is is perfectly documented - python.org - documentation. In addition you would like to check for the existence of an item in sys.path using if myPath in sys.path: Dear Andreas and Jonathan, first a mistake: I want to access 'Extensions' folder as you mentioned Jonathan, not 'import'. Andreas, I've done that, I can see several path there like .../instance/Products/Sprout/src, .../lib/python/Zope2/Startup etc., but none for .../instance/Extensions. I was hoping that I could get the path where 'Extensions' is because I work with several zope installations in several platforms and I would like to make my module independent of a variable inside its code that should be manually adjusted for every situation. And yes, I am aware about adding the path only once (that's why there's a 'if') and then I avoid recursive insertions. Cheers, Alan -- Alan Wilter S. da Silva, D.Sc. - CCPN Research Associate Department of Biochemistry, University of Cambridge. 80 Tennis Court Road, Cambridge CB2 1GA, UK. http://www.bio.cam.ac.uk/~awd28 -- Alan Wilter S. da Silva, D.Sc. - CCPN Research Associate Department of Biochemistry, University of Cambridge. 80 Tennis Court Road, Cambridge CB2 1GA, UK. http://www.bio.cam.ac.uk/~awd28 ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] External Method importing modules
Alan wrote at 2007-2-13 13:10 +: if sys.path.count(myPath) == 0: sys.path.insert(0, myPath) where myPath should be '[Zope installation folder]/instance/import'. So my question now is: is there a variable inside Zope which can returns the 'import' path? Formerly, the ExternalMethod documentation suggested to put such modules into SOFTWARE_HOME/Shared/your_company/ Nowadays (since Zope 2.7, I think), INSTANCE_HOME/lib/python is a better place (with any structure you would like to use). This folder is put on PYTHONPATH automatically. No need to fiddle with it (I have already searched hours for problems caused by runtime sys.path manipulations). -- Dieter ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] External Method cPickle Import Module Error
Sean W. Duffy wrote at 2006-12-27 19:44 -0600: ... I have upgraded from Zope 2.8.5 to 2.9.4. This currently works in the 2.8.5 instance but not in the 2.9.4. I have a Module Progress in /usr/lib/python2.4/site-packages/Progress containing 4 files: __init__.py __init__.pyc Progress.py Progress.pyc Both instances have calls to neuro.py which includes: from Progress import Progress The External Method in both instances looks good. I even updated the External Method by clicking the Save Changes button without error in the new 294 instance. But when I access it from the dtml-method it goes boom: Traceback (innermost last): Module ZPublisher.Publish, line 115, in publish Module ZPublisher.mapply, line 88, in mapply Module ZPublisher.Publish, line 41, in call_object Module Products.ExternalMethod.ExternalMethod, line 134, in manage_edit Module Products.ExternalMethod.ExternalMethod, line 141, in getFunction Module App.Extensions, line 148, in getObject - __traceback_info__: ('/var/lib/hip_294_251/Extensions/neuro.py', 'neuro') Module /var/lib/hip_294_251/Extensions/neuro.py, line 299, in ? Module /var/lib/hip_294_251/Extensions/neuro.py, line 9, in GetProgress ImportError: No module named Progress But Progress is in: /usr/lib/python2.4/site-packages/Progress ! If I just start python at the command line I can import Progress w/o error. I'm guessing that it has something to do with how cPickle is sandboxed by Zope, but I just don't get it. It does not look like a Zope (version) issue: The import in an External Method is a pure Python import -- without any restrictions or additional magic. Therefore, if sys.path is still correct inside the External Method, all modules/packages reachable by sys.path should be importable. I would check sys.path. -- Dieter ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] External Method cPickle Import Module Error
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 - --On 27. Dezember 2006 19:44:24 -0600 Sean W. Duffy [EMAIL PROTECTED] wrote: Hi, I have upgraded from Zope 2.8.5 to 2.9.4. This currently works in the 2.8.5 instance but not in the 2.9.4. I have a Module Progress in /usr/lib/python2.4/site-packages/Progress containing 4 files: __init__.py __init__.pyc Progress.py Progress.pyc Both instances have calls to neuro.py which includes: from Progress import Progress The External Method in both instances looks good. I even updated the External Method by clicking the Save Changes button without error in the new 294 instance. But when I access it from the dtml-method it goes boom: Traceback (innermost last): Module ZPublisher.Publish, line 115, in publish Module ZPublisher.mapply, line 88, in mapply Module ZPublisher.Publish, line 41, in call_object Module Products.ExternalMethod.ExternalMethod, line 134, in manage_edit Module Products.ExternalMethod.ExternalMethod, line 141, in getFunction Module App.Extensions, line 148, in getObject - __traceback_info__: ('/var/lib/hip_294_251/Extensions/neuro.py', 'neuro') Module /var/lib/hip_294_251/Extensions/neuro.py, line 299, in ? Module /var/lib/hip_294_251/Extensions/neuro.py, line 9, in GetProgress ImportError: No module named Progress But Progress is in: /usr/lib/python2.4/site-packages/Progress ! If I just start python at the command line I can import Progress w/o error. I'm guessing that it has something to do with how cPickle is sandboxed by Zope, but I just don't get it. I don't see any indication for a cPickle issue. *Trible* check that your Zope instance use the system Python installationl. Check your file permissions, check sys.path, check your $PYTHONPATH. - -aj -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.6 (Darwin) iD8DBQFFk3KQCJIWIbr9KYwRAlcKAKDL0t0qSQFkau++QkcCFXzxVHNbxgCggpG3 ySS1E+jhamd0mLwC+fnvhlM= =ZveC -END PGP SIGNATURE- ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] external method, not escaping and
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 - --On 21. Dezember 2006 20:32:39 +0100 Mihamina Rakotomandimby [EMAIL PROTECTED] wrote: Hi, I have an external method that fetches some web content (POP messages) then format an HTML output to make it easy to display. the Id of the external method is mm. So as I said, it returns HTML content, with HTML tags and s and s. I directly call that external method from a ZPT this way: div tal:content=python:here.mm() foo /div the problem is the and returned by mm are all transformed to lt; and gt;. How to avoid that? Look at the 'structure' directive of ZPT *hint* - -aj -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.6 (Darwin) iD8DBQFFiuLZCJIWIbr9KYwRArATAJ9fW0UckZO5GFz30JWkddYv3h8GcwCfastX kc/+w1d6DMHK7pVgS3b08SY= =ojz9 -END PGP SIGNATURE- ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] External Method = Slow; Shell Script = Fast
ZopeProfiler seems to come with no instructions to install. Can you advise? I haven't installed it for years, but i seem to remember that it installed just like a normal product (ie. install in the Products directory, restart zope, it shows up automagically - in linux that is, i don't do windows). Wasn't there a README when you unpacked the tarball? Maybe someone else on the list has more recent experience... AFAIK profiling is integrated into Zope right now. Take a look at zope.conf and you'll find proper section. Although I'm not sure how it works. I've used ZopeProfiler product. To install ZopeProfiler product you have to copy it to Products/ folder of your zope instance, restart your Zope and go to ControlPanel in ZMI. You should see new link there: Zope Profiler. When you want to start profiling you hit Enable, do your things and then hit Disable and watch results. -- Maciej Wisniowski ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] External Method = Slow; Shell Script = Fast
On 11/2/06 6:52 AM, Maciej Wisniowski [EMAIL PROTECTED] wrote: To install ZopeProfiler product you have to copy it to Products/ folder of your zope instance, restart your Zope and go to ControlPanel in ZMI. You should see new link there: Zope Profiler. When you want to start profiling you hit Enable, do your things and then hit Disable and watch results. I was aware the built-in profiling existed but I've never found it very easy to work with. However, when I installed ZopeProfiler it complained the built-in profiling was enabled, which was news to me. I turned it off and my problem dissolved. And then I called our server team and gave them a stern talking to. :-) --- Edward J. Pollard, B.Sc Webmaster, University of Lethbridge Ext. 1828 ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] External Method = Slow; Shell Script = Fast
+---[ Edward Pollard ]-- | | I was aware the built-in profiling existed but I've never found it very easy | to work with. However, when I installed ZopeProfiler it complained the | built-in profiling was enabled, which was news to me. | | I turned it off and my problem dissolved. | | And then I called our server team and gave them a stern talking to. :-) And can you sell off 3/4 of your hardware now too? d8) -- Andrew Milton [EMAIL PROTECTED] ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] External Method = Slow; Shell Script = Fast
--On 2. November 2006 09:08:13 -0600 Edward Pollard [EMAIL PROTECTED] wrote: On 11/2/06 6:52 AM, Maciej Wisniowski [EMAIL PROTECTED] wrote: To install ZopeProfiler product you have to copy it to Products/ folder of your zope instance, restart your Zope and go to ControlPanel in ZMI. You should see new link there: Zope Profiler. When you want to start profiling you hit Enable, do your things and then hit Disable and watch results. I was aware the built-in profiling existed but I've never found it very easy to work with. However, when I installed ZopeProfiler it complained the built-in profiling was enabled, which was news to me. The profiler is *never* enabled by default. *You* must have enabled it somehow :-) -aj pgpBSz9T4322u.pgp Description: PGP signature ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] External Method = Slow; Shell Script = Fast
- Original Message - From: Edward Pollard [EMAIL PROTECTED] To: zope@zope.org Sent: Wednesday, November 01, 2006 5:58 PM Subject: [Zope] External Method = Slow; Shell Script = Fast Hello, I've got an external method that does some pretty complicated stuff. Basically it takes two XML files - one defines constraints, the other variables - and the script finds a solution using the variables that satisfies the constraints. At the command line (or executed via an external method that calls a shell script) execution is 2 seconds. As an external method execution is 15-20 seconds with the same input. Can anyone offer tips or strategies to improve performance? It would be obnoxious to have to encode objects for passing to a shell script. You should use something like ZopeProfiler or CallProfiler to find out where the time is being spent. Jonathan ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] External Method = Slow; Shell Script = Fast
- Original Message - From: Edward Pollard [EMAIL PROTECTED] To: Jonathan [EMAIL PROTECTED] Sent: Wednesday, November 01, 2006 5:21 PM Subject: Re: [Zope] External Method = Slow; Shell Script = Fast Hi Jon, ZopeProfiler seems to come with no instructions to install. Can you advise? Ed I haven't installed it for years, but i seem to remember that it installed just like a normal product (ie. install in the Products directory, restart zope, it shows up automagically - in linux that is, i don't do windows). Wasn't there a README when you unpacked the tarball? Maybe someone else on the list has more recent experience... Jonathan ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] external method strangeness
On Wed, 2006-10-18 at 15:07 -0400, Paul Winkler wrote: On Wed, Oct 18, 2006 at 06:13:38PM +0100, garry saddington wrote: Can anyone explain what is happening here. I am using Saxon to transform an xml file(source) using a stylesheet(style) the result is then written to Postgres. The contents of source are uploaded in Zope and passed to the external method as a string. When I run this external method: import psycopg, string, re, subprocess def scholarpack_xml_transform(source): f=open('/opt/scholarpack/ancillary/source.xml','w') f.write(source) I have no idea what's causing your problem, but this raises red flags for me: if two people upload sources at the same time, you'll have problems here. There is no chance of this as it is a one-off populate the db exercise. If you really really must read/write files on the filesystem, either use locks or use python's tempfile module. f.close source= '/opt/scholarpack/ancillary/source.xml' style='/opt/scholarpack/ancillary/style.xml' source1=source.replace('apos;','`') source2=source1.replace('NLPGaddress','BS7666address') p=re.compile(\') source3=p.sub( '`' , source2) r = subprocess.Popen(['/opt/scholarpack/ancillary/jre/bin/java','-jar','./saxon.jar',source3,style], stdout = subprocess.PIPE,cwd = '/opt/scholarpack/ancillary/') Are you just using saxon for xslt processing? If so, IMO using an external process for that is severe overkill. Get lxml and try something like this: from lxml import etree style = etree.XSLT(etree.parse(some_file_object)) transformed = style.apply(source_data) Thank you I've never heard of this, I'll give it a try. I was using 4suite but it started to misbehave in the way that I wanted to use it. regards Garry but again, this doesn't address your immediate problem :) ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] external method strangeness
garry saddington wrote at 2006-10-18 18:13 +0100: ... import psycopg, string, re, subprocess def scholarpack_xml_transform(source): f=open('/opt/scholarpack/ancillary/source.xml','w') f.write(source) f.close The line above looks buggy: missing (). ... do=curs.execute(transformed1) do The line above looks doubtfull: no effect conn.commit() conn.close I get a programming error thrown from the conn.commit() line and the method fails. Almost surely, postgres does not like the command your have generated. It is quite picky with binary data... -- Dieter ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] external method strangeness
+---[ garry saddington ]-- | Can anyone explain what is happening here. I am using Saxon to transform | an xml file(source) using a stylesheet(style) the result is then written | to Postgres. The contents of source are uploaded in Zope and passed to | the external method as a string. When I run this external method: [snip] | Can anyone point me in the correct direction? Text encoding? Would probably be a lot easier if you told us the error message in full that you get. -- Andrew Milton [EMAIL PROTECTED] ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] external method strangeness
+---[ garry saddington ]-- | On Thu, 2006-10-19 at 03:18 +1000, Andrew Milton wrote: | +---[ garry saddington ]-- | | Can anyone explain what is happening here. I am using Saxon to transform | | an xml file(source) using a stylesheet(style) the result is then written | | to Postgres. The contents of source are uploaded in Zope and passed to | | the external method as a string. When I run this external method: | | [snip] | | | Can anyone point me in the correct direction? | | Text encoding? | The same files are used both times. The error log is not very helpful | here but I enclose it for completeness. | regards | garry I'd add some debugging into the pyana.py file, at the point where it's raising the exception. -- Andrew Milton [EMAIL PROTECTED] ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] external method strangeness
On Wed, Oct 18, 2006 at 06:13:38PM +0100, garry saddington wrote: Can anyone explain what is happening here. I am using Saxon to transform an xml file(source) using a stylesheet(style) the result is then written to Postgres. The contents of source are uploaded in Zope and passed to the external method as a string. When I run this external method: import psycopg, string, re, subprocess def scholarpack_xml_transform(source): f=open('/opt/scholarpack/ancillary/source.xml','w') f.write(source) I have no idea what's causing your problem, but this raises red flags for me: if two people upload sources at the same time, you'll have problems here. If you really really must read/write files on the filesystem, either use locks or use python's tempfile module. f.close source= '/opt/scholarpack/ancillary/source.xml' style='/opt/scholarpack/ancillary/style.xml' source1=source.replace('apos;','`') source2=source1.replace('NLPGaddress','BS7666address') p=re.compile(\') source3=p.sub( '`' , source2) r = subprocess.Popen(['/opt/scholarpack/ancillary/jre/bin/java','-jar','./saxon.jar',source3,style], stdout = subprocess.PIPE,cwd = '/opt/scholarpack/ancillary/') Are you just using saxon for xslt processing? If so, IMO using an external process for that is severe overkill. Get lxml and try something like this: from lxml import etree style = etree.XSLT(etree.parse(some_file_object)) transformed = style.apply(source_data) but again, this doesn't address your immediate problem :) -- Paul Winkler http://www.slinkp.com ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] external method: importing and updating method
Alan wrote: Thanks for help. I did what suggested below. We also set a crontab to restart the zope server every night, Why?! Chris -- Simplistix - Content Management, Zope Python Consulting - http://www.simplistix.co.uk ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: Re: [Zope] external method: importing and updating method
Hi List, crontab is really a bad idea. We quitted that. Thanks for your commentaries. Alan On 05/10/06, Chris Withers [EMAIL PROTECTED] wrote: Alan wrote: Thanks for help. I did what suggested below. We also set a crontab to restart the zope server every night, Why?! Chris -- Simplistix - Content Management, Zope Python Consulting - http://www.simplistix.co.uk -- Alan Wilter S. da Silva, D.Sc. - Research Associate Department of Biochemistry, University of Cambridge. 80 Tennis Court Road, Cambridge CB2 1GA, UK. http://www.bio.cam.ac.uk/~awd28 ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: Re: [Zope] external method: importing and updating method
--On 5. Oktober 2006 10:24:31 +0100 Alan [EMAIL PROTECTED] wrote: Hi List, crontab is really a bad idea. We quitted that. Why is using crontab a bad idea? It's the most common and most reliable solution to run scripts in Zope periodically. -aj pgpHnQfkHcCKi.pgp Description: PGP signature ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] external method: importing and updating method
Well the complete story was: We also set a crontab to restart the zope server every night, but them I was wondering if it is a good idea. And later on: crontab is really a bad idea. We quitted that. And in that case (using crontab to restart Zope every night), I think it was a bad idea. Of course, for stuff like starting some processing at a given time in the Zope instance, crontab can be great... Well, there is also this interesting on-going thread about TimerService/ZopeScheduler :)) Pascal De : Jens Vagelpohl [EMAIL PROTECTED] Date : Thu, 5 Oct 2006 08:03:53 -0400 À : zope Mailing List zope@zope.org Objet : Re: [Zope] external method: importing and updating method -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 5 Oct 2006, at 05:24, Alan wrote: Hi List, crontab is really a bad idea. We quitted that. Might make sense to back up blanket nonsensical statements like that with some hard facts. jens -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.1 (Darwin) iD8DBQFFJPSqRAx5nvEhZLIRAkKWAJ45fYr4khMmREaF89vfFJEGvo2v3gCfSe8g bXYxESSH8t4mi4nFmVWY67A= =wI9T -END PGP SIGNATURE- ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev ) ** This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the system manager. This footnote also confirms that this email message has been swept by MIMEsweeper for the presence of computer viruses. www.mimesweeper.com ** ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: Re: [Zope] external method: importing and updating method
Hi Folks, Thanks for help. I did what suggested below. We also set a crontab to restart the zope server every night, but them I was wondering if it is a good idea. Cheers, Alan On 03/10/06, Jonathan [EMAIL PROTECTED] wrote: - Original Message - From: Dieter Maurer [EMAIL PROTECTED] To: Alan [EMAIL PROTECTED] Cc: zope@zope.org Sent: Tuesday, October 03, 2006 2:06 PM Subject: Re: [Zope] external method: importing and updating method Alan wrote at 2006-10-2 18:48 +0100: In my external method I have something like this: ... sys.path.insert(0, CCPNPYTHON) This is not a good idea! The source of an External Method can be read arbitrarily often -- and each time, you extend sys.path... We get around this 'evergrowing' path problem by (if there is a problem with this solution let me know!): import sys SOMEPATH = '/some/path/goes/here' if SOMEPATH not in sys.path: sys.path.append(SOMEPATH) Jonathan -- Alan Wilter S. da Silva, D.Sc. - Research Associate Department of Biochemistry, University of Cambridge. 80 Tennis Court Road, Cambridge CB2 1GA, UK. http://www.bio.cam.ac.uk/~awd28 ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: Re: [Zope] external method: importing and updating method
- Original Message - From: Alan [EMAIL PROTECTED] To: Jonathan [EMAIL PROTECTED] Cc: Dieter Maurer [EMAIL PROTECTED]; zope@zope.org Sent: Wednesday, October 04, 2006 6:12 AM Subject: Re: Re: [Zope] external method: importing and updating method Hi Folks, Thanks for help. I did what suggested below. We also set a crontab to restart the zope server every night, but them I was wondering if it is a good idea. What you are trying to accomplish/resolve by restarting zope everynight? I can't think of any real downside to doing it, but it shouldn't be necessary - we once had a production server that ran for over 13 months, continuously, without ever being restarted! (now that's a stable platform!) Jonathan ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: Re: [Zope] external method: importing and updating method
On 10/4/06, Alan [EMAIL PROTECTED] wrote: Thanks for help. I did what suggested below. We also set a crontab to restart the zope server every night, but them I was wondering if it is a good idea. Isn't it better to just restart the server when you have updated the software? Modules loaded from External methods are not different from any other Zope software in that sense. -- Lennart Regebro, Nuxeo http://www.nuxeo.com/ CPS Content Management http://www.cps-project.org/ ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] external method: importing and updating method
Alan wrote at 2006-10-2 18:48 +0100: In my external method I have something like this: ... sys.path.insert(0, CCPNPYTHON) This is not a good idea! The source of an External Method can be read arbitrarily often -- and each time, you extend sys.path... The imp module allows you to import modules without the need to modify path. ... the problem I am facing now it that if I update my memops stuff (which is found in CCPNPYTHON path) it seems not to be being updated in Zope, because Zope is still using the old version. (If I run outside Zope, the code works). That's typical Python behaviour: Python does not recognize at runtime when a module source has changed. It provides however a builtin reload which you can use to explicitely reload a module. Be warned the reload is dangerous. Funny effects can happen. As someone else suggested, restarting Zope is the safest way (although not the fasted one). -- Dieter ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] external method: importing and updating method
- Original Message - From: Dieter Maurer [EMAIL PROTECTED] To: Alan [EMAIL PROTECTED] Cc: zope@zope.org Sent: Tuesday, October 03, 2006 2:06 PM Subject: Re: [Zope] external method: importing and updating method Alan wrote at 2006-10-2 18:48 +0100: In my external method I have something like this: ... sys.path.insert(0, CCPNPYTHON) This is not a good idea! The source of an External Method can be read arbitrarily often -- and each time, you extend sys.path... We get around this 'evergrowing' path problem by (if there is a problem with this solution let me know!): import sys SOMEPATH = '/some/path/goes/here' if SOMEPATH not in sys.path: sys.path.append(SOMEPATH) Jonathan ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] external method: importing and updating method
- Original Message - From: Alan [EMAIL PROTECTED] To: zope@zope.org Sent: Monday, October 02, 2006 1:48 PM Subject: [Zope] external method: importing and updating method Hi List! In my external method I have something like this: ... sys.path.insert(0, CCPNPYTHON) from memops.general.Io import loadXmlProjectFile ... the problem I am facing now it that if I update my memops stuff (which is found in CCPNPYTHON path) it seems not to be being updated in Zope, because Zope is still using the old version. (If I run outside Zope, the code works). I have encountered this problem before, and the quick-fix was to restart Zope (from the ZMI - Control Panel). hth Jonathan ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] external method with import tarfile
Hi there! I managed to find the problem and the solution. First, I've forgot to mention that in my script, oname is an uploaded file. I just inserted a f.close() and voilá! def upload_external(self,file,REQUEST): import os,tarfile ... f=open(oname,wb) f.write(file.read()) f.close() ... tar = tarfile.open(oname,r:gz) for itar in tar: tar.extract(itar.name,jobdir) return Done Cheers, Alan On 18/07/06, Alan [EMAIL PROTECTED] wrote: Thanks for your reply. Yes, my script works and my file are not broken. I am using mac osx tiger 10.4.7, zope 2.9.3 and python 2.4.2. Cheers, Alan On 18/07/06, Andreas Jung [EMAIL PROTECTED] wrote: --On 18. Juli 2006 16:12:18 +0100 Alan [EMAIL PROTECTED] wrote: Error Type: IOError Error Value: CRC check failed This is unlikely a Zope issue. Either your tar file is broken or the tarfile module is broken. Check if your code runs without Zope as a simple PythonScript..there is nothing about Zope involved in your issue. -aj -- Alan Wilter S. da Silva, D.Sc. - Research Associate Department of Biochemistry, University of Cambridge. 80 Tennis Court Road, Cambridge CB2 1GA, UK. http://www.bio.cam.ac.uk/~awd28 -- Alan Wilter S. da Silva, D.Sc. - Research Associate Department of Biochemistry, University of Cambridge. 80 Tennis Court Road, Cambridge CB2 1GA, UK. http://www.bio.cam.ac.uk/~awd28 ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] external method with import tarfile
Alan wrote: Hi there! I managed to find the problem and the solution. First, I've forgot to mention that in my script, oname is an uploaded file. I just inserted a f.close() and voilá! def upload_external(self,file,REQUEST): import os,tarfile ... f=open(oname,wb) f.write(file.read()) f.close() ... tar = tarfile.open(oname,r:gz) for itar in tar: tar.extract(itar.name,jobdir) return Done Err. why not tar=tarfile.open(fileobj=file) ? Why bother with potentially name clashing files in filesystem? Regards Tino ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] external method with import tarfile
--On 18. Juli 2006 16:12:18 +0100 Alan [EMAIL PROTECTED] wrote: Error Type: IOError Error Value: CRC check failed This is unlikely a Zope issue. Either your tar file is broken or the tarfile module is broken. Check if your code runs without Zope as a simple PythonScript..there is nothing about Zope involved in your issue. -aj pgp0ncqn4RhT4.pgp Description: PGP signature ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] External Method Working Directory?
jwithers wrote: Because I need to feed the file to Mailman for evil purposes of my own (well, fairly mundane purposes of allowing my zope app to manipulate mailman list memberships, really) that the prototype mailman adapter I found doesn't meet. When I've needed to do simple stuff with this is the past, I just manipulate mailmain by send email from Zope to mailman's admin interface... And yeah, tempfile would work, although, I have to admit I really don't see the point of it when you are only storing one file. I am probably missing some usecase or good programming practice here, but it seems like it saves you a single line for the delete in return for an extra module import. What happens when two users do something that creates one of these temp files at exactly the same time? ;-) cheers, Chris -- Simplistix - Content Management, Zope Python Consulting - http://www.simplistix.co.uk ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] External Method Working Directory?
When I've needed to do simple stuff with this is the past, I just manipulate mailmain by send email from Zope to mailman's admin interface... Pipes seem easier to me. Responses from the command line scripts seem much easier to use for confirmation. And there are things you can do easily from the cli interface that you either can't do through email, are difficult to do through email, or possibly I just don't know how to do through email. And yeah, tempfile would work, although, I have to admit I really don't see the point of it when you are only storing one file. I am probably missing some usecase or good programming practice here, but it seems like it saves you a single line for the delete in return for an extra module import. What happens when two users do something that creates one of these temp files at exactly the same time? ;-) Yah, you and Tres Seaver (OL) both made this point, and thanks for saving me from having much wailing and gnashing of teeth over my dimness once this actually went live. Thanks for the help, J.P. Withers ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] External Method Working Directory?
jwithers wrote: eep, another one, hope we're not related ;-) Can anyone tell me what the default working directory for an external method is? You can't rely on it being anything. If you're working with files, you need to be very careful... Further, I need this to create a file temporarily in Extensions. Why? I would prefer not to have to hardwire the location of Extension into the code, since that would make the script non-portable to other instances easily. Any advice on this would be appreciated. I'd suggest looking at python's tempfile module... Chris -- Simplistix - Content Management, Zope Python Consulting - http://www.simplistix.co.uk ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] External Method Working Directory?
jwithers wrote at 2005-9-28 15:43 -0700: ... I have an external method that at this point is made up of nothing but os.getcwd() and lives in my Extensions directory. When it is run, it reports the working directory as being one of my Products directories. Some products are broken (they change the current working directory). Apparently, you have one of them installed. In general, it is a bad idea to change the current working directory in a multi-threaded application (such as Zope). An External Method does not have a specific working directory when it is run. Because Zope must not modify the working directory, it cannot let it follow the run of an External Method. The current working directory remains what it was. On a system with well behaving products, the current working directory remains the INSTANCE_HOME. ... Further, I need this to create a file temporarily in Extensions. I would prefer not to have to hardwire the location of Extension into the code, since that would make the script non-portable to other instances easily. The Extensions directory is a bad place for temporary files... -- Dieter ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] External Method Working Directory?
On Thu, 2005-09-29 at 00:20, Chris Withers wrote: eep, another one, hope we're not related ;-) When I saw your posts on newsgroups years ago, I almost gave up python programming altogether Chris, thinking that any given field of endeavor needs only one Withers, but decided to go ahead and chance it. Can anyone tell me what the default working directory for an external method is? You can't rely on it being anything. If you're working with files, you need to be very careful... Further, I need this to create a file temporarily in Extensions. Why? Because I need to feed the file to Mailman for evil purposes of my own (well, fairly mundane purposes of allowing my zope app to manipulate mailman list memberships, really) that the prototype mailman adapter I found doesn't meet. And yeah, tempfile would work, although, I have to admit I really don't see the point of it when you are only storing one file. I am probably missing some usecase or good programming practice here, but it seems like it saves you a single line for the delete in return for an extra module import. Peter Bengtsson gave me the solution in just using the INSTANCE_HOME variable directly, which is bound in external scripts. That beat the daylights out of the solution that had come up wjth the help of some folks on ICQ of using self.Control_Panel.getINSTANCE_HOME(). And Deiter is right and it is dim to put the temporary file in Extensions and it will be put in var instead. Not sure what I was thinking there. John Withers I would prefer not to have to hardwire the location of Extension into the code, since that would make the script non-portable to other instances easily. Any advice on this would be appreciated. I'd suggest looking at python's tempfile module... Chris ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] External Method Working Directory?
Products?? That is odd. I thought it was the var/ directory or at least the zope instance home directory. From the External method you should have access to INSTANCE_HOME and SOFTWARE_HOME. Try if these are what you want. I doubt that you'll find your Extensions/ dir in any of them so you might have do something like: import os return os.path.join(INSTANCE_HOME, 'Extensions') 2005/9/28, jwithers [EMAIL PROTECTED]: Folks, I have an external method that at this point is made up of nothing but os.getcwd() and lives in my Extensions directory. When it is run, it reports the working directory as being one of my Products directories. Can anyone tell me what the default working directory for an external method is? Further, I need this to create a file temporarily in Extensions. I would prefer not to have to hardwire the location of Extension into the code, since that would make the script non-portable to other instances easily. Any advice on this would be appreciated. J. P. Withers ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev ) -- Peter Bengtsson, work www.fry-it.com home www.peterbe.com hobby www.issuetrackerproduct.com ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] External Method Working Directory?
jwithers, a) Is your os.getcwd() (in /Extensions) called from a Product (in /Products?) Otherwise I have not idea b) Regarding temporary files .. I've used stuff like ... import tempfile tmpFile2 = tempfile.mktemp() theFile=open( tmpFile2,'rb') result = theFile.read() theFile.close() os.remove(tmpFile2) I think this may depreciated but do a google on python tempfile and you can use the updated modules if they apply to your issue. David jwithers wrote: Folks, I have an external method that at this point is made up of nothing but os.getcwd() and lives in my Extensions directory. When it is run, it reports the working directory as being one of my Products directories. Can anyone tell me what the default working directory for an external method is? Further, I need this to create a file temporarily in Extensions. I would prefer not to have to hardwire the location of Extension into the code, since that would make the script non-portable to other instances easily. Any advice on this would be appreciated. J. P. Withers ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] external method and security
Marty Stitt wrote: Is it up to me to write my own security code when using an external method? Basically, yes. You can protect access to the "stub" within the ZODB using the Security tab, but the body of the external method has free reign. Shane ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] External Method
If you are talking about dtml you can pass them in the dtml-call tag dtml-call "my_external_method(_.None, _, param_1=1, param_2=2)" -- Andy McKay, Developer. ActiveState. - Original Message - From: "Kini Natekar" [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Tuesday, November 21, 2000 2:12 AM Subject: [Zope] External Method Hi, How can I pass parameters to an External Method? I know of one way to do this, is to use dtml-var tag. Is there any other way? Thanks, Kini. __ Do You Yahoo!? Yahoo! Shopping - Thousands of Stores. Millions of Products. http://shopping.yahoo.com/ ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev ) ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] External Method
Kini Natekar writes: How can I pass parameters to an External Method? I know of one way to do this, is to use dtml-var tag. Is there any other way? Anywhere, you can use 'expr=""'. This means almost all DTML tags: call, var, in, with, let (without 'expr='!) ... Example: dtml-call "your_method(param1, param2, )" Dieter ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] external method import error (ImportError)...
Eric writes: To summarize: How do I import modules in an External Method's .py file? I remember, I read this in some "External Method" related documentation. You do *NOT* place such modules inside the folder "Extensions" but put them somewhere else reachable by "PYTHONPATH". The documentation suggests that you create a subpackage inside "Shared", say "myCompanyExtensions", and place there your module (don't forget "__init__.py" in the subfolder representing the subpackage), say "myModule". Then, in your external method, you would use: from Shared.myCompanyExtensions import myModule Dieter ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] external method database connection
Also, you could always import the specific module for your database, and create a db connection, then execute() and fetch() directly. Although, if you are putting this in an external method, it would be wiser to use your existing ZSQL methods ;] Knight [EMAIL PROTECTED] On Fri, 6 Oct 2000, knight wrote: How do I get a zope database connection from an enternal method? You can access your db using your existing ZSQL Methods by calling them from the namespace passed in, specifically self. Example: def myextmethod(self): mfl_id = 3 results = self.sqlCountUsers(mfl_id=mfl_id) for result in results: print result[0], result[3] Keep in mind that a list is returned, not a dictionary. Knight [EMAIL PROTECTED] ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev ) ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] External method and stdout
Andreas Pauley wrote: For some reason you have to "return" everything that should be available to zope. You can return a sequence and loop through it with DTML or you can build a variable with everything you want to display and then return the variable. I have no idea why this is so, and why you can't just the print statement as an equivalent to dtml-var. There is probably elegant ways of replacing DTML with external methods or Python Methods, I was just unable to find documentation and examples on it until now. Can anyone help with this? Regards, Andreas. there are a couple of ways. first zope's publishing objects. if your publishing a dtml method object than the semantics of it require that values be inserted into the template/page thats being returned to the user. you can also publish an external method or a python module directly(indeed Zope is just a published python module). but sticking to zope external methods, an example, if you had def myhello_world(self, REQUEST): page = " welcome to %s corner of my hello world "%self.getParentNode().id and just browse directly to the external method. its important to keep in mind that stdout isn't connected to the client. the client is connected to medusa/ZServer, which gives a channel to ZPublisher to publish data that will be returned to the client. this mainly applies to fs code, i'm not totally sure about the semantics of web python methods. i know this probably goes a bit further down the rabbit hole than you might be interested in going. if you want to know some more of the details. check out the medusa docs at http://www.nightmare.com/medusa and the ZPublisher docs under the Documentation Sec. of Zope.org. These are dated but they give a understanding of the interaction between medusa's asynch interfaces and zope. and of course the source code. you could also use document templates directly from python def new_world_order(self, REQUEST): from DocumentTemplate import HTML my_sites = [('My homepage','http://homepage'), ('my favorite bookstore','http://amazon.com') , ... etc] page_to_return = """ html body ul dtml-in sites lia href="dtml-var sequence-item"dtml-var sequence-key/a/li /dtml-in /ul /body /html """ return HTML(my_sites)(sites=my_sites) or evaluate a dtml file on the file system using HTMLFILE see the DocumentTemplate directory for source and more examples D.Templates also give you a pretty good separation of app. logic and presentation. Doing straight python insertion in a page is not the Zope Way. if you're interested in this type of thing, you might want to check out some other python projects like mod_snake (apache), pywx.sourceforge.net (aolserver), or webware. I'll think you find the benefits of doing it through DTML offer you a lot more benefits in terms on maintainbility and site management. Cheers Kapil Sven Hohage wrote: Hallo, that's the problem: I've made an external method which is working with lists and should return the result to Zope. The python code is working very well, but is sending everything to sys.stdout( I'm using the print-statement).How do I convince Zope to print the result on the html-page. Thanks. -- In a world without fences, who needs gates? ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev ) ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] External Method not accepting CGI module
Kelvin Cheong writes: import cgi form = cgi.FieldStorage() This gives you an empty "FieldStorage" fileitem = form["userTABPIX1"] In it, "userTABPIX1" is unknown. fname = tempfile.mktemp() fp=open(fname,'w') fp.write(fileitem.file.read()) fp.close() Give your external method either the first argument "self" or an argument "REQUEST". In the first case, you can use "REQUEST=self.REQUEST" to get the REQUEST object. In the second case, you use REQUEST directly. "REQUEST.form" contains the form variables of the REQUEST. Dieter ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] External Method Difficulties
Jason Lee writes: ... external method access ... dtml-call genhash This says, "call the method (for its side effects) but discard any return value". This produces nothing. I think I read somewhere that dtml-call returns no data, so that might explain it. I could be wrong. You are right. dtml-var genhash That should work. What KeyError do you get? The error message's head should tell you what key has not been found. The traceback at the foot (especially the last line) tells you where the KeyError occured. Dieter ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] External Method Difficulties
Dieter Maurer wrote: dtml-var genhash That should work. What KeyError do you get? The error message's head should tell you what key has not been found. The traceback at the foot (especially the last line) tells you where the KeyError occured. After I posted, I did some more wild, random, send-up-a-prayer hacking and I think I discovered the problem. It appears that the name of the external method and the name of the module file must be the same. At least, I changed the name of the file to genhash.py and things worked. It could be that the file was called md5.py, and since there is a Python module called md5, the interpreter may have been getting confused. I don't know which. Can any one shed some light on that? Thanks for your help, Dieter! -- Jason Lee |Maybe it's good that I can't afford anti-psychotic [EMAIL PROTECTED]|medication. It frees me up to plan the assassination Programmer/Analyst |of Deputy Dawg. -- The Onion ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )