From c327e0ca0b6208e2c1e7b9cfbfc562023356630d Mon Sep 17 00:00:00 2001 From: Mark Hymers Date: Sun, 4 Jul 2010 17:29:53 +0100 Subject: [PATCH] Allow getting db config out easily Signed-off-by: Mark Hymers --- dak/admin.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/dak/admin.py b/dak/admin.py index dbf1d45d..2be34703 100755 --- a/dak/admin.py +++ b/dak/admin.py @@ -55,6 +55,10 @@ Perform administrative work on the dak database. Commands can use a long or abbreviated form: + config / c: + c db show db config + c db-shell show db config in a usable form for psql + architecture / a: a list show a list of architectures a rm ARCH remove an architecture (will only work if @@ -323,6 +327,47 @@ dispatch['s-a'] = suite_architecture ################################################################################ +def show_config(command): + args = [str(x) for x in command] + cnf = utils.get_conf() + d = DBConn() + + die_arglen(args, 2, "E: config needs at least a command") + + mode = args[1].lower() + + if mode == 'db': + connstr = "" + if cnf["DB::Host"]: + # TCP/IP + connstr = "postgres://%s" % cnf["DB::Host"] + if cnf["DB::Port"] and cnf["DB::Port"] != "-1": + connstr += ":%s" % cnf["DB::Port"] + connstr += "/%s" % cnf["DB::Name"] + else: + # Unix Socket + connstr = "postgres:///%s" % cnf["DB::Name"] + if cnf["DB::Port"] and cnf["DB::Port"] != "-1": + connstr += "?port=%s" % cnf["DB::Port"] + print connstr + elif mode == 'db-shell': + e = ['PGDATABASE'] + print "PGDATABASE=%s" % cnf["DB::Name"] + if cnf["DB::Host"]: + print "PGHOST=%s" % cnf["DB::Host"] + e.append('PGHOST') + if cnf["DB::Port"] and cnf["DB::Port"] != "-1": + print "PGPORT=%s" % cnf["DB::Port"] + e.append('PGPORT') + print "export " + " ".join(e) + else: + die("E: config command unknown") + +dispatch['config'] = show_config +dispatch['c'] = show_config + +################################################################################ + def main(): """Perform administrative work on the dak database""" global dryrun -- 2.39.5