def do_updateUsers(self, unused_rest): try: if not self.ldap_context.GetUserFilter(): logging.error(messages.ERR_NO_USER_FILTER) return print messages.msg(messages.MSG_ADDING, self.ldap_context.GetUserFilter()) self._ShowGoogleAttributes() last_update_time.beginNewRun() self.errors = False # add in the condition for "> lastUpdate" search_filter = self.ldap_context.ldap_user_filter self.last_update = None if last_update_time.get(): self.last_update = self._TimeFromLDAPTime(last_update_time.get()) logging.debug('last_update time=%s' % str(self.last_update)) attrs = self.users.GetAttributes() directory_type = _GetDirectoryType(attrs) if self.last_update: search_filter = self._AndUpdateTime(search_filter, self.users.GetTimestampAttributeName(), self.last_update, directory_type) try: found_users = self.ldap_context.Search(filter_arg=search_filter, attrlist=attrs) except RuntimeError,e: logging.exception(str(e)) return if not found_users or found_users.UserCount() == 0: print messages.msg(messages.MSG_FIND_USERS_RETURNED, "0") if found_users: # we need to compute the Google attrs now, since # userdb.AnalyzeChangedUsers uses that: self.users.MapGoogleAttrs(found_users) (adds, mods, renames) = self.users.AnalyzeChangedUsers(found_users) # mark new uses as "to be added to Google" for dn in adds: found_users.SetGoogleAction(dn, 'added') for dn in mods: found_users.SetGoogleAction(dn, 'updated') for dn in renames: found_users.SetGoogleAction(dn, 'renamed') self.users.MergeUsers(found_users) if adds: print messages.msg(messages.MSG_NEW_USERS_ADDED, (str(len(adds)), str(self.users.UserCount()))) if mods: print messages.msg(messages.MSG_UPDATED_USERS_MARKED, (str(len(mods)))) if renames: print messages.msg(messages.MSG_RENAMED_USERS_MARKED, (str(len(renames)))) # find exited users & lock their accounts self._FindExitedUsers()
def do_showLastUpdate(self, unused_rest): self.last_update = last_update_time.get() if not self.last_update: print messages.MSG_SHOW_NO_LAST_UPDATE else: try: self.last_update = float(self.last_update) except ValueError: logging.exception('bad update time: %s', str(self.last_update)) self.last_update = 0 tstr = time.asctime(time.localtime()) print messages.msg(messages.MSG_SHOW_LAST_UPDATE, tstr)