diff --git a/ucs-school-old-homedirs/remove-old-homedirs.py b/ucs-school-old-homedirs/remove-old-homedirs.py index 31edd55..933e008 100755 --- a/ucs-school-old-homedirs/remove-old-homedirs.py +++ b/ucs-school-old-homedirs/remove-old-homedirs.py @@ -29,7 +29,7 @@ # /usr/share/common-licenses/AGPL-3; if not, see # . -__package__ = '' # workaround for PEP 366 +from __future__ import absolute_import import listener import os import shutil @@ -53,6 +53,7 @@ target_dir = listener.configRegistry.get("ucsschool/listener/oldhomedir/targetdir") fs_types = listener.configRegistry.get("ucsschool/listener/oldhomedir/fs_types", DEFAUL_FS).split(":") lo = None +local_ous = [] def check_target_dir(dir): @@ -141,16 +142,12 @@ def warn(msg): ) -def get_my_ous(): - """find out which OUs this host is responsible for, returns list of strings""" - return [s.name for s in School.get_all(lo)] - - def prerun(): - global lo + global lo, local_ous listener.setuid(0) try: lo, po = getMachineConnection(ldap_master=False) + local_ous = [s.name for s in School.get_all(lo)] except LDAPError as exc: warn(str(exc)) return @@ -164,12 +161,11 @@ def postrun(): def handler(dn, new, old, command): - my_ous = set(get_my_ous()) - users_ous = set(new.get("ucsschoolSchool", [])) + users_ous = set(new.get("ucsschoolSchool", local_ous)) if ( old and not new and not command == "r" or - old and new and command == "m" and my_ous.isdisjoint(users_ous) + old and new and command == "m" and local_ous.isdisjoint(users_ous) ): uid = old["uid"][0]