Why is pexpect acting funny with sendline() and expect()?

2012-12-26 Thread saqib . ali . 75
I am running Solaris 5-10, python 2.6.2 and pexpect 2.4 I have the very simple python script below which exercises the functionality of sending and receiving text from the shell. My understanding is that pexepect([pexpect.TIMEOUT, x,y,z], timeout=w) will return the index of the match that it

Why does os.stat() tell me that my file-group has no members?

2012-12-19 Thread saqib . ali . 75
I'm using python 2.6.4 on Solaris 5-10. I have a file named myFile. It is owned by someone else, by I (myuser) am in the file's group (mygrp). Below is my python code. Why does it tell me that mygrp has no members??? import os, pwd, grp stat_info = os.stat(myFile) fileUID =

Re: Why does os.stat() tell me that my file-group has no members?

2012-12-19 Thread saqib . ali . 75
Thanks!! This was very helpful. It worked perfectly. I had no clue about the intricacies of how python represents the group data from the underlying OS. This page doesn't go into to detailed explanation like you did: http://docs.python.org/2/library/grp.html On Wednesday, December 19, 2012

Problem while doing a cat on a tabbed file with pexpect

2012-01-15 Thread Saqib Ali
I am using Solaris 10, python 2.6.2, pexpect 2.4 I create a file called me.txt which contains the letters A, B, C on the same line separated by tabs. My shell prompt is % I then do the following in the python shell: import pexpect x = pexpect.spawn(/bin/tcsh) x.sendline(cat me.txt) 11

Re: Problem while doing a cat on a tabbed file with pexpect

2012-01-15 Thread Saqib Ali
, I can't simply open the file in my own python context. On Jan 15, 2:24 pm, Dennis Lee Bieber wlfr...@ix.netcom.com wrote: On Sun, 15 Jan 2012 09:51:44 -0800 (PST), Saqib Ali saqib.ali...@gmail.com wrote: Now, clearly the file contains tabs. But when I cat it through expect, and collect cat's

Re: Problem while doing a cat on a tabbed file with pexpect

2012-01-15 Thread Saqib Ali
...@zip.com.au wrote: On 15Jan2012 23:04, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: | On Sun, 15 Jan 2012 09:51:44 -0800, Saqib Ali wrote: | I am using Solaris 10, python 2.6.2, pexpect 2.4 | | I create a file called me.txt which contains the letters A, B, C | on the same

Changing the system clock with pexpect confuses pexpect!

2011-12-26 Thread Saqib Ali
See my code below. I'm controlling a shell logged in as root with pexpect. The class below has a method (startProc) which spawns a shell and keeps it alive until told to destroy it (stopProc). The other 2 methods in this class allow me to change the system clock and to get the IP Address of

Can't I define a decorator in a separate file and import it?

2011-12-22 Thread Saqib Ali
I'm using this decorator to implement singleton class in python: http://stackoverflow.com/posts/7346105/revisions The strategy described above works if and only if the Singleton is declared and defined in the same file. If it is defined in a different file and I import that file, it doesn't

Re: Can't I define a decorator in a separate file and import it?

2011-12-22 Thread Saqib Ali
MYCLASS.PY: #!/usr/bin/env python import os, sys, string, time, re, subprocess import Singleton @Singleton class myClass: def __init__(self): print 'Constructing myClass' def __del__(self): print 'Destructing myClass' SINGLETON.PY: #!/usr/bin/env python import os,

Re: Can't I define a decorator in a separate file and import it?

2011-12-22 Thread Saqib Ali
BTW Here is the traceback: import myClass Traceback (most recent call last): File stdin, line 1, in module File myClass.py, line 6, in module @Singleton TypeError: 'module' object is not callable Here is Singleton.py: class Singleton: def __init__(self, decorated):

Re: Can't I define a decorator in a separate file and import it?

2011-12-22 Thread Saqib Ali
Thanks for pointing out the mistake! Works. - Saqib On Thu, Dec 22, 2011 at 4:31 PM, Ethan Furman et...@stoneleaf.us wrote: Saqib Ali wrote: MYCLASS.PY: #!/usr/bin/env python import os, sys, string, time, re, subprocess import Singleton This should be 'from Singleton import

Can I get use pexpect to control this process?

2011-12-21 Thread Saqib Ali
I have a program X that constantly spews output, hundreds of lines per minute. X is not an interactive program. IE: it doesn't take any user input. It just produces a lot of textual output to STDOUT. I would like to save the output produced by X into a different file every 5 seconds regardless

Re: Need help with really elementary pexpect fragment

2011-12-20 Thread Saqib Ali
Oops! Good call. Thank you. You pointed out my mistake. - Saqib On Tue, Dec 20, 2011 at 12:31 AM, Nick Dokos nicholas.do...@hp.com wrote: Saqib Ali saqib.ali...@gmail.com wrote: I want to write a pexpect script that simply cd's into a directory (~/ install) and then runs a command

Need help with really elementary pexpect fragment

2011-12-19 Thread Saqib Ali
I want to write a pexpect script that simply cd's into a directory (~/ install) and then runs a command from there. It should be so easy. But even my cd command is failing. Can't figure out what the problem is. The command line prompt is [my machine name here] % Here is the code fragment:

Inexplicable behavior in simple example of a set in a class

2011-07-02 Thread Saqib Ali
I have written two EXTREMELY simple python classes. One class (myClass1) contains a data attribute (myNum) that contains an integer. The other class (myClass2) contains a data attribute (mySet) that contains a set. I instantiate 2 instances of myClass1 (a b). I then change the value of

Re: Inexplicable behavior in simple example of a set in a class

2011-07-02 Thread Saqib Ali
Instance variables are properly created in the __init__() initializer method, *not* directly in the class body. Your class would be correctly rewritten as: class MyClass2(object):     def __init__(self):         self.mySet = sets.Set(range(1,10))     def clearSet(self): # ...rest same