def main(): if len(sys.argv) != 3: usage(sys.argv) config_uri = sys.argv[1] setup_logging(config_uri) settings = get_appsettings(config_uri) engine = engine_from_config(settings, 'sqlalchemy.') Session.configure(bind=engine) people = fetch_consent_data(sys.argv[2]) by_email = {} for user in people: email = user['email'] if email in by_email: if to_date(user) > by_email[email]: continue by_email[email] = to_date(user) matched = {} total = len(by_email) # Attempt to match by email for user in User.query_by().order_by(User.name).all(): if user.username in by_email: matched[user.username] = by_email[user.username] if not user.consent_at or \ by_email[user.username] < user.consent_at: print 'updating' user.consent_at = by_email[user.username] del by_email[user.username] transaction.commit() print('Matched {} out of {} ({} remaining)'.format(len(matched), total, len(by_email)))
def main(): if len(sys.argv) != 3: usage(sys.argv) config_uri = sys.argv[1] setup_logging(config_uri) settings = get_appsettings(config_uri) engine = engine_from_config(settings, 'sqlalchemy.') Session.configure(bind=engine) people = fetch_consent_data(sys.argv[2]) by_email = {} for user in people: email = user['email'] if email in by_email: if to_date(user) > by_email[email]: continue by_email[email] = to_date(user) matched = {} total = len(by_email) # Attempt to match by email for user in User.query_by().order_by(User.name).all(): if user.username in by_email: matched[user.username] = by_email[user.username] if not user.consent_at or \ by_email[user.username] < user.consent_at: print 'updating' user.consent_at = by_email[user.username] del by_email[user.username] transaction.commit() print('Matched {} out of {} ({} remaining)' .format(len(matched), total, len(by_email)))
def delete_unused_projects(): for class_ in locked_classes(): for project in class_.projects: submitted = set() for group in project.groups: submitted |= set(list(group.users)) - set(class_.admins) if len(submitted) < 10 and prompt( 'Do you want to delete project {}:{} with {} students?' .format(class_.name, project.name, len(submitted))): Session.delete(project) transaction.commit()
def delete_inactive_classes(): for class_ in locked_classes(): msg = None if len(class_.users) < 10: msg = ('Delete class {} with only {} users?' .format(class_.name, len(class_.users))) elif len(class_.admins) < 1: msg = 'Delete class {} with no admins?'.format(class_.name) elif len(class_.projects) < 1: msg = 'Delete class {} with no projects?'.format(class_.name) if msg and prompt(msg): Session.delete(class_) transaction.commit()
def main(): if len(sys.argv) < 2: usage(sys.argv) config_uri = sys.argv[1] setup_logging(config_uri) settings = get_appsettings(config_uri) engine = engine_from_config(settings, 'sqlalchemy.') Session.configure(bind=engine) mailer = Mailer.from_settings(settings) ldap_conn = helper.connect() for line in sys.stdin: merge_to_umail(ldap_conn, mailer, *line.strip().split()) transaction.commit()
def delete_inactive_users(): # Delete inactive users for user in User.query_by().order_by(User.created_at).all(): msg = None if user.is_admin or len(user.admin_for) > 0: continue # Admin for a class if not user.classes: msg = 'Delete user {} with no classes ({} files)'.format( user.name, len(user.files)) elif not user.groups_assocs: msg = 'Delete user {} with no groups?'.format(user.name) elif not user.files: msg = 'Delete user {} with no files?'.format(user.name) if msg and prompt(msg): Session.delete(user) transaction.commit()
def main(): if len(sys.argv) < 2: usage(sys.argv) config_uri = sys.argv[1] setup_logging(config_uri) settings = get_appsettings(config_uri) engine = engine_from_config(settings, 'sqlalchemy.') Session.configure(bind=engine) #delete_unused_projects() #delete_inactive_classes() #delete_inactive_users() delete_unlinked_files(settings['file_directory']) if False: update_umail_users() match_to_umail()
def merge_users(merge_to, merge_from): """Merge a non-umail account with a umail account.""" # Determine most active user based on most recently created group assert(merge_to.username.endswith('umail.ucsb.edu')) # Merge groups for u2g in merge_from.groups_assocs[:]: merge_to.group_with(merge_from, u2g.project, bypass_limit=True) # merge classes and files merge_to.classes.extend(merge_from.classes) merge_to.files.extend(merge_from.files) # update file ownership for sub in Submission.query_by(created_by=merge_from).all(): sub.created_by = merge_to # Delete the secondary user Session.delete(merge_from)
def merge_users(merge_to, merge_from): """Merge a non-umail account with a umail account.""" # Determine most active user based on most recently created group assert merge_to.username.endswith("umail.ucsb.edu") # Merge groups for u2g in merge_from.groups_assocs[:]: merge_to.group_with(merge_from, u2g.project, bypass_limit=True) # merge classes and files merge_to.classes.extend(merge_from.classes) merge_to.files.extend(merge_from.files) # update file ownership for sub in Submission.query_by(created_by=merge_from).all(): sub.created_by = merge_to # Delete the secondary user Session.delete(merge_from)