reading a line in file

2007-08-20 Thread Brian McCann
 
Hi,
 
does anyone have a good example of how to read a line in a file?

say you have a file build.log and in the file are values like

buildnum = 1
date = 20070820

I know how to read the contents and write them to a file, but how would one
grab just the date or build number in order to create a directory named 
20070820_build1

Thanks,
Brian

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

RE: reading a line in file

2007-08-20 Thread Brian McCann
Hi,
 
I can read in the whole file build.number which has the following lines
how do I just capture the value of build.number and assign it to a variable
Thanks,
Brian

contents of file build.number:
#Build Number for ANT. Do not edit!
#Mon Aug 20 04:04:51 EDT 2007
build.number=1

buildinfo.py
##
#!/usr/bin/python
import string
import os
import sys
import time
import errno
import shutil
buildinfo = "build.number"
input = open(buildinfo, 'r')
for line in input:
print line
#
 
command line when script is run
$ buildinfo.py
#Build Number for ANT. Do not edit!
#Mon Aug 20 04:04:51 EDT 2007
build.number=1

 



From: [EMAIL PROTECTED] on behalf of Shawn Milochik
Sent: Mon 8/20/2007 1:29 PM
To: python-list@python.org
Subject: Re: reading a line in file



Write some code, even if it doesn't quite work, and post it. We'll
help you fix it.

You can open a file with:  input = open("file.txt", "r")

You can read a line with: someText = input.readline()

You can loop through an open file like this:

for line in input:
#do something with line


That should get you started.
--
http://mail.python.org/mailman/listinfo/python-list


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

RE: reading a line in file

2007-08-20 Thread Brian McCann
 
Hi Tim,
The sample data is in file build.number

contents of file build.number:
 
 #Build Number for ANT. Do not edit!
 #Mon Aug 20 04:04:51 EDT 2007
build.number=1
 
Thanks,
Brian
 



From: [EMAIL PROTECTED] on behalf of Tim Williams
Sent: Mon 8/20/2007 2:59 PM
To: Brian McCann
Cc: python-list@python.org
Subject: Re: reading a line in file



On 20/08/07, Brian McCann <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> I can read in the whole file build.number which has the following lines
> how do I just capture the value of build.number and assign it to a variable
> Thanks,
> Brian
>
> contents of file build.number:
> #Build Number for ANT. Do not edit!
> #Mon Aug 20 04:04:51 EDT 2007
> build.number=1
> buildinfo.py
> ##
> #!/usr/bin/python
> import string
> import os
> import sys
> import time
> import errno
> import shutil
> buildinfo = "build.number"
> input = open(buildinfo, 'r')
> for line in input:
> print line
> #
>
> command line when script is run
> $ buildinfo.py
> #Build Number for ANT. Do not edit!
>
> #Mon Aug 20 04:04:51 EDT 2007
> build.number=1
>
>

This is preferred nowadays

for line in open(buildinfo):
print line

Without a sample of the data, no-one can help you further.   If this
is homework, you should say so, people will give you guidance :)


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

RE: reading a line in file

2007-08-20 Thread Brian McCann
Shawn, Tim ,Jay
 
many thanks,
 
It looks like there are many ways this problem can be approached

either by using  regex or a tokens 

Tim I'm not familiar with your solution, but will learn about that method also
Jay, what do you mean by regex comes with a lot of overhead?

--Brian
 
 



From: [EMAIL PROTECTED] on behalf of Shawn Milochik
Sent: Mon 8/20/2007 3:07 PM
To: python-list@python.org
Subject: Re: reading a line in file



Hopefully this will help (using your input file)

#!/usr/bin/env python
import re
buildinfo = "input.txt"
input = open(buildinfo, 'r')

regex = re.compile(r"^\s*build.number=(\d+)\s*$")

for line in input:
if re.search(regex, line):
print line
buildNum = re.sub(r"^\s*build.number=(\d+)\s*$", "\\1", line)
print line
print buildNum
--
http://mail.python.org/mailman/listinfo/python-list


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

RE: reading a line in file

2007-08-20 Thread Brian McCann
Hi Shawn,

what if I had a file
com.properties with the below line in it

If I needed to capture the value of everything separeted by a ":"
and asign each to a variable would regex be the right method to grab those?

like 
a=jdbc
b=oracle
[EMAIL PROTECTED]
d=1521
e:XE
 
--Brian

com.db.connstr=jdbc:oracle:thin:@127.0.0.1:1521:XE
 
 
 



From: [EMAIL PROTECTED] on behalf of Shawn Milochik
Sent: Mon 8/20/2007 4:35 PM
To: python-list@python.org
Subject: Re: reading a line in file



Although you're technically correct, I think there's a knee-jerk
anti-regex reaction, citing the meaningless overhead. If you're
running many thousands of records or something then it becomes a small
issue compared to a replace statement or something. But in most cases
it makes no difference at all.

Run the example script both ways and I'm sure there will be no
difference, and I prefer a clear regex to a convoluted (in my opinion)
substring call.

In any case, it's a preference, and I have never seen anything which
convinced me that one should avoid regexes at all costs unless there's
no other way to do it.

And the comment about solving a problem by using regular expressions
creating another problem is just asinine.  Like so many other things,
it's often repeated without any thought about whether it is true in
general, much less in the situation in question.
--
http://mail.python.org/mailman/listinfo/python-list


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

creating a tar file with python

2007-08-23 Thread Brian McCann
Hi,
 
I'm trying to create a tar file of the contents of the current directory
 
right now there is only one file "text.xml" in the current dir,  I'm using"." 
current dir as source
but that gives syntax error

any help would be greatly appreciated
--Brian
 
 
#!/usr/bin/python
import string
import os
import sys
import time
import errno
import shutil
import tarfile
 

tar = tarfile.open(.,"test.tar.gz", "w:gz)

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

RE: creating a tar file with python

2007-08-23 Thread Brian McCann
Hi, 
 
I tried Steve's solution but get this error
using the tar script below
--Brian 

tar = tarfile.open(".","test.tar.gz",w:gz)
[EMAIL PROTECTED] tmp]$ ./tarup.py
  File "./tarup.py", line 24
tar = tarfile.open(".","test.tar.gz",w:gz)
  ^
SyntaxError: invalid syntax
##
 
#!/usr/bin/python
import string
import os
import sys
import time
import errno
import shutil
import tarfile

tar = tarfile.open(".","test.tar.gz",w:gz)

<mailto:[EMAIL PROTECTED]> 
 
 



From: [EMAIL PROTECTED] on behalf of Steve Holden
Sent: Thu 8/23/2007 5:24 PM
To: python-list@python.org
Subject: Re: creating a tar file with python



Brian McCann wrote:
> Hi,
> 
> I'm trying to create a tar file of the contents of the current directory
> 
> right now there is only one file "text.xml" in the current dir,  I'm
> using"." current dir as source
> but that gives syntax error
>
> any help would be greatly appreciated
> --Brian
> 
> 
> #!/usr/bin/python
> import string
> import os
> import sys
> import time
> import errno
> import shutil
> import tarfile
> 
>
> tar = tarfile.open(.,"test.tar.gz", "w:gz)
> <mailto:[EMAIL PROTECTED]>
> 
>
well, /probably/ (meaning I haven't done any testing) you need quotes
around the name of the current directory just like you do around the
name of the file. Try

   tar = tarfile(".", "test.tar.gz", "w:gz")

regards
  Steve
--
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden
--- Asciimercial --
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
--- Thank You for Reading -

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


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

RE: creating a tar file with python

2007-08-23 Thread Brian McCann
Hi,
 
I'm now getting this error
any ideas?
Thanks,
Brian


Traceback (most recent call last):
  File "./tarup.py", line 25, in ?
tar = tarfile.open("test.xml","sample.tar.gz", 'w:gz')
  File "/usr/lib64/python2.4/tarfile.py", line 929, in open
raise ValueError, "undiscernible mode"
ValueError: undiscernible mode

#!/usr/bin/python
import string
import os
import sys
import time
import errno
import shutil
import tarfile

tar = tarfile.open(test.xml","sample.tar.gz", 'w:gz')
 
<mailto:[EMAIL PROTECTED]> 
 



From: [EMAIL PROTECTED] on behalf of Steve Holden
Sent: Thu 8/23/2007 5:24 PM
To: python-list@python.org
Subject: Re: creating a tar file with python



Brian McCann wrote:
> Hi,
> 
> I'm trying to create a tar file of the contents of the current directory
> 
> right now there is only one file "text.xml" in the current dir,  I'm
> using"." current dir as source
> but that gives syntax error
>
> any help would be greatly appreciated
> --Brian
> 
> 
> #!/usr/bin/python
> import string
> import os
> import sys
> import time
> import errno
> import shutil
> import tarfile
> 
>
> tar = tarfile.open(.,"test.tar.gz", "w:gz)
> <mailto:[EMAIL PROTECTED]>
> 
>
well, /probably/ (meaning I haven't done any testing) you need quotes
around the name of the current directory just like you do around the
name of the file. Try

   tar = tarfile(".", "test.tar.gz", "w:gz")

regards
  Steve
--
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden
--- Asciimercial --
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
--- Thank You for Reading -

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


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

RE: creating a tar file with python

2007-08-23 Thread Brian McCann
 
<mailto:[EMAIL PROTECTED]> 
Steve,
 
I ran the code as you suggested, didn't work, tried variations of it didn't 
work,
If you don't know the answer don't pretend you do!

Apology not accepted, please don't wake up!

Future correspondence on any python questions from you go to trash.
May your pillow not have pity on your head!
 
--Brian
 



From: Steve Holden [mailto:[EMAIL PROTECTED]
Sent: Thu 8/23/2007 11:15 PM
To: Brian McCann
Cc: python-list@python.org
Subject: Re: creating a tar file with python



Brian McCann wrote:
>
> Hi,
> 
> I'm now getting this error
> any ideas?
> Thanks,
> Brian
>
>
> Traceback (most recent call last):
>   File "./tarup.py", line 25, in ?
> tar = tarfile.open("test.xml","sample.tar.gz", 'w:gz')
>   File "/usr/lib64/python2.4/tarfile.py", line 929, in open
> raise ValueError, "undiscernible mode"
> ValueError: undiscernible mode
> 
> #!/usr/bin/python
> import string
> import os
> import sys
> import time
> import errno
> import shutil
> import tarfile
>
> tar = tarfile.open(test.xml","sample.tar.gz", 'w:gz')
> 
Well, my first idea is that you took the time to think beyond the
mistake exhibited in your first response. But since a soft mattress is
currently looking about a hundred times more attractive than actually
trying to debug your code I am sorry to tell you I am going to punt on
this one and trust that some other c.l.py netizen will take pity on you
and probably help you with less crabby comments than me. Good luck!

regards
  Steve
--
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden
--- Asciimercial --
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
--- Thank You for Reading -


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

how to tar with python

2007-08-24 Thread Brian McCann
Hi,
 
I'm trying to tar the contents of a directory "test" which contains
3 files foo1.xml ,foo2.xml, foo3.xml
 
in my current directory /home/pythonbox/tmp I have the directory "test"
 
if I run the below script it fails with the below error, but the files exist in 
the directory test
any help would be greatly appreciated
--Brian
 
##
[tmp]$ ./tarup.py
Traceback (most recent call last):
  File "./tarup.py", line 29, in ?
tfile .add(f)
  File "/usr/lib64/python2.4/tarfile.py", line 1229, in add
tarinfo = self.gettarinfo(name, arcname)
  File "/usr/lib64/python2.4/tarfile.py", line 1101, in gettarinfo
statres = os.lstat(name)
OSError: [Errno 2] No such file or directory: 'viz2.xml'

###
import string
import os
import shutil
import tarfile


tfile = tarfile.open("files.tar.gz", 'w:gz')
files = os.listdir("test")
for f in files:
tfile .add(f)
tfile.close
 
 
-- 
http://mail.python.org/mailman/listinfo/python-list

RE: creating a tar file with python

2007-08-24 Thread Brian McCann
I don't care if Steve Holden is the python God himself,
He's a rude, arrogant, vulgar human who shows his true level
of intellect by his use of profanity


And he goes one level lower stating he respects the python group
he spews his profanity to

He chose to respond to my question, no one dragged him out of bed
as hi so quickly pointed out. Re-read the thread!



If your three chums are indicative to the type of people in this group
Python is in sorry state

 

 

 
 
 



From: [EMAIL PROTECTED] on behalf of Ed Leafe
Sent: Fri 8/24/2007 11:33 AM
To: Carsten Haese
Cc: python-list@python.org
Subject: Re: creating a tar file with python



On Aug 24, 2007, at 11:24 AM, Carsten Haese wrote:

> You clearly have no idea who you're talking to. I suggest you 
> Google for
> '"Steve Holden" Python' to get a clue. Good luck finding any more help
> here.

Even if it were Joe Nobody to whom he was directing those comments, 
it was *way* out of line. The fact that it was Steve only reinforces 
the cluelessness of the writer.

-- Ed Leafe
-- http://leafe.com
-- http://dabodev.com


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


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

RE: creating a tar file with python

2007-08-24 Thread Brian McCann
Ed, Carsten, Steve,
 
I don't care if  Steve Holden is the python God himself,
He's a rude, arrogant, vulgar human who shows his true level
of intellect by his use of profanity


And he goes one level lower, stating he respects the python group
he spews his profanity to.

He chose to respond to my question, no one dragged him out of bed,
as he so quickly pointed out. Re-read the thread!



If your three chums are indicative to the type of people in this group
Python is in sorry state

 

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

copying files

2007-08-29 Thread Brian McCann
Hi,
 
with the code below I set a variable TEST_HOME to a path and the variable m to 
a path
in my current dir. 
I have a symbolic link setting m>lib
when I run the script I get no errors and the lib dir with its 20 files does 
not get copied to /v01/test_home
any help would be greatly appreciated
 
--Brian

#!/usr/bin/python
import string
import os
import sys
import errno
import shutil
import tarfile
 
TEST_HOME = "/v01/test_home"
m = "./lib"
os.system("cp -r m TEST_HOME")
#os.system("tar -cvf viziant-ingestion.tar /v01/")

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

RE: copying files

2007-08-29 Thread Brian McCann
 
<mailto:[EMAIL PROTECTED]> 
one thing I just noticed is that when I run the script I get a new symbolic link
created in my current dir  TEST_HOME-->lib
--Brian
 



From: [EMAIL PROTECTED] on behalf of Brian McCann
Sent: Wed 8/29/2007 2:40 PM
To: python-list@python.org
Subject: copying files 


Hi,
 
with the code below I set a variable TEST_HOME to a path and the variable m to 
a path
in my current dir. 
I have a symbolic link setting m>lib
when I run the script I get no errors and the lib dir with its 20 files does 
not get copied to /v01/test_home
any help would be greatly appreciated
 
--Brian

#!/usr/bin/python
import string
import os
import sys
import errno
import shutil
import tarfile
 
TEST_HOME = "/v01/test_home"
m = "./lib"
os.system("cp -r m TEST_HOME")


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

RE: copying files

2007-08-29 Thread Brian McCann
 
 
<mailto:[EMAIL PROTECTED]> 
Hi Ricardo,

what do the + signs do?
 



From: Ricardo Aráoz [mailto:[EMAIL PROTECTED]
Sent: Wed 8/29/2007 2:51 PM
To: Brian McCann
Cc: python-list@python.org
Subject: Re: copying files



Brian McCann wrote:
> Hi,
> 
> with the code below I set a variable TEST_HOME to a path and the
> variable m to a path
> in my current dir.
> I have a symbolic link setting m>lib
> when I run the script I get no errors and the lib dir with its 20 files
> does not get copied to /v01/test_home
> any help would be greatly appreciated
> 
> --Brian
>
> #!/usr/bin/python
> import string
> import os
> import sys
> import errno
> import shutil
> import tarfile
> 
> TEST_HOME = "/v01/test_home"
> m = "./lib"
> os.system("cp -r m TEST_HOME")
> #os.system("tar -cvf viziant-ingestion.tar /v01/")
> 

Sorry, meant : os.system("cp -r " + m + " " + TEST_HOME)




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

passing command line arguments

2007-09-07 Thread Brian McCann
 
Hi,
 
when I run the script show_args2.py

# ./show_args2.py 1 2 3

I get the following error

Traceback (most recent call last):
  File "./show_args2.py", line 4, in ?
print 'The arguments of %s are "%s"' %s \
NameError: name 's' is not defined


#
 
this is the script
 #!/usr/bin/python
import sys, string
print 'The arguments of %s are "%s"' %s \
(sys.argv[0], string.join(sys.argv[1:]))

 

any help would be greatly appreciated

-Brian


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

RE: passing command line arguments

2007-09-07 Thread Brian McCann
 
Darren,
Thanks
 



From: [EMAIL PROTECTED] on behalf of darren kirby
Sent: Fri 9/7/2007 1:58 PM
To: python-list@python.org
Subject: Re: passing command line arguments



quoth the Brian McCann:
> Hi,
>
> when I run the script show_args2.py
>
> # ./show_args2.py 1 2 3
>
> I get the following error
>
> Traceback (most recent call last):
>   File "./show_args2.py", line 4, in ?
> print 'The arguments of %s are "%s"' %s \
> NameError: name 's' is not defined
>
>
> #
> <mailto:[EMAIL PROTECTED]>
> this is the script
>  #!/usr/bin/python
> import sys, string
> print 'The arguments of %s are "%s"' %s \
> (sys.argv[0], string.join(sys.argv[1:]))

You don't want the 's' on the last format operator. Try:

 print 'The arguments of %s are "%s"' % \
 (sys.argv[0], string.join(sys.argv[1:]))

> any help would be greatly appreciated
>
> -Brian

-d
--
darren kirby :: Part of the problem since 1976 :: http://badcomputer.org
"...the number of UNIX installations has grown to 10, with more expected..."
- Dennis Ritchie and Ken Thompson, June 1972
--
http://mail.python.org/mailman/listinfo/python-list


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

sys.argv index out of range error

2007-09-13 Thread Brian McCann
Hi, 
 
I trying to create a bootstrap.sh shell script that takes two command line args 
that passes them
to two scripts. one script is init.sh  that sets up some environment varilables
the other will be a Python script used as the main build script. the contents 
of the bootstrap file and init.sh are
I've simplified the scripts as much as I could and still retain the errors
 
bootstrap.sh
#!/bin/sh
cd /home/workspaces
export LANG="en_US.UTF-8"

source init $1
test.py $2
#
 
init.sh

#!/bin/sh
WORKSPACE_ROOT="$1";

export 
JAVA_OPTIONS="-Djava.library.path=$WORKSPACE_ROOT/:$WORKSPACE_ROOT/:$WORKSPACE_ROOT/"
echo "JAVA_OPTIONS="$JAVA_OPTIONS;
 
set 
PATH="$WORKSPACE_ROOT/vendor/basistech/rlp5.4/rlp/bin/ia32-glibc23-gcc32:$WORKSPACE_ROOT/vendor/basistech/rlp5.4/rlp/bin/ia32-w32-msvc71:$WORKSPACE_ROOT/lib/core:$PATH"


##
when I run the bootstrap.sh with two args

$ ./bootstrap.sh  spam   ham

init takes the spam with no problem 

this is the output on the command line

$ ./bootstrap.sh spam ham
JAVA_OPTIONS=-Djava.library.path=spam/:spam/:spam/
Traceback (most recent call last):
  File "./test.py", line 12, in ?
aaa = sys.argv[1]
IndexError: list index out of range
 
 
This is the test.py script that gets the second arg
##
!/usr/bin/python
import string
import os
import sys

filename  = sys.argv[0]
aaa = sys.argv[1]


print aaa
#
 
 
If I remove "source init $1" from init.sh and replace it with "init 1$" I get 
this output which works
$ bootstrap.sh spam ham
JAVA_OPTIONS=-Djava.library.path=spam/:spam/:spam/
ham

what's wrong with  the line "source init $1  ?
 
 
Thanks,
Brian
 
 
-- 
http://mail.python.org/mailman/listinfo/python-list