示例#1
0
def setup_admin():
    """Setup super admin account."""
    log.info("Creating super admin account...")

    # Prompt for the username, defaults to the system user
    default_username = getpass.getuser()
    username = raw_input("Super admin username [%s]: " % default_username)
    if len(username) == 0:
        username = default_username

    # Prompt for the password
    password = getpass.getpass("Password: "******"Confirm password: "******"Passwords do not match!")
        sys.exit()

    # Add super user do the database
    user = AuthUser(username, password)
    Session.add(user)
    Session.commit()

    log.info("Created super admin account.")

    return user
示例#2
0
文件: websetup.py 项目: kuba/SIS
def setup_admin():
    """Setup super admin account."""
    log.info("Creating super admin account...")

    # Prompt for the username, defaults to the system user
    default_username = getpass.getuser()
    username = raw_input("Super admin username [%s]: " % default_username)
    if len(username) == 0:
        username = default_username

    # Prompt for the password
    password = getpass.getpass("Password: "******"Confirm password: "******"Passwords do not match!")
        sys.exit()

    # Add super user do the database
    user = AuthUser(username, password)
    Session.add(user)
    Session.commit()

    log.info("Created super admin account.")

    return user
示例#3
0
文件: schedule.py 项目: kuba/SIS
 def process_lesson(self, sub, room, part=None):
     sub = self.subjects[sub]
     teacher = None
     room = room == 'h' and 100 or int(room)
     l = Lesson(self.schedule, self.group, part, sub,
             teacher, self.day_number, self.order, room)
     Session.add(l)
     return l
示例#4
0
文件: schedule.py 项目: kuba/SIS
 def process_lesson(self, sub, room, part=None):
     sub = self.subjects[sub]
     teacher = None
     room = room == 'h' and 100 or int(room)
     l = Lesson(self.schedule, self.group, part, sub, teacher,
                self.day_number, self.order, room)
     Session.add(l)
     return l
示例#5
0
def parse_numbers(path):
    """
    Parse lucky numbers file.

    :param path: Path to parsable subjects file.

    """
    log.info("Parsing lucky numbers...")

    lucky_numbers_file = codecs.open(path, 'r', 'utf-8')
    for number in LuckyNumberParser(lucky_numbers_file):
        Session.add(number)
    Session.commit()

    log.info("Lucky numbers parsed and committed.")
示例#6
0
文件: websetup.py 项目: kuba/SIS
def parse_numbers(path):
    """
    Parse lucky numbers file.

    :param path: Path to parsable subjects file.

    """
    log.info("Parsing lucky numbers...")

    lucky_numbers_file = codecs.open(path, 'r', 'utf-8')
    for number in LuckyNumberParser(lucky_numbers_file):
        Session.add(number)
    Session.commit()

    log.info("Lucky numbers parsed and committed.")
示例#7
0
def parse_subjects(path):
    """
    Parse subjects file.

    :param path: Path to parsable subjects file.

    """
    log.info("Parsing subjects...")

    subjects = {}
    for subject in SubjectsParser(path):
        subjects[subject.short] = subject
        Session.add(subject)

    Session.commit()

    log.info("Subjects parsed and committed.")

    return subjects
示例#8
0
文件: websetup.py 项目: kuba/SIS
def parse_subjects(path):
    """
    Parse subjects file.

    :param path: Path to parsable subjects file.

    """
    log.info("Parsing subjects...")

    subjects = {}
    for subject in SubjectsParser(path):
        subjects[subject.short] = subject
        Session.add(subject)

    Session.commit()

    log.info("Subjects parsed and committed.")

    return subjects
示例#9
0
def parse_teachers(path):
    """
    Parse teachers file.

    :param path: Path to the parsable teachers file.

    """
    log.info("Parsing teachers...")

    teachers = {}
    teachers_file = codecs.open(path, 'r', 'utf-8')
    for teacher in TeachersParser(teachers_file):
        teachers[teacher.last_name] = teacher
        Session.add(teacher)

    Session.commit()

    log.info("Teachers parsed and committed.")

    return teachers
示例#10
0
文件: websetup.py 项目: kuba/SIS
def parse_teachers(path):
    """
    Parse teachers file.

    :param path: Path to the parsable teachers file.

    """
    log.info("Parsing teachers...")

    teachers = {}
    teachers_file = codecs.open(path, 'r', 'utf-8')
    for teacher in TeachersParser(teachers_file):
        teachers[teacher.last_name] = teacher
        Session.add(teacher)

    Session.commit()

    log.info("Teachers parsed and committed.")

    return teachers
示例#11
0
def parse_students(students_dir):
    """
    Parse directory with students files.

    :param students_dir: Directory with parsable students files.

    """
    log.info("Parsing students...")

    years = {}

    for path in os.listdir(students_dir):
        students_file = codecs.open(os.path.join(students_dir, path), 'r',
                                    'utf-8').readlines()
        parser = StudentsParser(students_file)
        years[parser.year] = parser.groups

        for students in parser.students.values():
            Session.add_all(students)

    groups = {}

    sorted_years = sorted(years.keys(), key=lambda y: y.start)
    for index, year in enumerate(reversed(sorted_years)):
        user_index = raw_input("Enter index for school year %d/%d [%d]: " \
                          % (year.start.year, year.start.year + 1, index+1))
        if user_index == '':
            user_index = str(index + 1)

        for group in years[year]:
            groups[user_index + group.name] = group

    Session.commit()

    log.info("Students (and groupd) parsed and committed.")

    return sorted_years[-1], groups
示例#12
0
文件: websetup.py 项目: kuba/SIS
def parse_students(students_dir):
    """
    Parse directory with students files.

    :param students_dir: Directory with parsable students files.

    """
    log.info("Parsing students...")

    years = {}

    for path in os.listdir(students_dir):
        students_file = codecs.open(os.path.join(students_dir, path), 'r',
                                    'utf-8').readlines()
        parser = StudentsParser(students_file)
        years[parser.year] = parser.groups

        for students in parser.students.values():
            Session.add_all(students)

    groups = {}

    sorted_years = sorted(years.keys(), key=lambda y: y.start)
    for index, year in enumerate(reversed(sorted_years)):
        user_index = raw_input("Enter index for school year %d/%d [%d]: " \
                          % (year.start.year, year.start.year + 1, index+1))
        if user_index == '':
            user_index = str(index+1)

        for group in years[year]:
            groups[user_index+group.name] = group

    Session.commit()

    log.info("Students (and groupd) parsed and committed.")

    return sorted_years[-1], groups
示例#13
0
def setup_app(command, conf, vars):
    """Setup the SIS application."""
    # Don't reload the app if it was loaded under the testing environment
    if not pylons.test.pylonsapp:
        load_environment(conf.global_conf, conf.local_conf)

    # Create the tables if they don't already exist
    log.info("Creating tables...")
    Base.metadata.create_all(bind=Session.bind)
    log.info("Schema saved to the database.")

    # Run parsers
    log.info("Running parsers...")

    # Parse lucky numbers
    parse_numbers(conf['numbers_file'])

    # Parse subjects
    subjects_file = conf.get('subjects_file', 'subjects.xml')
    subjects = parse_subjects(subjects_file)

    # Parse teachers
    teachers = parse_teachers(conf['teachers_file'])

    # Parse students
    students_dir = conf['students_dir']
    current_year, groups = parse_students(students_dir)

    # Parse schedule
    schedule = parse_schedule(conf['schedule_file'], current_year, groups,
                              subjects, teachers)

    try:
        Session.commit()
    except IntegrityError as error:
        if not error.statement.startswith("INSERT INTO lessons"):
            raise

        schedule_id, group_id, first_part, second_part, subject_id, \
            teacher_id, order, day, room = error.params

        # Rollback commit
        Session.rollback()

        group = Session.query(Group).get(group_id)
        subject = Session.query(Subject).get(subject_id)

        error_msg = (u"Integrity error: no teacher set!:\n"
                     "   group: {0}\n"
                     "   first_part: {1}\n"
                     "   second_part: {2}\n"
                     "   subject: {3}\n"
                     "   day: {4}\n"
                     "   order: {5}\n"
                     "   room: {6}")
        log.error(
            error_msg.format(group.full_name(), first_part, second_part,
                             subject.name, day, order, room).encode("utf-8"))

        sys.exit()

    # Check rooms, exclude gym
    check_rooms(schedule)

    # Create superadmin
    setup_admin()

    log.info("Succesfully set up.")
示例#14
0
文件: websetup.py 项目: kuba/SIS
def setup_app(command, conf, vars):
    """Setup the SIS application."""
    # Don't reload the app if it was loaded under the testing environment
    if not pylons.test.pylonsapp:
        load_environment(conf.global_conf, conf.local_conf)

    # Create the tables if they don't already exist
    log.info("Creating tables...")
    Base.metadata.create_all(bind=Session.bind)
    log.info("Schema saved to the database.")

    # Run parsers
    log.info("Running parsers...")

    # Parse lucky numbers
    parse_numbers(conf['numbers_file'])

    # Parse subjects
    subjects_file = conf.get('subjects_file', 'subjects.xml')
    subjects = parse_subjects(subjects_file)

    # Parse teachers
    teachers = parse_teachers(conf['teachers_file'])

    # Parse students
    students_dir = conf['students_dir']
    current_year, groups = parse_students(students_dir)

    # Parse schedule
    schedule = parse_schedule(conf['schedule_file'], current_year, groups, subjects,
                   teachers)

    try:
        Session.commit()
    except IntegrityError as error:
        if not error.statement.startswith("INSERT INTO lessons"):
            raise

        schedule_id, group_id, first_part, second_part, subject_id, \
            teacher_id, order, day, room = error.params

        # Rollback commit
        Session.rollback()

        group = Session.query(Group).get(group_id)
        subject = Session.query(Subject).get(subject_id)

        error_msg = (
            u"Integrity error: no teacher set!:\n"
            "   group: {0}\n"
            "   first_part: {1}\n"
            "   second_part: {2}\n"
            "   subject: {3}\n"
            "   day: {4}\n"
            "   order: {5}\n"
            "   room: {6}")
        log.error(error_msg.format(group.full_name(), first_part, second_part,
            subject.name, day, order, room).encode("utf-8"))

        sys.exit()

    # Check rooms, exclude gym
    check_rooms(schedule)

    # Create superadmin
    setup_admin()

    log.info("Succesfully set up.")