示例#1
0
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)))
示例#2
0
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)))
示例#3
0
文件: cleanup.py 项目: ucsb-cs/submit
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()
示例#4
0
文件: cleanup.py 项目: ucsb-cs/submit
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()
示例#5
0
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()
示例#6
0
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()
示例#7
0
文件: cleanup.py 项目: ucsb-cs/submit
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()
示例#8
0
文件: cleanup.py 项目: ucsb-cs/submit
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()
示例#9
0
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)
示例#10
0
文件: helper.py 项目: ucsb-cs/submit
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)