Showing posts with label close. Show all posts
Showing posts with label close. Show all posts

Tuesday, October 27, 2009

Python - break a large mysql dump into small dumps

# created a dumpfile from my mysql db
# and found that it was too large to
# upload to my new db host.
 
# this python script breaks up the database
# into smaller pieces that you can more
# easily import through phpmyadmin
# (if I'd only had shell access I wouldn't
# have this problem at all!)
 
# indicates a new table is about to be
# created
dlmtr = "-- Table structure for table"
 
wholeFile = open("myDBDump.sql")
fileN = 0
oFile = open(str(fileN) + ".sql", 'w')
reducing = True
 
for line in wholeFile:
    if line.find(dlmtr) > -1:
        # this is the seam for the next file
        print "starting new file"
        oFile.close()
        fileN += 1
        oFile = open(str(fileN) + ".sql", 'w')
    oFile.write(line)
 
oFile.close()
print "Done"
 
 

Sunday, September 20, 2009

Python - create and add files to a zip archive

# you may also be interested in reading 
# zip files ... check out my reading zip files post 


import zipfile 

t = "testie.zip"


# create a new zip file
# use the 'w' to write a new file
zippy = zipfile.ZipFile(t, "w")

# add contents to zip file
# I used a couple files I had sitting around
# you'll need to change these to files in your
# current directory
print 'Adding contents to zip file...'
zippy.write('echoClient.py')
zippy.write('echoServer.py')

zippy.close()
print 'zip file creatd.'
# the zip file is ready to use