download shared user subscriptions as opml
[mygpo.git] / bin / run-database-procedure
blob52b07debb45d8994239325819a9a8f402e56c45d
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
4 # This file is part of my.gpodder.org.
6 # my.gpodder.org is free software: you can redistribute it and/or modify it
7 # under the terms of the GNU Affero General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or (at your
9 # option) any later version.
11 # my.gpodder.org is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
14 # License for more details.
16 # You should have received a copy of the GNU Affero General Public License
17 # along with my.gpodder.org. If not, see <http://www.gnu.org/licenses/>.
20 import os
21 import sys
22 import MySQLdb
24 # Make sure the local "mygpo" package is in our PATH
25 sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
27 from mygpo.settings import *
29 # All allowed procedure names should be listed here
30 VALID_PROCEDURES = ('update_suggestion', )
32 if len(sys.argv) != 2 or sys.argv[-1] not in VALID_PROCEDURES:
33 print >>sys.stderr, """
34 Usage: python %s [%s]
35 """ % (sys.argv[0], '|'.join(VALID_PROCEDURES))
36 else:
37 procedure_name = sys.argv[-1]
38 try:
39 connection = MySQLdb.connect(host=DATABASE_HOST, user=DATABASE_USER, \
40 passwd=DATABASE_PASSWORD, db=DATABASE_NAME)
42 cur = connection.cursor()
43 cur.callproc(procedure_name, ())
44 cur.close()
46 connection.close()
47 except MySQLdb.Error, e:
48 print >>sys.stderr, 'MySQL Error %d: %s' % (e.args[0], e.args[1])
49 sys.exit(1)