From 1bda51a91a84969e0d84a8bf44d180a4b3e168bf Mon Sep 17 00:00:00 2001 From: Fred Gleason Date: Thu, 8 Jun 2017 17:50:29 -0400 Subject: [PATCH] 2017-06-08 Fred Gleason * Added 'scripts/engine_conv.py'. --- ChangeLog | 2 ++ rivendell.spec.in | 1 + scripts/engine_conv.py | 68 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+) create mode 100755 scripts/engine_conv.py diff --git a/ChangeLog b/ChangeLog index 635a8fb2..b8c23e91 100644 --- a/ChangeLog +++ b/ChangeLog @@ -15824,3 +15824,5 @@ argument of 'localhost' be sent to the localhost. 2017-06-05 Fred Gleason * Added a 'Air Gate' ['AG'] RML. +2017-06-08 Fred Gleason + * Added 'scripts/engine_conv.py'. diff --git a/rivendell.spec.in b/rivendell.spec.in index 88a24452..20898e34 100644 --- a/rivendell.spec.in +++ b/rivendell.spec.in @@ -428,6 +428,7 @@ rm -rf $RPM_BUILD_ROOT %doc docs/WINGS_FILTER.txt %doc docs/RIVENDELL_FILTER.txt %doc docs/NEXGEN_FILTER.txt +%doc scripts/engine_conv.py %files devel diff --git a/scripts/engine_conv.py b/scripts/engine_conv.py new file mode 100755 index 00000000..01191b26 --- /dev/null +++ b/scripts/engine_conv.py @@ -0,0 +1,68 @@ +#!/usr/bin/python + +# engine_conv.py +# +# Convert a Rivendell database to use a different MySQL table engine +# +# (C) Copyright 2017 Fred Gleason +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public +# License along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# + +# Usage: engine_conv.py + +from __future__ import print_function + +import ConfigParser +import mysql.connector +import sys + +def eprint(*args,**kwargs): + print(*args,file=sys.stderr,**kwargs) + + +def GetDbCredentials(): + config=ConfigParser.ConfigParser() + config.readfp(open('/etc/rd.conf')) + return (config.get('mySQL','Loginname'),config.get('mySQL','Password'), + config.get('mySQL','Hostname'),config.get('mySQL','Database')) + + +def OpenDb(): + creds=GetDbCredentials() + return mysql.connector.connect(user=creds[0],password=creds[1], + host=creds[2],database=creds[3],buffered=True) + +if(len(sys.argv)<2): + eprint("engine_conv.py: missing argument") + exit(256) + +engine=sys.argv[1] + +db=OpenDb() +creds=GetDbCredentials() + +sql='select TABLE_NAME,ENGINE from information_schema.TABLES where TABLE_SCHEMA="'+creds[3]+'" && ENGINE!="'+engine+'"' +q=db.cursor() +q.execute(sql) +for row in q.fetchall(): + print('Converting table "'+row[0]+'" to '+engine) + sql='alter table `'+row[0]+'` engine='+engine + q1=db.cursor() + q1.execute(sql) + db.commit() + q1.close() +q.close() + +db.close()