#!/usr/bin/env python import ldap import subprocess import os import os.path import grp import shutil user_dirs=["Music","Videos","Pictures","Documents","Share","Groups"] def is_frozen_and_generic(username): final_groups = [] ok=False p = subprocess.Popen(["llxcfg-showvars","LDAP_BASE_DN"],stdout=subprocess.PIPE) output = p.communicate()[0] if output != "": basedn = output.split("'")[1] connect_ldap = ldap.initialize('ldap://server') connect_ldap.PORT = 636 ldap_result = connect_ldap.search_s(basedn,ldap.SCOPE_SUBTREE,'cn=flux') try: frozen_groups = ldap_result[0][1]['member'] for x in frozen_groups: final_groups.append(x[x.find("=")+1:x.find(",")]) except Exception as e: print e user_groups = grp.getgrall() for group in user_groups: if username in group[3]: if group[0] in final_groups: ok=True if ok: basedn = output.split("'")[1] connect_ldap = ldap.initialize('ldap://server') connect_ldap.PORT = 636 ldap_result = connect_ldap.search_s(basedn,ldap.SCOPE_SUBTREE,'uid='+username) try: if (ldap_result[0][1].has_key('x-lliurex-type') and ldap_result[0][1]['x-lliurex-usertype']==["generic"]) or (not ldap_result[0][1].has_key('x-lliurex-type')): home_dir=os.path.expanduser("~/") dir_list=os.listdir(home_dir) for item in dir_list: if os.path.isfile(home_dir+item): #print "os.remove("+home_dir+item+")" os.remove(home_dir+item) elif os.path.isdir(home_dir+item): if "net" in os.path.realpath(home_dir+item): delete_dir_content(home_dir+item+"/") except Exception as e: print e else: print "do nothing" #def is_freeze def delete_dir_content(dir): try: for item in os.listdir(dir): if os.path.isfile(dir+item): #print "os.remove("+dir+item+")" os.remove(dir+item) elif os.path.isdir(dir+item): if item not in user_dirs: #print "shutil.rmtree("+dir+item+")" shutil.rmtree(dir+item) else: delete_dir_content(dir+item+"/") except Exception as e: print e #def delete_dir_content print os.environ["USER"] is_frozen_and_generic(os.environ["USER"])