Re: [Tutor] Working with bash (subversion)

2007-07-18 Thread Luke Paireepinart
Justin Cardinal wrote:
> That fixed it, thanks! Now I just need to do some studying on working with
> lists (or whatever this output is...) so I can filter out the results I
> don't want. Here's an updated version of the program:
> 
> #!/usr/bin/env python
>  
> import commands as c
>
> lsout = c.getoutput('ls -d /home/svn/repository/*/').split('\n')
> results = []
> for row in lsout:
>   temp = c.getoutput('svnadmin lslocks ' + row).split('\n')
>   if temp != ['']:
> results.append(temp)
>   
temp is a list, so results is going to end up being a list of lists. is 
that the desired behavior?
> print results 
> 
> ...and the output:
> 
> ['Path: /test/trunk/data.bin', 'UUID Token:
> opaquelocktoken:9ee85aae-c9dc-4388-8958-87b708e628a3', 'Owner: jcardinal',
> 'Created: 2007-07-17 14:36:18 -0500 (Tue, 17 Jul 2007)', 'Expires: ',
> 'Comment (1 line):', '', '']
> 
>
> Thanks very much to all who replied, it's amazing how quick help arrives!
>   
Well, I for one would rather answer your questions than study for a 
Differential Equations test :)
> -Justin
-Luke
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Working with bash (subversion)

2007-07-18 Thread Luke Paireepinart
Tiger12506 wrote:
>>  results.write(c.getoutput('svnadmin lslocks ' + eval(row)))
>> 
>
> Mmm... I want to add that the eval function tries to execute whatever is in 
> the argument passed as python expressions.
>   
Did I not say that already? ;)
I guess my term 'command' was the problem, eh?
-Luke
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Working with bash (subversion)

2007-07-18 Thread Justin Cardinal
That fixed it, thanks! Now I just need to do some studying on working with
lists (or whatever this output is...) so I can filter out the results I
don't want. Here's an updated version of the program:

#!/usr/bin/env python
 
import commands as c

lsout = c.getoutput('ls -d /home/svn/repository/*/').split('\n')
results = []
for row in lsout:
  temp = c.getoutput('svnadmin lslocks ' + row).split('\n')
  if temp != ['']:
results.append(temp)
print results 

...and the output:

['Path: /test/trunk/data.bin', 'UUID Token:
opaquelocktoken:9ee85aae-c9dc-4388-8958-87b708e628a3', 'Owner: jcardinal',
'Created: 2007-07-17 14:36:18 -0500 (Tue, 17 Jul 2007)', 'Expires: ',
'Comment (1 line):', '', '']


Thanks very much to all who replied, it's amazing how quick help arrives!
-Justin

> Here's what I've got so far:
> =
> #!/usr/bin/env python
>  
> import commands as c
>  
> lsout = c.getoutput('ls -d /home/svn/repository/*/').split('\n')
> results = file("results.txt", "w")
> for row in lsout:
>   results.write(c.getoutput('svnadmin lslocks ' + eval(row))) 
> ===
> Traceback (most recent call last):
>   File "checklocks.py", line 8, in ?
> results.write(c.getoutput('svnadmin lslocks ' + eval(row)))
>   File "", line 1
> /home/svn/repository/projecta/
> ^
> SyntaxError: invalid syntax
> ===
>  
> Any advice would be much appreciated. Thanks!
eval evaluates the string as a python command.
Because there are no Python commands that start with a forward slash,
Python's pointing to this as a syntax error.
Because row is a string already (and note that 'column' would be a more apt
term for this, as a 1-dimensional list is more similar to a single row than
a single column) you can just do simple string concatenation (or you can use
string substitution but in this case it's not necessary and would just make
your code less readable.) Here's a basic example:
 >>> 'hello ' + 'world!'
'hello world!'

Does that tell you everything you need to know?
(recall that whether 'world!' is referenced using a variable name or used
directly, the effect will be the same.  I.E.
a = 'ba'
a + 'nana'
has the same end result as
'ba' + 'nana'with the exception being that the variable 'a' is not 
defined or is not bound to a new value after this statement.)

HTH,
-Luke

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


Re: [Tutor] Working with bash (subversion)

2007-07-18 Thread Tiger12506
>  results.write(c.getoutput('svnadmin lslocks ' + eval(row)))

Mmm... I want to add that the eval function tries to execute whatever is in 
the argument passed as python expressions.

>>> eval('1+2')
3
>>> row = 4
>>> 1+row
5
>>> eval('1+row')
5
>>>

JS 

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


Re: [Tutor] Working with bash (subversion)

2007-07-18 Thread Andreas Kostyrka
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

mkarg is quite useful, from time to time.

Andreas

Luke Paireepinart wrote:
> Justin Cardinal wrote:
>> I'm trying to write a program that will list all subversion repository 
>> directories, then issue a command using each directory as an argument, 
>> then parse those results. So far, I'm able to get a list of the 
>> directories...and that's it!
>> Here's what I've got so far:
>> =
>> #!/usr/bin/env python
>>  
>> import commands as c
> As a side note, why is this 'commands' module part of the standard library?
> it just appears to wrap os.popen in a very bare way and it is not 
> platform-independent.
> It seems pretty useless, as far as I can tell.
> -Luke
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGnorcHJdudm4KnO0RAilrAKCDCM5eOvtqgVJ0ViouGpuEqOjDOACgxg88
4sCL39aNoFiZqRR4e1zUEJk=
=Q4ZW
-END PGP SIGNATURE-
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Working with bash (subversion)

2007-07-18 Thread Luke Paireepinart
Justin Cardinal wrote:
> I'm trying to write a program that will list all subversion repository 
> directories, then issue a command using each directory as an argument, 
> then parse those results. So far, I'm able to get a list of the 
> directories...and that's it!
> Here's what I've got so far:
> =
> #!/usr/bin/env python
>  
> import commands as c
As a side note, why is this 'commands' module part of the standard library?
it just appears to wrap os.popen in a very bare way and it is not 
platform-independent.
It seems pretty useless, as far as I can tell.
-Luke
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Working with bash (subversion)

2007-07-18 Thread Luke Paireepinart
Justin Cardinal wrote:
> I'm trying to write a program that will list all subversion repository 
> directories, then issue a command using each directory as an argument, 
> then parse those results. So far, I'm able to get a list of the 
> directories...and that's it!
> Here's what I've got so far:
> =
> #!/usr/bin/env python
>  
> import commands as c
>  
> lsout = c.getoutput('ls -d /home/svn/repository/*/').split('\n')
> results = file("results.txt", "w")
> for row in lsout:
>   results.write(c.getoutput('svnadmin lslocks ' + eval(row)))
> =
> lsout is a list of repository directories, like I wanted. 
> (['/home/svn/repository/projecta/', '/home/svn/repository/projectb/', 
> '/home/svn/repository/projectc/']
> The next 3 lines are probably totally wrong. I want to perform the 
> following bash command for each directory...
> ==
> svnadmin lslocks /home/svn/repository/projecta
> ==
> ...and then parse the results. I just don't know where/how to store 
> the results from each svnadmin command. When I run the program in its 
> current form, I get the following error:
> ===
> Traceback (most recent call last):
>   File "checklocks.py", line 8, in ?
> results.write(c.getoutput('svnadmin lslocks ' + eval(row)))
>   File "", line 1
> /home/svn/repository/projecta/
> ^
> SyntaxError: invalid syntax
> ===
>  
> Any advice would be much appreciated. Thanks!
eval evaluates the string as a python command.
Because there are no Python commands that start with a forward slash, 
Python's pointing to this as a syntax error.
Because row is a string already (and note that 'column' would be a more 
apt term for this, as a 1-dimensional list is more similar to a single 
row than a single column)
you can just do simple string concatenation (or you can use string 
substitution but in this case it's not necessary and would just make 
your code less readable.)
Here's a basic example:
 >>> 'hello ' + 'world!'
'hello world!'

Does that tell you everything you need to know?
(recall that whether 'world!' is referenced using a variable name or 
used directly, the effect will be the same.  I.E.
a = 'ba'
a + 'nana'
has the same end result as
'ba' + 'nana'with the exception being that the variable 'a' is not 
defined or is not bound to a new value after this statement.)

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