X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=julia;h=6cf0e46ae33765b50e28eb8a9d4569a13dac237d;hb=9540d873fa78598454af57f5f8a4875969ed0439;hp=6d5ff3746c20caeff54399ee052644187ab4f028;hpb=a092f0aa8e82394e25a16da9e87263ee26b8de0e;p=dak.git diff --git a/julia b/julia index 6d5ff374..6cf0e46a 100755 --- a/julia +++ b/julia @@ -1,8 +1,8 @@ #!/usr/bin/env python -# Sync PostgreSQL with (LDAP-generated) passwd file -# Copyright (C) 2001 James Troup -# $Id: julia,v 1.2 2001-09-27 01:23:41 troup Exp $ +# Sync PostgreSQL users with system users +# Copyright (C) 2001, 2002 James Troup +# $Id: julia,v 1.9 2003-01-02 18:12:50 troup Exp $ # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -30,7 +30,7 @@ ################################################################################ -import os, pg, string, sys; +import pg, pwd, sys; import utils; import apt_pkg; @@ -41,12 +41,13 @@ projectB = None; ################################################################################ def usage (exit_code=0): - print """Usage: julia [OPTION]... PASSWD_FILE -Sync PostgreSQL's pg_user with PASSWD_FILE. + print """Usage: julia [OPTION]... +Sync PostgreSQL's users with system users. + -h, --help show this help and exit + -n, --no-action don't do anything -q, --quiet be quiet about what is being done - -v, --verbose explain what is being done - -h, --help show this help and exit""" + -v, --verbose explain what is being done""" sys.exit(exit_code) ################################################################################ @@ -54,39 +55,32 @@ Sync PostgreSQL's pg_user with PASSWD_FILE. def main (): global Cnf, projectB; - apt_pkg.init(); + Cnf = utils.get_conf() - Cnf = apt_pkg.newConfiguration(); - apt_pkg.ReadConfigFileISC(Cnf,utils.which_conf_file()); - - Arguments = [('q',"quiet","Julia::Options::Quiet"), - ('v',"verbose","Julia::Options::Verbose"), - ('h',"help","Julia::Options::Help")]; - for i in ["quiet", "verbose", "help" ]: - Cnf["Julia::Options::%s" % (i)] = ""; + Arguments = [('n', "no-action", "Julia::Options::No-Action"), + ('q', "quiet", "Julia::Options::Quiet"), + ('v', "verbose", "Julia::Options::Verbose"), + ('h', "help", "Julia::Options::Help")]; + for i in [ "no-action", "quiet", "verbose", "help" ]: + if not Cnf.has_key("Julia::Options::%s" % (i)): + Cnf["Julia::Options::%s" % (i)] = ""; arguments = apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv); Options = Cnf.SubTree("Julia::Options") if Options["Help"]: usage(); - if arguments == []: - utils.warn("julia needs the name of the passwd file to sync with as an argument."); - usage(1); - elif len(arguments) > 1: - utils.warn("julia only takes one non-option argument, the passwd file to sync with."); + elif arguments: + utils.warn("julia takes no non-option arguments."); usage(1); - passwd = arguments[0]; projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"])); - valid_gid = Cnf.get("Julia::ValidGID",""); + valid_gid = int(Cnf.get("Julia::ValidGID","")); passwd_unames = {}; - passwd_file = utils.open_file(passwd); - for line in passwd_file.readlines(): - split = string.split(line, ':'); - uname = split[0]; - gid = split[3]; + for entry in pwd.getpwall(): + uname = entry[0]; + gid = entry[3]; if valid_gid and gid != valid_gid: if Options["Verbose"]: print "Skipping %s (GID %s != Valid GID %s)." % (uname, gid, valid_gid); @@ -101,8 +95,8 @@ def main (): postgres_unames[uname] = ""; known_postgres_unames = {}; - for i in string.split(Cnf.get("Julia::KnownPostgres",""),","): - uname = string.strip(i); + for i in Cnf.get("Julia::KnownPostgres","").split(","): + uname = i.strip(); known_postgres_unames[uname] = ""; keys = postgres_unames.keys() @@ -117,7 +111,8 @@ def main (): if not postgres_unames.has_key(uname): if not Options["Quiet"]: print "Creating %s user in Postgres." % (uname); - q = projectB.query('CREATE USER "%s"' % (uname)); + if not Options["No-Action"]: + q = projectB.query('CREATE USER "%s"' % (uname)); #######################################################################################