Advertisement
Guest User

Untitled

a guest
Jun 13th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.42 KB | None | 0 0
  1. Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41)
  2. [GCC 4.4.3] on linux2
  3. Type "help", "copyright", "credits" or "license" for more information.
  4. >>> import myserver
  5. >>> newqry = myserver.myserver()
  6. >>> newqry.sql("show tables", "mysql")
  7. Traceback (most recent call last):
  8.   File "<stdin>", line 1, in <module>
  9. AttributeError: 'myserver' object has no attribute 'sql'
  10. >>>
  11.  
  12. ==================================================================================================================================================================
  13. import MySQLdb
  14.  
  15. class myserver(object):
  16.    "this is the server class, should be used to control things at a server level"
  17.    
  18. def __init__(self, host='localhost', port=3306, socket='', sql_user='backupuser', sql_pass=''):
  19.    print "Server Initialised"
  20.  
  21.    def getconf(part):
  22.       from ConfigParser import ConfigParser
  23.       conf = "/etc/backup.cnf"
  24.       config = ConfigParser()
  25.       config.read(conf)
  26.       item = config.get('backup', part)
  27.       return item  
  28.  
  29.    def _connect(self, db=''):
  30.       if not self.__conn:
  31.          self.__conn = MySQLdb.connect(host=self.host, port=self.port, unix_socket=self.socket, db=db, user=self.sql_user, passwd=self.sql_pass)
  32.       elif db:
  33.          self.__conn.select_db(db)
  34.  
  35.    def sql(self, command, db=''):
  36.       self._connect(db)
  37.       c = self.__conn.cursor(MySQLdb.cursors.DictCursor)
  38.       c.execute(command)
  39.       print "this got to here"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement