# Path: submit/models.py
# class BuildFile(BasicBase, Base):
# class Class(BasicBase, Base):
# class ExecutionFile(BasicBase, Base):
# class File(BasicBase, Base):
# class FileVerifier(BasicBase, Base):
# class Group(BasicBase, Base):
# class GroupRequest(BasicBase, Base):
# class VerificationResults(object):
# class PasswordReset(Base):
# class Project(BasicBase, Base):
# class Submission(BasicBase, Base):
# class SubmissionToFile(Base):
# class TestCase(BasicBase, Base):
# class TestCaseResult(Base):
# class Testable(BasicBase, Base):
# class TestableResult(BasicBase, Base):
# class User(UserMixin, BasicBase, Base):
# class UserToGroup(Base):
#     def __cmp__(self, other):
#     def can_edit(self, user):
#     def edit_json(self, jsonify=True):
#     def __repr__(self):
#     def __str__(self):
#     def __cmp__(self, other):
#     def can_edit(self, user):
#     def can_view(self, user):
#     def is_admin(self, user):
#     def __cmp__(self, other):
#     def can_edit(self, user):
#     def edit_json(self, jsonify=True):
#     def fetch_or_create(data, base_path, sha1sum=None):
#     def file_path(base_path, sha1sum):
#     def __init__(self, base_path, data, sha1):
#     def can_view(self, user):
#     def __cmp__(self, other):
#     def can_edit(self, user):
#     def edit_json(self, jsonify=True):
#     def verify(self, base_path, file_):
#     def has_consent(self):
#     def users(self):
#     def users_str(self):
#     def __lt__(self, other):
#     def can_view(self, user):
#     def can_access(self, user):
#     def can_edit(self, user):
#     def errors(self):
#     def extra_filenames(self):
#     def warnings(self):
#     def __init__(self):
#     def __str__(self):
#     def missing_testables(self):
#     def set_errors_for_filename(self, errors, filename):
#     def set_extra_filenames(self, filenames):
#     def set_warnings_for_filename(self, warnings, filename):
#     def fetch_by(cls, **kwargs):
#     def generate(cls, user):
#     def get_token(self):
#     def delay(self):
#     def is_ready(self):
#     def student_submissions(self):
#     def __cmp__(self, other):
#     def build_files_json(self):
#     def can_access(self, user):
#     def can_edit(self, user):
#     def can_view(self, user):
#     def execution_files_json(self):
#     def file_verifiers_json(self):
#     def points_possible(self, include_hidden=False):
#     def process_submissions(self):
#     def recent_submissions(self):
#     def submit_string(self):
#     def testables_json(self):
#     def verify_submission(self, base_path, submission, update):
#     def is_late(self):
#     def earlier_submission_for_group(submission):
#     def later_submission_for_group(submission):
#     def merge_dict(d1, d2, on_collision):
#     def most_recent_submission(project, group):
#     def __cmp__(self, other):
#     def can_edit(self, user):
#     def can_view(self, user):
#     def file_mapping(self):
#     def get_delay(self, update):
#     def points(self, include_hidden=False):
#     def testables_pending(self, prune=False):
#     def testables_succeeded(self):
#     def time_score(self, request, group=False, admin=False):
#     def verify(self, base_path, update=False):
#     def __cmp__(self, other):
#     def __cmp__(self, other):
#     def can_edit(self, user):
#     def edit_json(self, jsonify=False):
#     def serialize(self):
#     def fetch_by_ids(cls, submission_id, test_case_id):
#     def update(self, data):
#     def __cmp__(self, other):
#     def can_edit(self, user):
#     def edit_json(self, jsonify=True):
#         def ids(item):
#     def points(self):
#     def requires_file(self, filename):
#     def update_points(self):
#     def fetch_or_create(make_results, status, **kwargs):
#     def get_value(cls, value):
#     def login(username, password, development_mode=False):
#     def __cmp__(self, other):
#     def __repr__(self):
#     def __str__(self):
#     def can_join_group(self, project):
#     def can_view(self, user):
#     def classes_can_admin(self):
#     def group_with(self, to_user, project, bypass_limit=False):
#     def fetch_group_assoc(self, project):
#     def make_submission(self, project):
#     def user_count(self):
#     def __eq__(self, other):
# def configure_sql(engine):
# def create_schema(alembic_config_ini=None):
# def populate_database():


from submit.models import Class, File, Session, User
from pyramid.paster import get_appsettings, setup_logging
from sqlalchemy import engine_from_config, not_
import os
import sys
import transaction
import helper
        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 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()


def match_to_umail():
    ldap_conn = helper.connect()
    for user in sorted(

# Path: submit/models.py
# class BuildFile(BasicBase, Base):
# class Class(BasicBase, Base):
# class ExecutionFile(BasicBase, Base):
# class File(BasicBase, Base):
# class FileVerifier(BasicBase, Base):
# class Group(BasicBase, Base):
# class GroupRequest(BasicBase, Base):
# class VerificationResults(object):
# class PasswordReset(Base):
# class Project(BasicBase, Base):
# class Submission(BasicBase, Base):
# class SubmissionToFile(Base):
# class TestCase(BasicBase, Base):
# class TestCaseResult(Base):
# class Testable(BasicBase, Base):
# class TestableResult(BasicBase, Base):
# class User(UserMixin, BasicBase, Base):
# class UserToGroup(Base):
#     def __cmp__(self, other):
#     def can_edit(self, user):
#     def edit_json(self, jsonify=True):
#     def __repr__(self):
#     def __str__(self):
#     def __cmp__(self, other):
#     def can_edit(self, user):
#     def can_view(self, user):
#     def is_admin(self, user):
#     def __cmp__(self, other):
#     def can_edit(self, user):
#     def edit_json(self, jsonify=True):
#     def fetch_or_create(data, base_path, sha1sum=None):
#     def file_path(base_path, sha1sum):
#     def __init__(self, base_path, data, sha1):
#     def can_view(self, user):
#     def __cmp__(self, other):
#     def can_edit(self, user):
#     def edit_json(self, jsonify=True):
#     def verify(self, base_path, file_):
#     def has_consent(self):
#     def users(self):
#     def users_str(self):
#     def __lt__(self, other):
#     def can_view(self, user):
#     def can_access(self, user):
#     def can_edit(self, user):
#     def errors(self):
#     def extra_filenames(self):
#     def warnings(self):
#     def __init__(self):
#     def __str__(self):
#     def missing_testables(self):
#     def set_errors_for_filename(self, errors, filename):
#     def set_extra_filenames(self, filenames):
#     def set_warnings_for_filename(self, warnings, filename):
#     def fetch_by(cls, **kwargs):
#     def generate(cls, user):
#     def get_token(self):
#     def delay(self):
#     def is_ready(self):
#     def student_submissions(self):
#     def __cmp__(self, other):
#     def build_files_json(self):
#     def can_access(self, user):
#     def can_edit(self, user):
#     def can_view(self, user):
#     def execution_files_json(self):
#     def file_verifiers_json(self):
#     def points_possible(self, include_hidden=False):
#     def process_submissions(self):
#     def recent_submissions(self):
#     def submit_string(self):
#     def testables_json(self):
#     def verify_submission(self, base_path, submission, update):
#     def is_late(self):
#     def earlier_submission_for_group(submission):
#     def later_submission_for_group(submission):
#     def merge_dict(d1, d2, on_collision):
#     def most_recent_submission(project, group):
#     def __cmp__(self, other):
#     def can_edit(self, user):
#     def can_view(self, user):
#     def file_mapping(self):
#     def get_delay(self, update):
#     def points(self, include_hidden=False):
#     def testables_pending(self, prune=False):
#     def testables_succeeded(self):
#     def time_score(self, request, group=False, admin=False):
#     def verify(self, base_path, update=False):
#     def __cmp__(self, other):
#     def __cmp__(self, other):
#     def can_edit(self, user):
#     def edit_json(self, jsonify=False):
#     def serialize(self):
#     def fetch_by_ids(cls, submission_id, test_case_id):
#     def update(self, data):
#     def __cmp__(self, other):
#     def can_edit(self, user):
#     def edit_json(self, jsonify=True):
#         def ids(item):
#     def points(self):
#     def requires_file(self, filename):
#     def update_points(self):
#     def fetch_or_create(make_results, status, **kwargs):
#     def get_value(cls, value):
#     def login(username, password, development_mode=False):
#     def __cmp__(self, other):
#     def __repr__(self):
#     def __str__(self):
#     def can_join_group(self, project):
#     def can_view(self, user):
#     def classes_can_admin(self):
#     def group_with(self, to_user, project, bypass_limit=False):
#     def fetch_group_assoc(self, project):
#     def make_submission(self, project):
#     def user_count(self):
#     def __eq__(self, other):
# def configure_sql(engine):
# def create_schema(alembic_config_ini=None):
# def populate_database():


# Path: scripts/cleanup.py
from submit.models import Class, File, Session, User
from pyramid.paster import get_appsettings, setup_logging
from sqlalchemy import engine_from_config, not_
import os
import sys
import transaction
import helper

        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 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()


def match_to_umail():
    ldap_conn = helper.connect()
    for user in sorted(

        User.query_by().filter(