PID and/or handle assistance. . .?

2005-10-22 Thread Michael Williams
Hi All,

Can anyone explain how to both spawn processes from PYTHON and  
acquire their process IDs or a handle to them for use later?  I'd  
also like to acquire the stdout of each spawned process.

Regards,
Mike


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


Re: Re: PID and/or handle assistance. . .?

2005-10-22 Thread Michael Williams
On Oct 22, 2005, at 1:16 PM, [EMAIL PROTECTED] wrote:Michael Williams wrote: Hi All, Can anyone explain how to both spawn processes from PYTHON and  acquire their process IDs or a handle to them for use later?  I'd  also like to acquire the stdout of each spawned process.  Google dead today? Well, check out the modules subprocess, popen2 and os.  Regards,  Diez No, Google certainly isn't dead.  I simply figured I'd ask those in the know instead of mindlessly meandering the web.  Anyway, I've checked out the OS module and although I can find examples of say .fork, and .popen, they aren't extremely informative or straightforward.  Any other ideas/examples?Regards-- 
http://mail.python.org/mailman/listinfo/python-list

Trouble with "freeze.py" importing 3rd Party Modules

2005-11-13 Thread Michael Williams
Can anyone explain why "freeze.py" will make binaries with the std  
modules fine, however, when using 3rd party modules (Pexpect in  
particular) it requires the target system to actually have it installed?

Thanks in advance,
Mike
-- 
http://mail.python.org/mailman/listinfo/python-list


interactive prompts

2005-11-26 Thread Michael Williams
Hi all,

I'm having an issue with environment variables and spawned commands.   
Specifically, I'm using "eval `ssh-agent`" and "ssh-add".  My  
question is, how do I force the environmental variables set by one  
'popen' or 'pexpect' to propagate throughout the entire Python  
session so that any commands called will see those env variables?

Regards,
Michael
-- 
http://mail.python.org/mailman/listinfo/python-list


Creating referenceable objects from XML

2005-12-04 Thread Michael Williams
Hi All,

I'm looking for a quality Python XML implementation.  All of the DOM  
and SAX implementations I've come across so far are rather  
convoluted.  Are there any quality implementations that will (after  
parsing the XML) return an object that is accessible by name? Such as  
the following:




xml = """

MyBook
the author

"""





And after parsing the XML allow me to access it as so:

book.title

I need it to somehow convert my XML to intuitively referenceable  
object.  Any ideas?  I could even do it myself if I knew the  
mechanism by which python classes do this (create variables on the fly).

Thanks in advance!
-- 
http://mail.python.org/mailman/listinfo/python-list


e: Favorite flavor of Linux? (for python or anything else)

2005-12-05 Thread Michael Williams
I'd say Ubuntu.  It has one of the most intuitive package management systems, and manual installation of software seems to work very well.On Dec 5, 2005, at 2:00 AM, [EMAIL PROTECTED] wrote:From: "Mike C. Fletcher" <[EMAIL PROTECTED]> Date: December 5, 2005 12:56:13 AM EST To: [email protected] Subject: Re: Favorite flavor of Linux? (for python or anything else) Reply-To: [EMAIL PROTECTED]   Brett Hoerner wrote:  I have to add another vote for Gentoo.  And another here.  Portage (the Python-coded package-management system) does a very good job.  I tend to use fairly conservative settings as well, Gentoo's just nice and stable as a general rule, I don't care about ultimate speed or tweaking the code much, I just find that building everything from source (but without the headaches) tends to make things work together well.  As far as Python support goes, Gentoo tends to work very well for Python packages, Pygame and wxPython on AMD64, for instance, install flawlessly out of the box (where others seem to have problems)... in fact most of the major packages install reliably.  There's a key note that you might miss regarding the Python updating process, namely that you have to run python-updater to rebuild all of your packages for the new Python version, but once you know that, Pythonicity in Gentoo is pretty straightforward.  Anyway, just a vote that's trying very hard to keep on-topic for the python list, Mike  --  -- 
http://mail.python.org/mailman/listinfo/python-list

dynamic variable referencing

2005-12-06 Thread Michael Williams
I would RTM, but I'm not sure exactly what to look for.  Basically, I  
need to be able to call a variable dynamically.  Meaning something  
like the following:

-  I don't want to say OBJECT.VAR  but rather   
   OBJECT. 
("string")  and have it retrieve the variable (not the value of  
it) if in fact it exists. . .

The purpose is to create an XML tree myself by means of  OBJECT. 
("string").__setattr(name,value).  I eventually want to be able to  
say BOOK[0].AUTHOR.FIRSTNAME . . . that kind of thing.  I've seen  
existing libraries, but I'd really rather know how to do it myself.   
Any assistance would be appreciated.


Regards,
Michael
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: dynamic variable referencing

2005-12-07 Thread Michael Williams
Bruno,Thanks, but the whole reason I need it is to create objects in the tree on the fly.  Every implementation I've seen of Element tree manually assigns values to the nodes and manually places them.  All I care about is that any tags they have are in my list of "valid_tags".  Otherwise they can be in any order, etc.  For instance they could have:	the good one	ted	1945or	1945	the good one	tedI want to avoid the line by line assignments like this:if name == "book":	# do book stuffif name == "title":	#do title stuffI want to assign objects on the fly:if name in valid_tags:	object = Element(name)	if condition:		object = SubElement(Super, object)I'd still need an algorithm that walked the tree and created it for me.  That way, if in fact I decide to allow more XML tags in the future, it's simply a matter of adding a few "valid_tags" to the list and it automatically allows them to be created.  Does that make any sense?Thanks again,MichaelOn Dec 7, 2005, at 5:20 AM, [EMAIL PROTECTED] wrote:Michael Williams wrote: I would RTM, but I'm not sure exactly what to look for.  Basically, I  need to be able to call a variable dynamically.  Meaning something  like the following:              -  I don't want to say     OBJECT.VAR      but rather      OBJECT. ("string")      and have it retrieve the variable (not the value of  it) if in fact it exists. . .  getattr(obj, 'name', defaultvalue)  You can also implement the special methods __getitem__ and __setitem__ to allow indexed access to attributes, ie:  class FalseDict(object):   def __init__(self, toto, tata):      self.toto = toto      self.tata = tata   def __getitem__(self, name):      return getattr(self, name)   def __setitem__(self, name, value):      setattr(self, name, value)  f = FalseDict('toto', 'tata') f['toto'] f['tata'] = 42   The purpose is to create an XML tree myself   Don't reinvent the wheel. ElementTree (and it's C based brother) are very good at this.  --  bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')])"  -- 
http://mail.python.org/mailman/listinfo/python-list

Re: Python-list Digest, Vol 27, Issue 123

2005-12-08 Thread Michael Williams
Thanks, Heiko, I'll give this a try.  In the meantime, I'll try to explain what exactly I mean.Basically, I want the ability to reference a variable just as I am able to set a variable (or attribute) on the fly.  For instance, say the user has the following list in a text file:	[butter, cream, eggs, toast, jam]I want to be able to loop through that and say the following:	item.__setattr__(list[0].value,myclass())At that point I have  item.butter, but I don't want to have to know (or hardcode) this, I want to then be able to do the following:	item.__getattr__(list[0].value).__setattr__(list[1].value)So that I now have:	item.butter.cream. . .and so on and so forth.  I want the entire thing to be dynamically created no matter what the user has entered.  And I for my part will simply limit the users input with a list of my own like so:if list[i].value not in my_list:	raise MyError()I don't doubt that that's probably more confusing, but that's what I want to be able to do.Regards,MichaelOn Dec 7, 2005, at 1:45 AM, [EMAIL PROTECTED] wrote:It's not exactly clear what you're trying to tell us here. Basically, what I guess you want is:  getattr(object,"varname")  This retrieves the value that is bound to varname at "namespace" object. You cannot retrieve a variable per se in Python, as a variable is just a name that is a binding to an object.  The second part of what you're trying to do sounds more like stacking objects. I'll just give it a shot and implement a little bit to test on. You'll have to extend it to suit your needs... ;-)  class xmlnode(object):      def __init__(self):         self.__subnodes = {}         self.__value = ""      def __getattr__(self,item):         if item == "value":             return self.__value         elif item.startswith("_"):             raise AttributeError, item         elif item not in self.__subnodes:             self.__subnodes[item] = xmlnode()         return self.__subnodes[item]      def __setattr__(self,item,value):         if item.startswith("_"):             super(xmlnode,self).__setattr__(item,value)         elif item == "value":             assert isinstance(value,(str,unicode))             self.__value = value         else:             assert isinstance(value,(str,unicode))             if item not in self.__subnodes:                 self.__subnodes[item] = xmlnode()             self.__subnodes[item].value = value      def __delattr__(self,item):         if item.startswith("_"):             super(xmlnode,self).__delattr__(item)         elif item == "value":             self.__value = None         else:             try:                 del self.__subnodes[item]             except KeyError:                 raise AttributeError, item      def toXML(self,name):         rv = ["<%s>" % name]         for sname, sitem in self.__subnodes.iteritems():             rv.append(sitem.toXML(sname))         if self.__value is not None:             rv.append(self.__value)         rv.append("" % name)         return "".join(rv)  This implements a simple XML-tree builder with a very specific output format (tags contain only one string value, which always comes after any subtag that they might contain, and subtag order is random). The "tricky" part is in the __*attr__ logic to get subnodes.  Example of usage:  a = test.xmlnode() a  a.value = "test" a.toXML("root") 'test' a.book = "welcome" a.anotherbook = "bye" a.toXML("root") 'byewelcometest' a.book.value 'welcome' a.book.anotherbook.somethingelse.thisislong = "test" a.toXML("root") 'byetestwelcometest'   HTH!  --- Heiko.   -- 
http://mail.python.org/mailman/listinfo/python-list

Freeze doesn't import all modules . . .

2005-12-09 Thread Michael Williams
Is there any way to FORCE freeze to import all necessary modules no  
matter what?  I have noticed that a few 3rd party modules simply  
don't get included in a "compiled" bundle.  More specifically,   
"PEXPECT", and some of the required "AMARA" xml modules aren't  
included when you freeze a python script. I've checked this out on  
both Ubuntu 5.10 systems and Mac OS X systems.  Whenever I run the  
compiled version on one of my "matching" systems, it simply tells me  
that "there is no module pexpect" or that "there is no module dom".   
To my knowledge, I shouldn't have to have *anything* installed on the  
receiving system.  Is that not correct?

Regards,
Michael
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to stop a linux process

2005-12-09 Thread Michael Williams
You may check out the  http://pexpect.sourceforge.net/ module.  This gives you pretty good control over running processes.  It even allows you to "interact" with them.Regards,MichaelOn Nov 28, 2005, at 4:00 PM, [EMAIL PROTECTED] wrote:From: Glen <[EMAIL PROTECTED]> Date: November 28, 2005 2:10:05 PM EST To: [email protected] Subject: How to stop a linux process   When I used the following line to play a midi file in linux,  return_value = os.system('timidity test.mid')  I have encountered two problems. 1. The python script halts until timidity has finished. 2. If I had control of the script, I can't think how I would stop timidity.  Any advice on the 'area' of python I should be looking at would be greatly appreciated.  Thanks. -- 
http://mail.python.org/mailman/listinfo/python-list

Using XML w/ Python...

2005-12-11 Thread Michael Williams
If you just want to get into it and use it, I'd recommend the following:	http://uche.ogbuji.net/uche.ogbuji.net/tech/4suite/amara/It requires the installation of the 4Suite module as well, but it's well worth it.  I uses data binding techniques to convert your document into a large tree of named XML Object (for lack of a better explanation).  You will then be able to output any portion by calling something like the following:	document.body.text.xml()What you call, of course, will depend on the name of each of your nodes in the document.  Keep in mind as well that currently there are a couple of issues with "freezing" this into a binary as well.  If you just plan to let Python interpret it without "compiling" you will be fine.  Amara is an amazing product.  And being free doesn't hurt.  ;)Regards,MichaelOn Dec 11, 2005, at 1:15 AM, [EMAIL PROTECTED] wrote:OK, I have this  XML doc, i dont know much about XML, but what i want to do is take certain parts of the XML doc, such as  blah  and take just that and put onto a text doc. Then same thing doe the  part. Thats about it, i checked out some of the xml modules but dont understand how to use them. Dont get parsing, so if you could please explain working with XML and python to me. Email me at [EMAIL PROTECTED]  Aim- jayjay08balla MSN- [EMAIL PROTECTED] Yahoo- raeraefad72   Thx -- 
http://mail.python.org/mailman/listinfo/python-list

Re: a good programming text editor (not IDE)

2006-06-15 Thread Michael Williams
If you're on a Mac, I'd recommend TextWrangler (http:// 
www.barebones.com/products/textwrangler/) hands down.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: what's wrong with my popen reasoning?

2006-02-05 Thread Michael Williams
Hello,I would possibly look into using Pexpect (http://pexpect.sourceforge.net/) and the python "time" module for things of this nature.  It gives you a bit more granular control over what happens when.Regards,MichaelOn Feb 5, 2006, at 2:57 PM, [EMAIL PROTECTED] wrote:From: Rick Spencer <[EMAIL PROTECTED]> Date: February 5, 2006 1:39:18 PM EST To: [email protected] Subject: what's wrong with my popen reasoning?   Hi all,  I am very new to Python programming. I am writing a program to manage wireless connections, this is for GNOME on Linux. I present the user with a "connect" button. I want to handle the connection for them slightly different depending on whether or not the wireless access point they are trying to connect to is secure. In either case, I have a similar question.   In the first case, the wireless access point is secured. I want to bring up the GNOME applet for configuring a wireless access interface.  I can pass the command line commands to bring it up, but I can't figure out how to bring it up in a modal fashion, so that my Python program waits for the user to dismiss it before my program gets control again.  In the second case, the access point is not secured. I just want to fire off the command line utility (iwconfig) for connecting. In this case, I want my program to wait until iwconfig is done before continuing on. I figure that I could just write a line of code to read in from the console, but I thought there might be a more pythonic way of doing it.   Here's my function so far, with variables replaced with constants to make it easier to read:  def connect_clicked(self, widget, data="">  if locked:   os.popen("sudo network-admin -c ath0")   self.emit('connection-attempted', "ath0")   else:   os.popen("sudo iwconfig ath0 ap 00:0F:B3:31:CB:01")  self.emit('connection-attempted', "ath0")  Thanks much!  Cheers, Rick  -- 
http://mail.python.org/mailman/listinfo/python-list

Using "subprocess" without lists. . .?

2007-05-13 Thread Michael Williams
Hi All,

I've recently seen the "subprocess" module and am rather confused by  
it's requirements.  Is it not possible to execute an entire string  
without having to break them up into a list of arguments?  For  
instance, I'd much rather do the following:


subprocess.call("ls -al | grep -i test")


. . .than to have to:


list = ["ls", "-a", "-l" ]  . . . . . . and so on and so forth.
subprocess.call(list. . .)


What is the best way to go about executing a massively complex single  
line command?


Thanks,
Michael
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using "subprocess" without lists. . .?

2007-05-13 Thread Michael Williams


I'm not sure you replied entirely to the correct post.  Basically I'm  
interested in encoding video with FFMPEG, but there will be variable  
length commands so I'd rather be able to type a single string for the  
"command" as opposed to having to enter it in the form of a list.   
And there is really no way to properly parse because some options  
have values and others are simply flags.


Thanks,
Michael

On May 13, 2007, at 2:17 PM, Steven Howe wrote:


Michael Williams wrote:

Hi All,

I've recently seen the "subprocess" module and am rather confused by
it's requirements.  Is it not possible to execute an entire string
without having to break them up into a list of arguments?  For
instance, I'd much rather do the following:


subprocess.call("ls -al | grep -i test")


. . .than to have to:


list = ["ls", "-a", "-l" ]  . . . . . . and so on and so forth.
subprocess.call(list. . .)


What is the best way to go about executing a massively complex single
line command?


Thanks,
Michael


How about a hybrid solution?:
from subprocess import Popen, PIPE
from string import strip
(stdout, stderr) = Popen(['ls','-al'], stdout=PIPE,  
stderr=PIPE).communicate()
# process spins off. Ideally, you should wait for it to complete,  
or assign the resulting object of Popen
# to a variable and inquire if it's completed via the 'poll()'  
operator or wait on it via the 'wait()'

# operator.
# then query the stderr via communicate()[1]; if good, i.e. len 
(stderr) == 0, inspect the resulting
# stdout string (via communicate()[0]) for your 'test' result. But  
I'm being lazy. I assume the call to

# ls -al will be faster then my next statement.
res = []
for line in stdout.strip():
if 'test' in line:
   res.append( line )

Do the work you need done at the shell prompt, do the rest in  
Python. Also I wonder if, you were looking for the word 'test' in  
the filename,  glob.glob wouldn't have been a bit more efficient?  
But if you were looking for a 'test' owner or group then using:
glob.glob(): get the list of  files, with directory. Example:   
glob.glob('/bin/*')
os.stat(): get an object of stats on a file. Example: os.stat('/bin/ 
ls')
stat.ST_UID: get just the group id, as an integer from the object  
returned by os.stat. Example: os.stat('/bin/ls')[stat.ST_UID]

pwd.getpwgid(): get the string translation of a UID. Example:
pwd.getpwgid( os.stat('/bin/ls')[stat.ST_UID] )
stat.ST_GID: get the group id, as an integer from the object  
returned os.stat. Example:

os.stat('/bin/ls')[stat.ST_GID]
grp.getgrgid(): get the string translation of a UID. Example:
grp.getgrgid( os.stat('/bin/ls')[stat.ST_UID] )
Now I have a list, which I iterate over, getting the UID and GID,  
as strings, that I can compare to. I never had to use a subprocess  
and having to build up a 'wait on done loop'.  Note, grp and pwd, I  
think, are Python/Unix functions. What one does on Windows I don't  
know, but I'll bet there are similar functions under Python/ 
Windows. Don't get me wrong, Subprocess is a fast and damn useful  
tool. I often use it to verify a program is in my path, before  
creating a subprocess to run some task python isn't built for (like  
mencoder functionality).


You see, the issue is: shell, python & shell or python alone. When  
transitioning from one language to another, say C/C++/Java to  
Python, it is often easier to use your knowledge of the shell  
command (bash/Bourne for example) to get things done. But it's only  
a transitional issue. The need to use the shell is a good  
demonstrator that either the Interpretor is weak, or that you  
haven't fully explored it's abilities. With the Python Interpretor  
at v2.4 going onto v2.5, it's very likely that the desired feature  
exists; you have but to do some clever research to find it. As to  
clever research ... I find Google a good place to start.


I had some familiarity with os.stat and glob. But the grp and pwd  
functions were things I discovered from http://docs.python.org/ 
modindex.html and about two minutes of searching for 'python uid to  
name' @ Google.


Also, os.listdir and os.path.join would have worked just as well as  
glob.glob('dirname/*'). But glob.glob was faster to write. Even a  
better choice would have been to use the 'os.walk' to iterate over  
the directory tree.


sph.

--
HEX: 09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0


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