Log rolling question

2005-10-25 Thread elake
I have an application that creates a lot of large log files. I only
want to keep logs for the previous 4 months. I am looking for a way to
list the contents of the log dir and if the create date on the log is
older than 4 months delete it. I have looked at the os.stat() function
to get the created date but I can't figure out how to get the date to
go back to a previos time.

Any help would be appreciated.

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


Re: Log rolling question

2005-10-25 Thread elake
Is there a way to do this for a whole calendar month?

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


Determining if a file is locked in Windows

2006-10-18 Thread elake
I found this thread about a pst file in Windows being locked and I am
having the same issue.

http://groups.google.com/group/comp.lang.python/browse_thread/thread/d3dee5550b6d3652/ed00977acf62484f?lnk=gst&q=%27copying+locked+files%27&rnum=1

The problem is that I have a script that can find the pst files on
every machine in my network and back them up to a server for safe
keeping. The problem is that when Outlook is running it locks the file
and will not allow me to copy it to the destination. I am using the
shutil module for the copy.

Is there a way to first determine if the file is locked and then do the
copy if it isn't? I thought about looking to see if Outlook.exe is
running but the machines are shared and the process could be running
but with a different pst file in use.

Thanks in advance

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


Re: Flushing standard input

2006-10-18 Thread elake
I found this.
http://mail.python.org/pipermail/python-list/2006-September/359296.html

You cannot flush input.  The flush method only relates to output.  The
*other* side of the file has to flush *its* output in order for you to
see it as input.

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


Re: Determining if a file is locked in Windows

2006-10-19 Thread elake
Larry Bates wrote:
> elake wrote:
> > I found this thread about a pst file in Windows being locked and I am
> > having the same issue.
> >

> > http://groups.google.com/group/comp.lang.python/browse_thread/thread/d3dee5550b6d3652/ed00977acf62484f?lnk=gst&q=%27copying+locked+files%27&rnum=1
> >
> > The problem is that I have a script that can find the pst files on
> > every machine in my network and back them up to a server for safe
> > keeping. The problem is that when Outlook is running it locks the file
> > and will not allow me to copy it to the destination. I am using the
> > shutil module for the copy.
> >
> > Is there a way to first determine if the file is locked and then do the
> > copy if it isn't? I thought about looking to see if Outlook.exe is
> > running but the machines are shared and the process could be running
> > but with a different pst file in use.
> >
> > Thanks in advance
> >
> Try the copy and catch the exception instead.
>
> -Larry Bates

Larry thanks for your suggestion. this is what I tried:

#!/usr/bin/env python

import os, shutil

path = 'c:\documents and settings\username\Local Settings\Application
Data\Microsoft\Outlook'

src = 'Outlook.pst'
dst = 'test.pst'

os.chdir(path)

try:
shutil.copy2(src, dst)
except IOError:
print 'Must be locked by Outlook'

print 'Finished'

The problem is that even though I catch the IOError it overwrites the
dst file and makes it 0kb. This is going to be for backing these files
up and it wont be good to overwrite the backup with a bad copy.

Is there another way to do this that I am missing. I am still kind of
new to Python. If i could tell that outlook had the file locked before
I tried the copy then I think that it would be prevented.

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


Re: Determining if a file is locked in Windows

2006-10-19 Thread elake

MatthewWarren wrote:
> elake wrote:
> > Larry Bates wrote:
> > > elake wrote:
> > > > I found this thread about a pst file in Windows being locked and I am
> > > > having the same issue.
> > > >
> >
> > > > http://groups.google.com/group/comp.lang.python/browse_thread/thread/d3dee5550b6d3652/ed00977acf62484f?lnk=gst&q=%27copying+locked+files%27&rnum=1
> > > >
> > > > The problem is that I have a script that can find the pst files on
> > > > every machine in my network and back them up to a server for safe
> > > > keeping. The problem is that when Outlook is running it locks the file
> > > > and will not allow me to copy it to the destination. I am using the
> > > > shutil module for the copy.
> > > >
> > > > Is there a way to first determine if the file is locked and then do the
> > > > copy if it isn't? I thought about looking to see if Outlook.exe is
> > > > running but the machines are shared and the process could be running
> > > > but with a different pst file in use.
> > > >
> > > > Thanks in advance
> > > >
> > > Try the copy and catch the exception instead.
> > >
> > > -Larry Bates
> >
> > Larry thanks for your suggestion. this is what I tried:
> >
> > #!/usr/bin/env python
> >
> > import os, shutil
> >
> > path = 'c:\documents and settings\username\Local Settings\Application
> > Data\Microsoft\Outlook'
> >
> > src = 'Outlook.pst'
> > dst = 'test.pst'
> >
> > os.chdir(path)
> >
> > try:
> > shutil.copy2(src, dst)
> > except IOError:
> > print 'Must be locked by Outlook'
> >
> > print 'Finished'
> >
> > The problem is that even though I catch the IOError it overwrites the
> > dst file and makes it 0kb. This is going to be for backing these files
> > up and it wont be good to overwrite the backup with a bad copy.
> >
> > Is there another way to do this that I am missing. I am still kind of
> > new to Python. If i could tell that outlook had the file locked before
> > I tried the copy then I think that it would be prevented.
>
> maybe try and open the file for reading first, then if it opens ok,
> just close it and do the copy?

I tried to do that and it did let me open it without an error. Here is
what I have done now and it seems work.

def copyFile(src, dst):
if os.path.isfile(dst):
shutil.copy2(dst, dst_bak)
try:
shutil.copy2(src, dst)
except IOError:
if os.path.isfile(dst_bak):
shutil.copy2(dst_bak, dst)
os.remove(dst_bak)
else:
try:
shutil.copy2(src, dst)
except IOError:
if os.path.isfile(dst_bak):
shutil.copy2(dst_bak, dst)

It check to see if the dst file is there first and them makes a backup
of it first. That way if the copy goes bad then there is still a backup
of it. Do you see anywhere that I could have done  this
better/differently?

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


Calling a definition

2006-10-19 Thread elake
I have a piece of code that I need some help with. It is supposed (in
my mind at least) take two arguments, a start path and a file
extension. Then when called it should return each of the file paths
that are found matching the criteria. It is only returning the first
file that it finds. What am I doing wrong?

# this is in a file called findFile.py
def findFileExt(startPath, fileExt):
for root, dirs, files in os.walk(startPath):
for file in files:
if file.endswith(fileExt):
filePath = str(os.path.join(root, file))
return filePath

# this part is in a different file calling the findFile module
ip_list = findFile.getIpRange(net, start, end)

for ip in ip_list:
src_path = '%s\\%s\\' % (ip, start_dir)
files = findFile.findFileExt(src_path, ext)
print files

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


Re: Calling a definition

2006-10-19 Thread elake
Thanks for all of the help guys. I am still new to Python so this is
part of the learning curve I guess. I will look at the glob module and
see if that will do what I need to better.

On Oct 19, 3:34 pm, Gabriel Genellina <[EMAIL PROTECTED]> wrote:
> At Thursday 19/10/2006 15:43, elake wrote:
>
> >I have a piece of code that I need some help with. It is supposed (in
> >my mind at least) take two arguments, a start path and a file
> >extension. Then when called it should return each of the file paths
> >that are found matching the criteria. It is only returning the first
> >file that it finds. What am I doing wrong?Someone else has shown how to make 
> >your code work. But notice that
> you don't even need the findFileExt function: see the glob module.
>
> --
> Gabriel Genellina
> Softlab SRL
>
> __
> Preguntá. Respondé. Descubrí.
> Todo lo que querías saber, y lo que ni imaginabas,
> está en Yahoo! Respuestas (Beta).
> ¡Probalo ya!http://www.yahoo.com.ar/respuestas

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