From: W. Trevor King Date: Sat, 26 Jun 2010 20:38:20 +0000 (-0400) Subject: Added logging commands to export_mysql X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=f3dc0e71e6513a7ca2ee0fddc26b0851a10ef085;p=sitecorepy.git Added logging commands to export_mysql --- diff --git a/sitecore/prof/export_mysql.py b/sitecore/prof/export_mysql.py index 21a229c..1514c9e 100644 --- a/sitecore/prof/export_mysql.py +++ b/sitecore/prof/export_mysql.py @@ -45,6 +45,8 @@ class SimpleDB (object): username = getpass.getpass('username: ') if password == None: password = getpass.getpass('password: ') + self.logger.info('logging in to %s:%s as %s' + % (host, database, username)) self.db = MySQLdb.connect(host=host, user=username, passwd=password, db=database) del(username) @@ -52,9 +54,14 @@ class SimpleDB (object): self.cursor = self.db.cursor() def disconnect(self): + self.logger.info('disconnecting') self.cursor = None self.db.close() + def execute(self, command): + self.logger.info(command) + self.cursor.execute(command) + def set_default_table(self, table): self.table = table @@ -64,15 +71,15 @@ class SimpleDB (object): dict = self._clean_dict(dict) keys = dict.keys() values = ["'%s'" % dict[key] for key in keys] - self.cursor.execute("INSERT INTO %s (%s) VALUES (%s)" - % (table, ', '.join(keys), ', '.join(values))) + self.execute("INSERT INTO %s (%s) VALUES (%s)" + % (table, ', '.join(keys), ', '.join(values))) # error checking def list_entries(self, dict=None, table=None): if table == None: table = self.table where = self._where_string(dict) - self.cursor.execute('SELECT * FROM %s%s' % (table, where)) + self.execute('SELECT * FROM %s%s' % (table, where)) numrows = int(self.cursor.rowcount) print '\t'.join([dtuple[0] for dtuple in self.cursor.description]) for x in range(0,numrows): @@ -83,7 +90,7 @@ class SimpleDB (object): if table == None: table = self.table where = self._where_string(dict) - self.cursor.execute('DELETE FROM %s%s' % (table, where)) + self.execute('DELETE FROM %s%s' % (table, where)) def _clean_dict(self, dict=None): if dict == None: