Re: [Zope-dev] Extrenal method unable to run the os.popen() or os.system() commands

2007-02-09 Thread Ridzwan Aminuddin
Oh yes, i forgot to mention that in my code i did use the absolute paths to my 
java .jar file as you can see i my code below, the absolute path to the 
Extensions directory is in the variable homedir. I also set my classpath to 
point to the folder just in case..

Any ideas why it won't work? and any suggestions for workarounds?

Thanks!


homedir = os.getcwd()
homedir = homedir + "/Extensions"

command = "cd "+homedir
os.popen(command)

command = "java -jar "+ '"' + homedir + "/" + "ActiveLearningTools.jar" + '" ' +
"prepArticles >> test.txt"
os.popen(command)

> -Original Message-
> From: [EMAIL PROTECTED]
> Sent: Fri, 9 Feb 2007 17:39:58 -0800
> To: [EMAIL PROTECTED]
> Subject: Re: [Zope-dev] Extrenal method unable to run the os.popen() or
> os.system() commands
> 
> Hi,
> 
> Since you say changing the working environment in zope is dangerous, is
> there any way around for what i need to do?
> 
> Is there a way i can find out the exact directory zope is on at that
> moment? and if i can find it is it a good idea for me to place the
> additional files i need to run my .jar in that directory?
> 
> Or should i just do everything in an absolute path method?
> 
> i.e when i wanna run my jar instead of using this as my "command"
> 
> java -jar ActivelearningTools.jar >> output.txt
> 
> I will do:
> 
> java -jar
> /var/lib/zope2.8/instance/plone-site/Extensions/ActiveLearningTools.jar
> >> /var/lib/zope2.8/instance/plone-site/Extensions/output.txt
> 
> Thanks in advance!
> 
> wan
> 
>> -Original Message-
>> From: [EMAIL PROTECTED]
>> Sent: Fri, 9 Feb 2007 19:58:06 +0100
>> To: [EMAIL PROTECTED]
>> Subject: Re: [Zope-dev] Extrenal method unable to run the os.popen() or
>> os.system() commands
>> 
>> Ridzwan Aminuddin wrote at 2007-2-9 00:47 -0800:
>>> ...
>> >command = "cd "+homedir
>> >os.popen(command)
>> 
>> This "popen" is useless.
>> 
>>   It will change the working directory in the new (!) process that
>> executes
>>   "command". But the effect is lost as soon as the process ends (after
>> the
>>   "cd" has been executed).
>> 
>>   "os.popen('cd ...')" will not affect the working directory
>>   of the Zope process (or any later 'os.popen').
>> 
>> 
>> Be warned: you should *not* change Zope's working directory.
>> Changing global resources (such as the working directory) is
>> dangerous in a multi thread environment (such as Zope).
>> 
>> 
>> 
>> --
>> Dieter
> ___
> Zope-Dev maillist  -  Zope-Dev@zope.org
> http://mail.zope.org/mailman/listinfo/zope-dev
> **  No cross posts or HTML encoding!  **
> (Related lists -
>  http://mail.zope.org/mailman/listinfo/zope-announce
>  http://mail.zope.org/mailman/listinfo/zope )
___
Zope-Dev maillist  -  Zope-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists -
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope )


Re: [Zope-dev] Extrenal method unable to run the os.popen() or os.system() commands

2007-02-09 Thread Ridzwan Aminuddin
Hi,

Since you say changing the working environment in zope is dangerous, is there 
any way around for what i need to do?

Is there a way i can find out the exact directory zope is on at that moment? 
and if i can find it is it a good idea for me to place the additional files i 
need to run my .jar in that directory?

Or should i just do everything in an absolute path method?

i.e when i wanna run my jar instead of using this as my "command"

java -jar ActivelearningTools.jar >> output.txt

I will do:

java -jar 
/var/lib/zope2.8/instance/plone-site/Extensions/ActiveLearningTools.jar >> 
/var/lib/zope2.8/instance/plone-site/Extensions/output.txt

Thanks in advance!

wan
 
> -Original Message-
> From: [EMAIL PROTECTED]
> Sent: Fri, 9 Feb 2007 19:58:06 +0100
> To: [EMAIL PROTECTED]
> Subject: Re: [Zope-dev] Extrenal method unable to run the os.popen() or
> os.system() commands
> 
> Ridzwan Aminuddin wrote at 2007-2-9 00:47 -0800:
>> ...
> > command = "cd "+homedir
> > os.popen(command)
> 
> This "popen" is useless.
> 
>   It will change the working directory in the new (!) process that
> executes
>   "command". But the effect is lost as soon as the process ends (after
> the
>   "cd" has been executed).
> 
>   "os.popen('cd ...')" will not affect the working directory
>   of the Zope process (or any later 'os.popen').
> 
> 
> Be warned: you should *not* change Zope's working directory.
> Changing global resources (such as the working directory) is
> dangerous in a multi thread environment (such as Zope).
> 
> 
> 
> --
> Dieter
___
Zope-Dev maillist  -  Zope-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists -
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope )


Re: [Zope-dev] Extrenal method unable to run the os.popen() or os.system() commands

2007-02-09 Thread Dieter Maurer
Ridzwan Aminuddin wrote at 2007-2-9 00:47 -0800:
> ...
>   command = "cd "+homedir
>   os.popen(command)

This "popen" is useless.

  It will change the working directory in the new (!) process that executes
  "command". But the effect is lost as soon as the process ends (after the
  "cd" has been executed).

  "os.popen('cd ...')" will not affect the working directory
  of the Zope process (or any later 'os.popen').


Be warned: you should *not* change Zope's working directory.
Changing global resources (such as the working directory) is
dangerous in a multi thread environment (such as Zope).



-- 
Dieter
___
Zope-Dev maillist  -  Zope-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope )


[Zope-dev] Zope Tests: 7 OK

2007-02-09 Thread Zope Tests Summarizer
Summary of messages to the zope-tests list.
Period Thu Feb  8 12:00:00 2007 UTC to Fri Feb  9 12:00:00 2007 UTC.
There were 7 messages: 7 from Zope Unit Tests.


Tests passed OK
---

Subject: OK : Zope-2.6 Python-2.1.3 : Linux
From: Zope Unit Tests
Date: Thu Feb  8 21:05:31 EST 2007
URL: http://mail.zope.org/pipermail/zope-tests/2007-February/007216.html

Subject: OK : Zope-2.6 Python-2.3.6 : Linux
From: Zope Unit Tests
Date: Thu Feb  8 21:07:02 EST 2007
URL: http://mail.zope.org/pipermail/zope-tests/2007-February/007217.html

Subject: OK : Zope-2.7 Python-2.3.6 : Linux
From: Zope Unit Tests
Date: Thu Feb  8 21:08:32 EST 2007
URL: http://mail.zope.org/pipermail/zope-tests/2007-February/007218.html

Subject: OK : Zope-2.8 Python-2.3.6 : Linux
From: Zope Unit Tests
Date: Thu Feb  8 21:10:02 EST 2007
URL: http://mail.zope.org/pipermail/zope-tests/2007-February/007219.html

Subject: OK : Zope-2.9 Python-2.4.4 : Linux
From: Zope Unit Tests
Date: Thu Feb  8 21:11:32 EST 2007
URL: http://mail.zope.org/pipermail/zope-tests/2007-February/007220.html

Subject: OK : Zope-2.10 Python-2.4.4 : Linux
From: Zope Unit Tests
Date: Thu Feb  8 21:13:02 EST 2007
URL: http://mail.zope.org/pipermail/zope-tests/2007-February/007221.html

Subject: OK : Zope-trunk Python-2.4.4 : Linux
From: Zope Unit Tests
Date: Thu Feb  8 21:14:32 EST 2007
URL: http://mail.zope.org/pipermail/zope-tests/2007-February/007222.html

___
Zope-Dev maillist  -  Zope-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope )


Re: [Zope-dev] Extrenal method unable to run the os.popen() or os.system() commands

2007-02-09 Thread Andreas Jung



--On 9. Februar 2007 00:47:09 -0800 Ridzwan Aminuddin <[EMAIL PROTECTED]> 
wrote:



Hi guys...

I wrote an external python script which would grab some HTML and so some
text and file preprocessing.

The script then is supposed to run come command line methods... using
os.system() .. however when i run the script triggered by my DTML code it
manages to do the grabbing of the html and saving it into a file ans
stuff... but once it hits the portion where its supposed to run the
command lines.. it just skips everything and goes right to the end
after which this error message is shown :

 Error Type
IOError
Error Value
[Errno 2] No such file or directory:
'/var/lib/zope2.8/instance/plone-site/Extensions/output.txt' Request made
at



You can resolve this issue on your own by checking why the file is 
generated in the wrong place or by it is looked up at the wrong 
place..adding some debug code or using pdb should be sufficient to track 
this down.


-aj

pgpentm0fFNoK.pgp
Description: PGP signature
___
Zope-Dev maillist  -  Zope-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope )


[Zope-dev] Extrenal method unable to run the os.popen() or os.system() commands

2007-02-09 Thread Ridzwan Aminuddin
Hi guys...

I wrote an external python script which would grab some HTML and so some text 
and file preprocessing.

The script then is supposed to run come command line methods... using 
os.system() .. however when i run the script triggered by my DTML code it 
manages to do the grabbing of the html and saving it into a file ans stuff... 
but once it hits the portion where its supposed to run the command lines.. it 
just skips everything and goes right to the end after which this error 
message is shown :

 Error Type
IOError
Error Value
[Errno 2] No such file or directory: 
'/var/lib/zope2.8/instance/plone-site/Extensions/output.txt'
Request made at

If the command line executables had run this error would not occur as one of 
the jar files was supposed to output a text file called output.txt.

I tried running this script, modified on its own off the terminal using "python 
test.py" and it works perfectly... but once DTML calls this script it is unable 
to run the cammand line portion...

can anyone please help me out or point me in the right direction... 

Thanks and regards

wan


Here is my code :




def removeIllegalChars( tgtString ):

import os
import sys
from yahoo.search.news import NewsSearch
import re

tgtString = re.sub('<([^!>]([^>]|\n)*)>', '', tgtString)
tgtString = re.sub('<([^>]([^>]|\n)*)>', '', tgtString)
tgtString = re.sub('\n', '', tgtString)
tgtString = re.sub('\t', '', tgtString)
tgtString = re.sub('\r', '', tgtString)
tgtString = re.sub('  ', '', tgtString) 

if tgtString:
try:
tgtString = str(tgtString)
except UnicodeEncodeError:
tgtString = str(tgtString.encode('U8'))

return tgtString


def getYahooAPI():

import os
import sys
from yahoo.search.news import NewsSearch
import re

queryWord = "Singapore"

print ("Fetching data from YahooAPI with query : " + queryWord  )
srch = NewsSearch('YahooDemo',query = "Singapore asean cup", language = 
'en', results = 50)
info = srch.parse_results()
info.total_results_available

homedir = os.getcwd()
tgtFile = homedir + "/Extensions/InputString.txt"

writeFile = open(tgtFile, 'w')

for result in info.results:

writeFile.write("\n")
writeFile.write("\n")
writeFile.write(removeIllegalChars(result['Title'])+ "\n")
writeFile.write("\n")
writeFile.write(removeIllegalChars(result['ClickUrl']) + "\n")
writeFile.write("\n")
writeFile.write(removeIllegalChars(result['Summary']) + "\n")
writeFile.write("\n")
writeFile.write(removeIllegalChars(result['PublishDate']) + 
"\n")
writeFile.write("\n")
writeFile.write(removeIllegalChars(result['NewsSource']) + "\n")
writeFile.write("\n")

writeFile.write(removeIllegalChars(result['Summary']) + "\n")

writeFile.write("")
writeFile.close

def runYahooSearch2(self):

import os
import sys
from yahoo.search.news import NewsSearch
import re


#---

# still trying to figure out how to get the absolute path to this script
# commands below work for windows... but not for linux. Need to find a 
platform
# independant one

# print 'sys.argv[0] =', sys.argv[0] 
# homedir = os.path.dirname(sys.argv[0])   # for windows 
# print 'path =', pathname

getYahooAPI()

homedir = os.getcwd() 
homedir = homedir + "/Extensions"


command = "cd "+homedir
os.popen(command)

command = "java -jar "+ '"' + homedir + "/" + "ActiveLearningTools.jar" 
+ '" ' + "prepArticles >> test.txt" 
os.popen(command)

print "Completed step 1 : preparing the articles"

command = homedir + "/" + "vcluster " + "-zscores " + "ClutoMatrix" + " 
2" 
sysCode = os.system(command)
print "Completed step 2 : Clustering the articles using Cluto"


command = "java -jar "+ '"' + homedir + "/" + "ActiveLearningTools.jar" 
+ '" ' + "processClusters >> output.txt"
sysCode = os.system(command)

filename = homedir +"/output.txt"
openfile = open(filename, 'r')
whatisread = openfile.read()
openfile.close()
#os.remove("output.txt")

return whatisread







___
Zope-Dev maillist  -  Zope-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML enco