[sysadmin-bin] Add options.parser to the cleanup-accounts script and rename it
- From: Andrea Veri <av src gnome org>
- To: gnome-sysadmin gnome org,commits-list gnome org
- Subject: [sysadmin-bin] Add options.parser to the cleanup-accounts script and rename it
- Date: Mon, 24 Mar 2014 12:41:09 +0000 (UTC)
commit 56126db079c6a236a3cf22694da1cf4a053117c0
Author: Andrea Veri <av gnome org>
Date: Mon Mar 24 13:41:03 2014 +0100
Add options.parser to the cleanup-accounts script and rename it
...ccounts.py => cleanup-inactive-ldap-accounts.py | 20 +++++++++++++++++---
1 files changed, 17 insertions(+), 3 deletions(-)
---
diff --git a/cleanup-accounts.py b/cleanup-inactive-ldap-accounts.py
similarity index 77%
rename from cleanup-accounts.py
rename to cleanup-inactive-ldap-accounts.py
index 7fe1d26..372ae33 100755
--- a/cleanup-accounts.py
+++ b/cleanup-inactive-ldap-accounts.py
@@ -1,14 +1,26 @@
#!/usr/bin/python
+from __future__ import print_function
import os
+import sys
import calendar
import time
import ldap
import ldap.filter
+from optparse import OptionParser
LDAP_USER_BASE='ou=people,dc=gnome,dc=org'
LDAP_GROUP_BASE='ou=groups,dc=gnome,dc=org'
+parser = OptionParser()
+parser.add_option("--print-inactive-accounts", action="store_true", default=False,
+ help="Generates a list of inactive accounts by parsing each gnome_pushlog file. The list
includes accounts that have been removed already")
+parser.add_option("--verbose",
+ action="store_true", dest="verbose", default=False,
+ help="Prints the list of accounts that are getting removed from gnomecvs/ftpbasic as the
scripts runs")
+
+(options, args) = parser.parse_args()
+
infrastructure_folders = 'archive', 'cgit', 'empty-description', 'repositories.txt', 'repositories.doap'
repositories = filter( lambda f: not f.startswith(infrastructure_folders), os.listdir('/git'))
last_pushed_times = {}
@@ -37,12 +49,10 @@ for repository in repositories:
now = time.time()
-print 'The following users will be removed from the gnomevcs, ftpbasic groups:\n'
-
for user, last_pushed in last_pushed_times.iteritems():
if last_pushed < now - 2 * 365 * 24 * 60 * 60:
last_pushed = time.gmtime(last_pushed)
- print "%s: %s" % (user, time.strftime("%d-%m-%Y", last_pushed))
+ print ("%s: %s" % (user, time.strftime("%d-%m-%Y", last_pushed)), end='')
def user_is_current(username):
return username in last_pushed_times and last_pushed_times[username] >= now - 2 * 365 * 24 * 60 * 60
@@ -85,10 +95,14 @@ ftpbasic_users = (get_uids_from_group('ftpbasic'))
for gnomecvs_user in gnomecvs_users:
if not user_is_current(gnomecvs_user):
+ if options.verbose:
+ print ("Removing user %s from gnomecvs" % gnomecvs_user, end='\n')
remove_members = [ (ldap.MOD_DELETE, 'memberUid','%s' % gnomecvs_user) ]
l.modify_s('cn=gnomecvs,ou=groups,dc=gnome,dc=org', remove_members)
for ftpbasic_user in ftpbasic_users:
if not user_is_current(ftpbasic_user):
+ if options.verbose:
+ print ("Removing user %s from ftpbasic" % ftpbasic_user, end='\n')
remove_members = [ (ldap.MOD_DELETE, 'memberUid','%s' % ftpbasic_user) ]
l.modify_s('cn=ftpbasic,ou=groups,dc=gnome,dc=org', remove_members)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]