[Tutor] Is it possible?

2008-02-08 Thread Nathan McBride
Is it possible to write a program that you pipe other programs through
and it measures the MBs per second of data moved?  Like I could pipe it
a cp and find out how fast the cp is working?

Thanks,
Nate

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] beginner pexpect question

2008-02-13 Thread Nathan McBride
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Hey guys,

I'm practically still a beginner with python.  I am working on a program
that originally I used popen for but then switched to pexpect because it
was easier for me to understand.
I was hoping someone could help me get this working:

I do a:

child = pexpect.spawn ('cryptsetup --verbose --cipher
"aes-cbc-essiv:sha256" --key-size 256 --verify-passphrase luksFormat ' +
self.loopdevice)
i = child.expect ([pexpect.TIMEOUT, '.*'])
if i == 0:
print 'ERROR!'
print child.before, child.after
child.sendline ('YES')
print "Sent YES"
child.expect ('.*')
#child.sendline ('Test')
child.send ('Test\n')
print "Sent Pass 1"
child.expect ('.*')
child.send ('Test\n')
print "Sent Pass 2"
#child.sendline ('Test')

This runs without errors but then to test I do a:

[EMAIL PROTECTED] project]# losetup /dev/loop0 /home/user/deleteme
[EMAIL PROTECTED] project]# cryptsetup luksOpen /dev/loop0 encr-container1
Enter LUKS passphrase:
/dev/loop0 is not a LUKS partition
Command failed: No key available with this passphrase.

I can't understand this at all.  If anyone can help I would appreciate
it a lot.

Thanks very much,
Nate

-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.7 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org

iD8DBQFHsxnq/n+duykW6K8RAufNAKDP3BNCDAC/ALFuH8ht8qyETy5/xQCfS4i7
2aA9UoTLBZDRst0LPA9YstM=
=rcB6
-END PGP SIGNATURE-

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] beginner pexpect question

2008-02-13 Thread Nathan McBride
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Anyone have any recomendations?  Seems like it is giving it the
passwords since it finishes cleanly,
but maybe not like I think?

Nate

Nathan McBride wrote:
> Hey guys,
>
> I'm practically still a beginner with python.  I am working on a program
> that originally I used popen for but then switched to pexpect because it
> was easier for me to understand.
> I was hoping someone could help me get this working:
>
> I do a:
>
> child = pexpect.spawn ('cryptsetup --verbose --cipher
> "aes-cbc-essiv:sha256" --key-size 256 --verify-passphrase luksFormat ' +
> self.loopdevice)
> i = child.expect ([pexpect.TIMEOUT, '.*'])
> if i == 0:
> print 'ERROR!'
> print child.before, child.after
> child.sendline ('YES')
> print "Sent YES"
> child.expect ('.*')
> #child.sendline ('Test')
> child.send ('Test\n')
> print "Sent Pass 1"
> child.expect ('.*')
> child.send ('Test\n')
> print "Sent Pass 2"
> #child.sendline ('Test')
>
> This runs without errors but then to test I do a:
>
> [EMAIL PROTECTED] project]# losetup /dev/loop0 /home/user/deleteme
> [EMAIL PROTECTED] project]# cryptsetup luksOpen /dev/loop0 encr-container1
> Enter LUKS passphrase:
> /dev/loop0 is not a LUKS partition
> Command failed: No key available with this passphrase.
>
> I can't understand this at all.  If anyone can help I would appreciate
> it a lot.
>
> Thanks very much,
> Nate
>

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.7 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org

iD8DBQFHs2wb/n+duykW6K8RAhcgAJ0T9f5WlxYCFtUtjBirdhxs3jfzzACeJNXr
x8TGYUdeRNbjzw51pG8J+Jg=
=qoOB
-END PGP SIGNATURE-

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to get response from os.system()

2008-03-16 Thread Nathan McBride
Why don't you just use 'commands.getoutput'?

-Original Message-
From: linuxian iandsd <[EMAIL PROTECTED]>
Sent: Sunday, March 16, 2008 3:12 PM
To: tutor@python.org
Subject: Re: [Tutor] how to get response from os.system()

use os.popen("your cmd here")

On Sun, Mar 16, 2008 at 8:06 PM, Luke Paireepinart <[EMAIL PROTECTED]>
wrote:

> shawn bright wrote:
> > Lo there all,
> >
> >  I am needing to get a response back from a system command.
> >  i can do this:
> >
> >  os.system('mailq | wc -l")
> >
> >  if i do this in the terminal  mailq | wc -l   ,   it will spit out a
> number.
> > How do i get that number as a python variable ?
> You need to use the subprocess module, specifically subprocess.Popen, to


[The entire original message is not included]
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to get response from os.system()

2008-03-16 Thread Nathan McBride
Would you mind perhaps show an example running an interactive command like su 
and show how to send input to the commands waiting propmts?

-Original Message-
From: linuxian iandsd <[EMAIL PROTECTED]>
Sent: Sunday, March 16, 2008 3:17 PM
To: tutor@python.org
Subject: Re: [Tutor] how to get response from os.system()

i guess that was too short tutorial well, here is an example from a live
session on the interpreter.

[EMAIL PROTECTED] ~]# python
Python 2.5.1 (r251:54863, Nov 23 2007, 16:16:53)
[GCC 4.1.1 20070105 (Red Hat 4.1.1-51)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> cmd='ping -c 1 localhost'
>>> import os
>>> a=os.popen(cmd)
>>> print a

>>> print a.read()
PING serv.kontactel.loc (127.0.0.1) 56(84) bytes of data.
64 bytes from serv.kontactel.loc (127.0.0.1): icmp_seq=1 ttl=64 time=0.134ms



[The entire original message is not included]
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to get response from os.system()

2008-03-16 Thread Nathan McBride
Yup I use the pexpect module for a lot however couldn't get 'pexpect.run' to 
work with mysqldump piping to gzip 

-Original Message-
From: Jeff Younker <[EMAIL PROTECTED]>
Sent: Sunday, March 16, 2008 6:59 PM
To: Nathan McBride <[EMAIL PROTECTED]>
Cc: tutor@python.org
Subject: Re: [Tutor] how to get response from os.system()


> Would you mind perhaps show an example running an interactive  
> command like su and show how to send input to the commands waiting  
> propmts?

If you're doing that then you *really* want to be using the pexpect
module.

cmd = pexpect.spawn('su - SOMEINTERACTIVECOMMAND')
cmd.expect('# ')   # the prompt
cmd.sendline('A COMMAND')
cmd.expect('# ')   # wait for the prompt again
output = cmd.before  # the stuff before the prompt
cmd.sendline('exit')
cmd.close()


- Jeff Younker - [EMAIL PROTECTED] -



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to get response from os.system()

2008-03-17 Thread Nathan McBride
That's a great tip I'll have to save than.

-Original Message-
From: Martin Walsh <[EMAIL PROTECTED]>
Sent: Monday, March 17, 2008 9:38 AM
To: Nathan McBride <[EMAIL PROTECTED]>
Cc: tutor@python.org
Subject: Re: [Tutor] how to get response from os.system()


Hi Nathan,

Nathan McBride wrote:
> Yup I use the pexpect module for a lot however couldn't get 'pexpect.run' to 
> work with mysqldump piping to gzip 
> 

Just to hazard a guess -- when you want to pipe commands with pexpect
you have to spawn ('run', it seems, would work the same way) the shell
command as an argument to bash (or similar) since pexpect does not
natively interpret shell operators or wildcards, like redirect, pipe, etc..
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to get response from os.system()

2008-03-17 Thread Nathan McBride
That's a great tip I'll have to save than.

-Original Message-
From: Martin Walsh <[EMAIL PROTECTED]>
Sent: Monday, March 17, 2008 9:38 AM
To: Nathan McBride <[EMAIL PROTECTED]>
Cc: tutor@python.org
Subject: Re: [Tutor] how to get response from os.system()


Hi Nathan,

Nathan McBride wrote:
> Yup I use the pexpect module for a lot however couldn't get 'pexpect.run' to 
> work with mysqldump piping to gzip 
> 

Just to hazard a guess -- when you want to pipe commands with pexpect
you have to spawn ('run', it seems, would work the same way) the shell
command as an argument to bash (or similar) since pexpect does not
natively interpret shell operators or wildcards, like redirect, pipe, etc..
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to get response from os.system()

2008-03-17 Thread Nathan McBride
That's a great tip I'll have to save than.

-Original Message-
From: Martin Walsh <[EMAIL PROTECTED]>
Sent: Monday, March 17, 2008 9:38 AM
To: Nathan McBride <[EMAIL PROTECTED]>
Cc: tutor@python.org
Subject: Re: [Tutor] how to get response from os.system()


Hi Nathan,

Nathan McBride wrote:
> Yup I use the pexpect module for a lot however couldn't get 'pexpect.run' to 
> work with mysqldump piping to gzip 
> 

Just to hazard a guess -- when you want to pipe commands with pexpect
you have to spawn ('run', it seems, would work the same way) the shell
command as an argument to bash (or similar) since pexpect does not
natively interpret shell operators or wildcards, like redirect, pipe, etc..
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to get response from os.system()

2008-03-17 Thread Nathan McBride
That's a great tip I'll have to save than.

-Original Message-
From: Martin Walsh <[EMAIL PROTECTED]>
Sent: Monday, March 17, 2008 9:38 AM
To: Nathan McBride <[EMAIL PROTECTED]>
Cc: tutor@python.org
Subject: Re: [Tutor] how to get response from os.system()


Hi Nathan,

Nathan McBride wrote:
> Yup I use the pexpect module for a lot however couldn't get 'pexpect.run' to 
> work with mysqldump piping to gzip 
> 

Just to hazard a guess -- when you want to pipe commands with pexpect
you have to spawn ('run', it seems, would work the same way) the shell
command as an argument to bash (or similar) since pexpect does not
natively interpret shell operators or wildcards, like redirect, pipe, etc..
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Maybe advanced pexpect question?

2008-03-22 Thread Nathan McBride
I've used pexpect for a few projects and love it.  Basically pexpect
lets you spawn a program and interact with it from code like you
yourself were running it in a console.  How would you send the ctrl key?

nomb

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Maybe advanced pexpect question?

2008-03-25 Thread Nathan McBride
I'm thinking more along the lines as of running a program, sending tab
to get to the field send text to put on the field, tab, send text ?

On Sun, 2008-03-23 at 14:00 -0500, mwalsh wrote:
> Kent Johnson wrote:
> > Nathan McBride wrote:
> >> I've used pexpect for a few projects and love it.  Basically pexpect
> >> lets you spawn a program and interact with it from code like you
> >> yourself were running it in a console.  How would you send the ctrl key?
> > 
> > I don't use pexpect, so I am guessing...
> > 
> > The ctrl key by itself is not a character so you can't send that. ctrl-C 
> > is a character that is represented in a string as \x03. I expect you 
> > would send a control character with sendline(), for example to sent 
> > ctrl-C try
> >child.sendline ('\x03')
> 
> In recent versions of pexpect (I'm looking at 2.3), 'spawn' objects 
> include a sendcontrol  method which does almost exactly that for cntl-c, 
> with send instead of sendline.
> 
> > Kent
> > ___
> > Tutor maillist  -  Tutor@python.org
> > http://mail.python.org/mailman/listinfo/tutor
> 
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] socket / over network

2008-04-03 Thread Nathan McBride
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Hey guys,

I'm pretty tired of the lame backup solution we have at work.
Could anyone point me to a (more or less newbieish) example of how to
have python open a socket on one box and get data from it, then have another
box write to it over the network?  I'm having trouble finding something like
this.

Thanks,

Nate
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.7 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org

iD8DBQFH9PUf/n+duykW6K8RAvXMAKCE5708Bly/9fzHFZu45cd/d11WGQCdGNcG
PWcbs2jjZXv7b586aNAnSv4=
=9uBW
-END PGP SIGNATURE-

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] socket / over network

2008-04-06 Thread Nathan McBride
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Alan Gauld wrote:
> "Nathan McBride" <[EMAIL PROTECTED]> wrote
>
> Hi Nathan,
>
> Please don't reply to an existing message to start a new discussion.
> It messes up those of us using threaded mail/news readers and
> increases the likelihood that your message will be missed.
>
>> I'm pretty tired of the lame backup solution we have at work.
>> Could anyone point me to a (more or less newbieish) example of how
>> to
>> have python open a socket on one box and get data from it, then have
>> another
>> box write to it over the network?
>
> For a very simple example of using a socket you could try the
> Network Programming topic in my tutorial.
>
> There is also a HowTo or Topic guide on the Python web site
> that gives a more detailed example.
>
> That having been said, backups are usually best done using
> OS tools or if you must roll your own then using ftp or similar
> as a file transfer mechanism rather than trying to send a
> bytestream over a socket. ftp can handle broken connections
> etc more easily. Detecting and fixing errors over a socket
> stream is non trivial and for backups is pretty much essential!!
>
Going off of wha tyou said, if I choose to use ftp, is there a way i
could do everything from within python including the server to get the
files?  Is there like a ftp module for python to help in the passing of
the files between the computers?

Thanks,

Nate
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.7 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org

iD8DBQFH+YH1/n+duykW6K8RAhv+AJoCDvQip6Q1wJSh3dEoRZoC4Gx3oACdF0DK
oQXQTccEnkEz0mf/Qo4Ywqo=
=QRMr
-END PGP SIGNATURE-

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] free loop device

2008-05-05 Thread Nathan McBride
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Hey Guys,

I have a program that uses the loop devices.  However I originally was
finding the free one with:
'losetup -f'.  Which returns the next free loop device. :D  However, I
found that some of the other distros
have a version of losetup that does not include that switch.  So I am
trying to work up another way to get the
next device.

What I'm figuring is doing 'losetup -a', parsing the returned data, and
incrementing it by one...
However I don't know how to accomplish this.  An example 'losetup -a'
would be like this:

[EMAIL PROTECTED] Desktop]# losetup -a
/dev/loop0: [fd00]:11305639 (enc)
/dev/loop1: [fd00]:11306533 (/home/nmcbride/Desktop/xxx.iso)

Can anyone give me a hand?

Thanks,
Nate
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.7 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org

iD8DBQFIH2Oo/n+duykW6K8RAnCTAJ480KREx5udm22wFx3KbNQ08p6AeQCfcfoO
IS+ZG3J8M1/oEjcHN/pLhU4=
=5zQk
-END PGP SIGNATURE-

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] free loop device

2008-05-05 Thread Nathan McBride
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Yup, I got some help in IRC.  What I ended up doing was using regex to
pull out each "/dev/loopX".  Then
took the X and fed it to max which in turn gave me the highest numbered
loop device in use.  After which I
then just added 1 to X and added it to the end of "/dev/loop_".  The
only other thing I had to do was put a
check in incase there were no used loop devices in which case then it
defaults to "/dev/loop0".

Works like a charm. :D

Nate

bob gailer wrote:
> Nathan McBride wrote:
>> -BEGIN PGP SIGNED MESSAGE-
>> Hash: SHA1
>>
>> Hey Guys,
>>
>> I have a program that uses the loop devices.  However I originally was
>> finding the free one with:
>> 'losetup -f'.  Which returns the next free loop device. :D  However, I
>> found that some of the other distros
>> have a version of losetup that does not include that switch.  So I am
>> trying to work up another way to get the
>> next device.
>>
>> What I'm figuring is doing 'losetup -a', parsing the returned data, and
>> incrementing it by one...
>> However I don't know how to accomplish this.  An example 'losetup -a'
>> would be like this:
>>
>> [EMAIL PROTECTED] Desktop]# losetup -a
>> /dev/loop0: [fd00]:11305639 (enc)
>> /dev/loop1: [fd00]:11306533 (/home/nmcbride/Desktop/xxx.iso)
>>
>> Can anyone give me a hand?
>>  
>
> I for one have no idea how this relates to Python. If others do then
they are likely to help you.
>
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.7 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org

iD8DBQFIH78C/n+duykW6K8RAuE3AJoDu69W1D7dldLPxXpCfRGuoc++FQCgj2G3
4fG0aSw7fe/noi4hqesG9oA=
=vas+
-END PGP SIGNATURE-

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor