Skip to content

Commit

Permalink
added example in readme
Browse files Browse the repository at this point in the history
  • Loading branch information
bmaeser committed Apr 29, 2013
1 parent 0a779a8 commit c1ab760
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
25 changes: 22 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ EARLY ALPHA AT THE MOMENT

API MIGHT CHANGE UNTIL V 1.0

------------
Installation
------------

Expand All @@ -25,16 +26,34 @@ or checkout from github: ::
$ cd pyque
$ python setup.py install

-------
Example
-------

Create a gziped MySQL dump of every database on localhost for user 'backupuser':

from pyque.db.mysql import db_list, db_dump
from pyque.utils import gzip

username = 'backupuser'
password = 'test'

for db in db_list(username = username, password=password):
dumpfilename = '/tmp/' + db + '.sql'
db_dump(dumpfilename, dbname=db, username=username, password=password)
gzip(dumpfilename)

----------
Contribute
------------------
----------

contributions welcome

pull-request please and/or create a issue on github


-------
LICENCE
------------
-------

The MIT License (MIT)
Copyright © 2013 Bernhard Mäser, http://bmaeser.io
Expand Down
16 changes: 16 additions & 0 deletions mysql_dump_all.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# -*- coding: utf-8 -*-

'''
Creates a gziped dump of every MySQL database on localhost
'''

from pyque.db.mysql import db_list, db_dump
from pyque.utils import gzip

username = 'backupuser'
password = 'test'

for db in db_list(username = username, password=password):
dumpfilename = '/tmp/' + db + '.sql'
db_dump(dumpfilename, dbname=db, username=username, password=password)
gzip(dumpfilename)
3 changes: 2 additions & 1 deletion pyque/db/mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def db_dump(filename, dbname, username=None, password=None, host=None,
return infodict

def _cursor(username=None, password=None, host=None, port=None):
"returns a connected cursor to the database-server."

c_opts = {}

Expand All @@ -71,7 +72,7 @@ def _cursor(username=None, password=None, host=None, port=None):

def db_list(username=None, password=None, host=None, port=None):
"returns a list of all databases on this server"

cur = _cursor(username=username, password=password, host=host, port=port)
cur.execute('SHOW DATABASES')
rows = cur.fetchall()
Expand Down

0 comments on commit c1ab760

Please sign in to comment.