| 1 |
#!/usr/bin/python |
#!/usr/bin/python |
| 2 |
|
|
| 3 |
# Remove a user (and associated place entries) from the database |
# Remove a user (and associated place entries) from the database |
| 4 |
# Copyright (C) 2002 Martin Michlmayr <tbm@cyrius.com> |
# Copyright (C) 2002, 2003 Martin Michlmayr <tbm@cyrius.com> |
| 5 |
# $Id$ |
# $Id$ |
| 6 |
|
|
| 7 |
# This program is free software; you can redistribute it and/or modify |
# This program is free software; you can redistribute it and/or modify |
| 20 |
|
|
| 21 |
|
|
| 22 |
import pg, sys |
import pg, sys |
| 23 |
import utils, gpg_utils |
import gpg_utils |
| 24 |
import apt_pkg |
import apt_pkg |
| 25 |
|
|
| 26 |
def help(): |
def help(): |
| 37 |
apt_pkg.ReadConfigFileISC(Cnf, "gpg.conf") |
apt_pkg.ReadConfigFileISC(Cnf, "gpg.conf") |
| 38 |
|
|
| 39 |
Arguments = [("h", "help", "RemoveUsers::Options::Help")] |
Arguments = [("h", "help", "RemoveUsers::Options::Help")] |
| 40 |
|
for i in ["Help"]: |
| 41 |
|
if not Cnf.has_key("RemoveUsers::Options::%s" % i): |
| 42 |
|
Cnf["RemoveUsers::Options::%s" % i] = "" |
| 43 |
|
|
| 44 |
removals = apt_pkg.ParseCommandLine(Cnf, Arguments, sys.argv) |
removals = apt_pkg.ParseCommandLine(Cnf, Arguments, sys.argv) |
| 45 |
|
|
| 50 |
help() |
help() |
| 51 |
return removals |
return removals |
| 52 |
|
|
| 53 |
# Remove one user and its places and (optionall) send mail |
# Remove one user and its places and (optionally) send mail |
| 54 |
def remove_user(db, email): |
def remove_user(db, email): |
| 55 |
print "Removing user with the email address %s..." % email |
print "Removing user with the email address %s..." % email |
| 56 |
db.query("DELETE FROM places WHERE who IN (SELECT id FROM people WHERE email = '%s')" % email) |
db.query("DELETE FROM places WHERE who IN (SELECT id FROM people WHERE email = '%s')" % email) |
| 62 |
removals = parse_args() |
removals = parse_args() |
| 63 |
db = pg.connect(Cnf["MyDB"]) |
db = pg.connect(Cnf["MyDB"]) |
| 64 |
for email in removals: |
for email in removals: |
| 65 |
remove_user(db, email) |
if gpg_utils.find_email(db, email): |
| 66 |
|
remove_user(db, email) |
| 67 |
|
else: |
| 68 |
|
print "No user with the email address %s" % email |
| 69 |
|
|
| 70 |
# vim:set ts=4: |
# vim:set ts=4: |
| 71 |
# vim:set expandtab: |
# vim:set expandtab: |