Author: justi9
Date: 2008-03-24 14:15:01 -0400 (Mon, 24 Mar 2008)
New Revision: 1788
Modified:
mgmt/cumin/bin/cumin-admin
Log:
Fix cumin-admin after the config changes.
Modified: mgmt/cumin/bin/cumin-admin
===================================================================
--- mgmt/cumin/bin/cumin-admin 2008-03-24 17:40:53 UTC (rev 1787)
+++ mgmt/cumin/bin/cumin-admin 2008-03-24 18:15:01 UTC (rev 1788)
@@ -9,24 +9,19 @@
from mint import MintDatabase, ConsoleUser
from psycopg2 import IntegrityError
+from cumin import CuminConfig
from cumin.util import *
-def usage():
- print """Usage: cumin-admin [OPTIONS...] COMMAND
-Options:
- -h, --help Print this message
- --data URL Connect to database at URL
- (default postgesql://cumin@localhost/cumin)
- --force yes Don't complain and just do it
-Commands:
+def print_usage(config):
+ config.print_usage("cumin-admin")
+
+ print """Commands:
create-schema Create the database schema
- drop-schema Drop the database schema; requires "--force yes"
+ drop-schema Drop the database schema; requires --force yes
add-user NAME Add user called NAME
- remove-user NAME Remove user called NAME; requires "--force yes"
- list-users List existing users
-"""
- sys.exit(1)
+ remove-user NAME Remove user called NAME; requires --force yes
+ list-users List existing users"""
def parse_command_args():
args = list()
@@ -41,55 +36,51 @@
return args
def main():
- if "-h" in sys.argv or "--help" in sys.argv:
- usage()
+ config = CuminConfig()
+ config.add_param("force", bool, False, "Don't complain and just do
it")
- home = os.environ.get("CUMIN_HOME")
+ # XXX I think we need to avoid using sys.argv inside of CuminConfig
- if not home:
- home = os.path.normpath("/usr/share/cumin")
+ config.init()
- config = Config()
- config.add_param("data", str,
"postgresql://cumin@localhost/cumin")
- config.add_param("force", bool, False)
+ if "-h" in sys.argv or "--help" in sys.argv:
+ print_usage(config)
+ sys.exit(0)
+
- 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)
+ if config.debug:
+ config.prt()
- config.prt()
-
- home = os.environ["CUMIN_HOME"]
- data = config.get("data")
- force = config.get("force")
-
args = parse_command_args()
if not args:
print "Error: no command found"
- usage()
+ print_usage(config)
+ sys.exit(1)
command = args[0]
- database = MintDatabase(data)
+ database = MintDatabase(config.data)
database.check()
database.init()
if command == "create-schema":
- main = os.path.join(home, "sql", "schema.sql")
- indexes = os.path.join(home, "sql", "indexes.sql")
+ main = os.path.join(config.home, "sql", "schema.sql")
+ indexes = os.path.join(config.home, "sql", "indexes.sql")
database.createSchema((main, indexes))
elif command == "drop-schema":
- if force:
+ if config.force:
database.dropSchema()
else:
print "Error: command create-schema requires --force yes"
- usage()
+ print_usage(config)
+ sys.exit(1)
elif command == "add-user":
if len(args) != 2:
print "Error: no user name given"
- usage()
+ print_usage(config)
+ sys.exit(1)
name = args[1]
@@ -111,7 +102,7 @@
if force:
if len(args) != 2:
print "Error: no user name given"
- usage()
+ sys.exit(1)
accounts = ConsoleUser.selectBy(name=args[1])
@@ -123,11 +114,14 @@
print "Error: no such user '%s'" % args[1]
else:
print "Error: command remove-user requires --force yes"
- usage()
+ sys.exit(1)
elif command == "list-users":
accounts = ConsoleUser.select(orderBy='name')
+ print " id name"
+ print "---- " + ("-" * 20)
+
for account in accounts:
print "%4i %s" % (account.id, account.name)
@@ -135,7 +129,8 @@
print "(%i user%s found)" % (count, ess(count))
else:
print "Error: command '%s' not recognized" % command
- usage()
+ print_usage(config)
+ sys.exit(1)
if __name__ == "__main__":
try:
Show replies by date