X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=dak%2Fadmin.py;h=2bb1f1853187af821ccf06c317bf40cc6de8aefd;hb=01496fe710b21e3922ef7b6f3ffa74f2b697b34d;hp=dbf1d45d5df1c097f499608d5a20826b22de89f4;hpb=ce828cf5a3557613771eab8f0ad59586bbbcecbb;p=dak.git diff --git a/dak/admin.py b/dak/admin.py index dbf1d45d..2bb1f185 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,46 @@ dispatch['s-a'] = suite_architecture ################################################################################ +def show_config(command): + args = [str(x) for x in command] + cnf = utils.get_conf() + + 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