Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Allow database connection details to be specified

  • Loading branch information...
commit dcec3cb02937698ea29ccf6c40c40da43e4316ea 1 parent 943eb9c
@robinhouston robinhouston authored
Showing with 23 additions and 2 deletions.
  1. +23 −2 bin/delete-data.py
View
25 bin/delete-data.py
@@ -1,11 +1,32 @@
#!/usr/bin/python
+import optparse
import sys
import psycopg2
-dataset_name = sys.argv[1]
+parser = optparse.OptionParser(usage="%prog [options] dataset")
+parser.add_option("", "--db-host",
+ action="store",
+ default="localhost",
+ help="database hostname (default %default)")
+parser.add_option("", "--db-name",
+ action="store",
+ help="database name")
+parser.add_option("", "--db-user",
+ action="store",
+ help="database username")
-db = psycopg2.connect("host=localhost")
+(options, args) = parser.parse_args()
+if len(args) != 1:
+ parser.error("Wrong number of arguments")
+dataset_name, = args
+
+db_connection_string = "host=" + options.db_host
+if options.db_name:
+ db_connection_string += " dbname=" + options.db_name
+if options.db_user:
+ db_connection_string += " user=" + options.db_user
+db = psycopg2.connect(db_connection_string)
c = db.cursor()
c.execute("""
Please sign in to comment.
Something went wrong with that request. Please try again.