[rhmessaging-commits] rhmessaging commits: r1697 - mgmt/cumin/bin.
rhmessaging-commits at lists.jboss.org
rhmessaging-commits at lists.jboss.org
Thu Feb 14 15:12:48 EST 2008
Author: justi9
Date: 2008-02-14 15:12:48 -0500 (Thu, 14 Feb 2008)
New Revision: 1697
Added:
mgmt/cumin/bin/cumin-database
Log:
Adds a command line tool for manipulating the deployed database.
Added: mgmt/cumin/bin/cumin-database
===================================================================
--- mgmt/cumin/bin/cumin-database (rev 0)
+++ mgmt/cumin/bin/cumin-database 2008-02-14 20:12:48 UTC (rev 1697)
@@ -0,0 +1,90 @@
+#!/usr/bin/env python
+
+import sys, os
+from sqlobject import connectionForURI
+from traceback import print_exc
+from mint import MintDatabase
+
+from cumin.util import *
+
+def usage():
+ print """Usage: cumin-database [OPTIONS...] COMMAND
+Options:
+ -h, --help Print this message
+ --data URL Connect to database at URL
+ (default postgesql://cumin@localhost/cumin)
+ --force Don't complain and just do it
+Commands:
+ create-schema Create the database schema; requires --force
+ drop-schema Drop the database schema; requires --force
+"""
+ sys.exit(1)
+
+def parse_command():
+ parg = ""
+
+ for arg in sys.argv[1:]:
+ if not arg.startswith("--") and not parg.startswith("--"):
+ return arg
+
+ parg = arg
+
+def main():
+ if "-h" in sys.argv or "--help" in sys.argv:
+ usage()
+
+ home = os.environ.get("CUMIN_HOME")
+
+ if not home:
+ home = os.path.normpath("/usr/share/cumin")
+
+ config = Config()
+ config.add_param("data", "s", "postgresql://cumin@localhost/cumin")
+ config.add_param("force", "b", False)
+
+ config.load_file(os.path.join(home, "etc", "cumin.conf"))
+ config.load_file(os.path.join(os.path.expanduser("~"), ".cumin.conf"))
+ config.load_args(sys.argv)
+
+ config.prt()
+
+ home = os.environ["CUMIN_HOME"]
+ data = config.get("data")
+ force = config.get("force")
+
+ command = parse_command()
+
+ if command is None:
+ print "Error: no command found"
+ usage()
+
+ database = MintDatabase(data)
+ database.checkConnection()
+
+ if command == "create-schema":
+ if force:
+ main = os.path.join(home, "sql", "schema.sql")
+ indexes = os.path.join(home, "sql", "indexes.sql")
+
+ database.createSchema((main, indexes))
+ else:
+ print "Command create-schema requires --force"
+ sys.exit(1)
+ elif command == "drop-schema":
+ if force:
+ database.dropSchema()
+ else:
+ print "Command create-schema requires --force"
+ sys.exit(1)
+ else:
+ print "Error: command '%s' not recognized" % command
+ usage()
+
+if __name__ == "__main__":
+ try:
+ main()
+ except SystemExit, e:
+ raise e
+ except:
+ print_exc()
+ sys.exit(1)
Property changes on: mgmt/cumin/bin/cumin-database
___________________________________________________________________
Name: svn:executable
+ *
More information about the rhmessaging-commits
mailing list