Permalink
Browse files

Add hosts option to resetdb.py script to allow for remote access to w…

…eb client.
  • Loading branch information...
1 parent fde9e21 commit a8c5b296272e5e53bc0755add1d70c226dbda999 @bendiy bendiy committed Aug 3, 2012
Showing with 6 additions and 5 deletions.
  1. +6 −5 resetdb.py
View
@@ -13,6 +13,7 @@
epilog="All output from commands are saved to a file called 'output.txt' in the current directory"
)
parser.add_argument('--database', '-d', type=str, help="the name of the database", dest='d', default='380postbooks')
+parser.add_argument('--host', '-H', type=str, help="the hostname of the database server", dest='H', default='localhost')
parser.add_argument('--backup', '-b', type=str, help="the path to the database backup to restore", dest='b', default='./postbooks_demo.backup')
parser.add_argument('--user', '-u', type=str, help="specify if owner user is different than admin", dest='u', default='admin')
@@ -22,14 +23,14 @@
out = open('output.txt', 'w')
try:
- print "Dropping database", args.d, "if it exists"
- subprocess.call(['dropdb', args.d], stdout=out, stderr=out)
+ print "Dropping database", args.H, args.d, "if it exists"
+ subprocess.call(['dropdb', '-h', args.H, args.d], stdout=out, stderr=out)
print "Creating database", args.d
- subprocess.call(['createdb', '-U', args.u, '-T', 'template1', args.d], stdout=out, stderr=out)
+ subprocess.call(['createdb', '-U', args.u, '-h', args.H, '-T', 'template1', args.d], stdout=out, stderr=out)
print "Restoring from backup file", args.b
- subprocess.call(['pg_restore', '-U', args.u, '-d', args.d, args.b], stdout=out, stderr=out)
+ subprocess.call(['pg_restore', '-U', args.u, '-h', args.H, '-d', args.d, args.b], stdout=out, stderr=out)
print "Running init script 'postgresql/init_script.sql'"
- subprocess.call(['psql', '-U', args.u, '-d', args.d, '-f', 'init_script.sql'], cwd='postgresql', stdout=out, stderr=out)
+ subprocess.call(['psql', '-U', args.u, '-h', args.H, '-d', args.d, '-f', 'init_script.sql'], cwd='postgresql', stdout=out, stderr=out)
finally:
out.close()

0 comments on commit a8c5b29

Please sign in to comment.