Beispiel #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)))
Beispiel #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)))
Beispiel #3
0
def match_to_umail():
    ldap_conn = helper.connect()
    for user in sorted(
        User.query_by().filter(
            not_(User.username.contains('@umail.ucsb.edu'))).all()):
        if user.admin_for or user.is_admin or '(' in user.name:
            continue
        match = helper.find_user(ldap_conn, user.name)
        if match:
            print match, user.username
Beispiel #4
0
def update_umail_users():
    ldap_conn = helper.connect()
    for user in User.query_by().order_by(User.name).all():
        email = user.username
        if email.endswith('umail.ucsb.edu'):
            name = helper.fetch_name(ldap_conn, email)
            if name and name != user.name:
                user.name = name
            elif not name:
                print email, user.name
    transaction.commit()
Beispiel #5
0
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()