Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41)
- [GCC 4.4.3] on linux2
- Type "help", "copyright", "credits" or "license" for more information.
- >>> import myserver
- >>> newqry = myserver.myserver()
- >>> newqry.sql("show tables", "mysql")
- Traceback (most recent call last):
- File "<stdin>", line 1, in <module>
- AttributeError: 'myserver' object has no attribute 'sql'
- >>>
- ==================================================================================================================================================================
- import MySQLdb
- class myserver(object):
- "this is the server class, should be used to control things at a server level"
- def __init__(self, host='localhost', port=3306, socket='', sql_user='backupuser', sql_pass=''):
- print "Server Initialised"
- def getconf(part):
- from ConfigParser import ConfigParser
- conf = "/etc/backup.cnf"
- config = ConfigParser()
- config.read(conf)
- item = config.get('backup', part)
- return item
- def _connect(self, db=''):
- if not self.__conn:
- self.__conn = MySQLdb.connect(host=self.host, port=self.port, unix_socket=self.socket, db=db, user=self.sql_user, passwd=self.sql_pass)
- elif db:
- self.__conn.select_db(db)
- def sql(self, command, db=''):
- self._connect(db)
- c = self.__conn.cursor(MySQLdb.cursors.DictCursor)
- c.execute(command)
- print "this got to here"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement