Script to export MySQL tables to csv

2005-11-10 Thread Jandre
To anyone that can help

I have 2 MySQL databases that contain large amounts of tables. I need
to be able to compare the data in the tables with older/newer versions
of the tables. I figured the easiest way would be to get the info in
csv format and then run a comparison. I can get all the data using
MySQL front, but this has to be done tabe-by-table, and is too time
consuming.

I am new to Python and also new to programming.
Can anyone please help.

Thanks
Jandre

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


Re: Script to export MySQL tables to csv

2005-11-16 Thread Jandre
Thnaks to everybody for their input. I have found a quick fix for now.
MySQL dump allows me to export the data to XML which can easily be
compared. This will help me for now and the project will have to wait
until I have some more time. 

Regards
Jandre

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


Recursive zipping of Directories in Windows

2007-02-01 Thread Jandre
Hi

I am a python novice and I am trying to write a python script (most of
the code is borrowed) to Zip a directory containing some other
directories and files. The script zips all the files fine but when it
tries to zip one of the directories it fails with the following
error:
"IOError: [Errno 13] Permission denied: 'c:\\aaa\\temp'"

The script I am using is:

import zipfile, os

def toZip( directory, zipFile ):
"""Sample for storing directory to a ZipFile"""
z = zipfile.ZipFile(
zipFile, 'w', compression=zipfile.ZIP_DEFLATED
)
def walker( zip, directory, files, root=directory ):
for file in files:
file = os.path.join( directory, file )
# yes, the +1 is hacky...
archiveName = file[len(os.path.commonprefix( (root,
file) ))+1:]
zip.write( file, archiveName, zipfile.ZIP_DEFLATED )
print file
os.path.walk( directory, walker, z  )
z.close()
return zipFile


if __name__ == "__main__":
toZip( 'c:\\aaa', 'c:\\aaa\\test.zip' )

I have tried to set the permissions on the folder, but when I check
the directory permissions it is set back to "Read Only"

Any suggestions?

Thanks
Johan Balt

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


Re: Recursive zipping of Directories in Windows

2007-02-04 Thread Jandre
On Feb 1, 9:39 pm, Larry Bates <[EMAIL PROTECTED]> wrote:
> Jandre wrote:
> > Hi
>
> > I am a python novice and I am trying to write a python script (most of
> > the code is borrowed) to Zip a directory containing some other
> > directories and files. The script zips all the files fine but when it
> > tries to zip one of the directories it fails with the following
> > error:
> > "IOError: [Errno 13] Permission denied: 'c:\\aaa\\temp'"
>
> > The script I am using is:
>
> > import zipfile, os
>
> > def toZip( directory, zipFile ):
> > """Sample for storing directory to a ZipFile"""
> > z = zipfile.ZipFile(
> > zipFile, 'w', compression=zipfile.ZIP_DEFLATED
> > )
> > def walker( zip, directory, files, root=directory ):
> > for file in files:
> > file = os.path.join( directory, file )
> > # yes, the +1 is hacky...
> > archiveName = file[len(os.path.commonprefix( (root,
> > file) ))+1:]
> > zip.write( file, archiveName, zipfile.ZIP_DEFLATED )
> > print file
> > os.path.walk( directory, walker, z  )
> > z.close()
> > return zipFile
>
> > if __name__ == "__main__":
> > toZip( 'c:\\aaa', 'c:\\aaa\\test.zip' )
>
> > I have tried to set the permissions on the folder, but when I check
> > the directory permissions it is set back to "Read Only"
>
> > Any suggestions?
>
> > Thanks
> > Johan Balt
>
> Couple of quick suggestions that may help:
>
> 1) don't use 'file' as a variable name. It will mask
> the builtin file function.  If it hasn't bitten you before
> it will if you keep doing that.
>
> 2) If you put the target .zip file in the directory you are
> backing what do you expect the program to do when it comes
> to the file you are creating as you walk the directory?  You
> haven't done anything to 'skip' it.
>
> 3) Your commonprefix and +1 appears to result in same
> information that the easier to use os.path.basename()
> would give you.  Double check me on that.
>
> I don't see anything that references C:\\aaa\temp in your
> code.  Does it exist on your hard drive?  If so does it
> maybe contain temp files that are open?  zipfile module
> can't handle open files.  You must use try/except to
> catch these errors.
>
> Hope info helps.
>
> -Larry

Thank you Larry.
I've changed the code as epr your advice. The code is now:

import zipfile, os

def toZip( directory, zipFile ):
"""Sample for storing directory to a ZipFile"""
z = zipfile.ZipFile(
zipFile, 'w', compression=zipfile.ZIP_DEFLATED
)
def walker( zip, directory, files, root=directory ):
for f in files:
f = os.path.join( directory, f )
archiveName = os.path.basename(f)
zip.write( f, archiveName, zipfile.ZIP_DEFLATED )
print f
os.path.walk( directory, walker, z  )
z.close()
return zipFile


if __name__ == "__main__":
toZip( 'c:\\aaa\\', 'c:\\bbb\\test.zip' )

I still get the same error:
Traceback (most recent call last):
  File "C:\Python24\Lib\site-packages\pythonwin\pywin\framework
\scriptutils.py", line 310, in RunScript
exec codeObject in __main__.__dict__
  File "C:\Python24\Scripts\dirZip.py", line 20, in ?
toZip( 'c:\\aaa\\', 'c:\\bbb\\test.zip' )
  File "C:\Python24\Scripts\dirZip.py", line 14, in toZip
os.path.walk( directory, walker, z  )
  File "C:\Python24\lib\ntpath.py", line 329, in walk
func(arg, top, names)
  File "C:\Python24\Scripts\dirZip.py", line 12, in walker
zip.write( f, archiveName, zipfile.ZIP_DEFLATED )
  File "C:\Python24\lib\zipfile.py", line 405, in write
fp = open(filename, "rb")
IOError: [Errno 13] Permission denied: 'c:\\aaa\\temp'

c:\\aaa\\temp is a directory in the directory I an trying to zip. I
want to use this script to back up my work once a day and would like
to
keep the directory structure as is. I can zip the files in c:\aaa\tem
fine so I guess that there aren't any open files in the directory.
Any more ideas?

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