Esempio n. 1
0
        os.mkdir(outputpath)
        os.mkdir(filespath)

        courses[course] = outputpath

def delete_excluded_files(path, exclusion_matcher):
    for root, subdirs, files in os.walk(path):
        for filename in files:
            if exclusion_matcher.if_matches(filename):
                filepath = os.path.join(root, filename)
                os.remove(filepath)

if __name__ == '__main__':

    semester = jsonio.read_file(ENCODING, INPUT_PATH)

    project_matcher = RegexMatcher(PATTERN)
    java_matcher = RegexMatcher(JAVA_PATTERN)
    if EXCLUDE_PATTERN is not None:
        exclusion_matcher = RegexMatcher(EXCLUDE_PATTERN)

    for project in semester.find_projects(project_matcher):
        course = project.repo.student.group.course
        initialize_course(course)

        outputpath = courses[course]
        filespath = os.path.join(outputpath, FILES_DIR)

        student_path = os.path.join(filespath, project.repo.student.anon_id)
        os.mkdir(student_path)

def add_or_get(_dict, key, value):
    final_value = value

    if key in _dict:
        final_value = _dict[key]
    else:
        _dict[key] = final_value

    return final_value


if __name__ == '__main__':

    semester = jsonio.read_file(ENCODING, JSON_PATH)

    db = {}

    exam = add_or_get(db, EXAM_NAME, {})

    answers = add_or_get(exam, 'answers', {})

    answer = add_or_get(answers, '1', {})

    groups = add_or_get(answer, 'groups', {})

    for group_obj in semester.find_all_groups():

        group = add_or_get(groups, str(group_obj.number), {})
Esempio n. 3
0
from libmomo.semester import Semester

parser = argparse.ArgumentParser(description='Merge two or more .json file')
parser.add_argument('-i', metavar='IN', type=str, nargs='+', help='One or many input .json files')
parser.add_argument('-o', metavar='OUT', default='merged.json', type=str, help='The output .json file -- defaults to merged.json')

args = parser.parse_args()

if args.i is None:
    parser.print_usage()
    exit(0)

ENCODING = 'utf-8'
INPUT_PATHS = args.i
OUTPUT_PATH = args.o

if __name__ == '__main__':

    semester = None

    for input_path in INPUT_PATHS:

        parsed_semester = jsonio.read_file(ENCODING, input_path)

        if semester is not None:
            semester.merge(parsed_semester)
        else:
            semester = parsed_semester

    jsonio.write_file('utf-8', semester, OUTPUT_PATH)