forked from lalinsky/mbslave
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mbslave-psql.py
executable file
·30 lines (25 loc) · 1.04 KB
/
mbslave-psql.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env python
import os
from optparse import OptionParser
from mbslave import Config
parser = OptionParser()
parser.add_option("-S", "--no-schema", action="store_true", dest="public", default=False, help="don't configure the default schema")
parser.add_option("-s", "--schema", dest="schema", default='musicbrainz', help="default schema")
options, args = parser.parse_args()
config = Config(os.path.dirname(__file__) + '/mbslave.conf')
args = ['psql']
args.append('-U')
args.append(config.get('DATABASE', 'user'))
if config.has_option('DATABASE', 'host'):
args.append('-h')
args.append(config.get('DATABASE', 'host'))
if config.has_option('DATABASE', 'port'):
args.append('-p')
args.append(config.get('DATABASE', 'port'))
args.append(config.get('DATABASE', 'name'))
if not options.public:
schema = config.schema.name(options.schema)
os.environ['PGOPTIONS'] = '-c search_path=%s,public' % schema
if config.has_option('DATABASE', 'password'):
os.environ['PGPASSWORD'] = config.get('DATABASE', 'password')
os.execvp("psql", args)