示例#1
0
def main():
    if len(sys.argv) != 2:
        sys.exit('''Usage: %s [DIRECTORY]
 Outputs .tex file to CWD
 Languages (for syntax highlighting) determined from file extensions.''' %
                 (sys.argv[0], ))

    # Check existence of folder
    directory = sys.argv[1]
    if not os.path.isdir(directory):
        sys.exit("Directory not found: %s" % directory)

    name_to_files = {}
    not_matched = []
    for item in os.listdir(directory):
        if not os.path.isfile(os.path.join(directory, item)):
            continue

        matches = re.findall("(.+?_\d+)_assignsubmission_file_(.+)$", item)

        if len(matches) == 0:
            not_matched.append(item)
        else:
            if matches[0][0] not in name_to_files:
                name_to_files[matches[0][0]] = []

            name_to_files[matches[0][0]].append(matches[0][1])

    for (name, files) in name_to_files.items():
        output_file_name = (name + "_files.tex").replace(" ", "_")
        output_file = open(output_file_name, "w")

        code2tex.makeTop(output_file)
        for file in files:
            full_file_name = name + "_assignsubmission_file_" + file
            full_file_path = os.path.join(directory, full_file_name)

            code2tex.addListing(full_file_path, file, output_file)
        code2tex.makeBottom(output_file)

        output_file.close()

        # Convert to PDF
        subprocess.call(["pdflatex", output_file_name])

    none_indicator = ["-----None-----"]
    print
    print "CONVERTED FILES FOR NAMES"
    for name in name_to_files.keys() or none_indicator:
        print name
    print
    print "FILES NOT MATCHED"
    for file in not_matched or none_indicator:
        print file
示例#2
0
def main():
    if len(sys.argv) != 2:
        sys.exit('''Usage: %s [DIRECTORY]
 Outputs .tex file to CWD
 Languages (for syntax highlighting) determined from file extensions.''' %
                 (sys.argv[0], ))

    # Check existence of folder
    directory = sys.argv[1]
    if not os.path.isdir(directory):
        sys.exit("Directory not found: %s" % directory)

    matched = []
    not_matched = []

    pattern = re.compile(r".*/(.+?_\d+)_assignsubmission_file_(.*)$")

    for item in os.listdir(directory):
        item = os.path.join(directory, item)
        # Each student's submissions are stored in a separate directory
        if not os.path.isdir(item):
            continue

        match = re.match(pattern, item)
        if match:
            matched.append((match.group(1), item))
        else:
            not_matched.append(item)

    for name, dir in matched:
        output_file_name = (name + "_files.tex").replace(" ", "_")
        output_file = open(output_file_name, "w")

        code2tex.makeTop(output_file)
        for file in os.listdir(dir):
            full_file_path = os.path.join(dir, file)
            code2tex.addListing(full_file_path, file, output_file)
        code2tex.makeBottom(output_file)

        output_file.close()

        # Convert to PDF
        print("{}".format(output_file_name))
        subprocess.call(
            ["pdflatex", "-interaction=batchmode", output_file_name])

    print()
    print("CONVERTED FILES FOR NAMES")
    for name, _ in matched or [("---None---", "")]:
        print(name)
    print()
    print("FILES NOT MATCHED")
    for file in not_matched or ["---None---"]:
        print(file)
示例#3
0
def main():
    if len(sys.argv) != 2:
        sys.exit('''Usage: %s [DIRECTORY]
 Outputs .tex file to CWD
 Languages (for syntax highlighting) determined from file extensions.''' % (sys.argv[0],))

    # Check existence of folder
    directory = sys.argv[1]
    if not os.path.isdir(directory):
        sys.exit("Directory not found: %s" % directory)

    matched = []
    not_matched = []

    pattern = re.compile(r".*/(.+?_\d+)_assignsubmission_file_(.*)$")

    for item in os.listdir(directory):
        item = os.path.join(directory, item)
        # Each student's submissions are stored in a separate directory
        if not os.path.isdir(item):
            continue

        match = re.match(pattern, item)
        if match:
            matched.append((match.group(1), item))
        else:
            not_matched.append(item)

    for name, dir in matched:
        output_file_name = (name + "_files.tex").replace(" ", "_")
        output_file = open(output_file_name, "w")

        code2tex.makeTop(output_file)
        for file in os.listdir(dir):
            full_file_path = os.path.join(dir, file)
            code2tex.addListing(full_file_path, file, output_file)
        code2tex.makeBottom(output_file)

        output_file.close()

        # Convert to PDF
        print("{}".format(output_file_name))
        subprocess.call(["pdflatex", "-interaction=batchmode", output_file_name])

    none_indicator = ["-----None-----"]
    print()
    print("CONVERTED FILES FOR NAMES")
    for name, _ in matched or none_indicator:
        print(name)
    print()
    print("FILES NOT MATCHED")
    for file in not_matched or none_indicator:
        print(file)
示例#4
0
def main():
    if len(sys.argv) != 2:
        sys.exit('''Usage: %s [DIRECTORY]
 Outputs .tex file to CWD
 Languages (for syntax highlighting) determined from file extensions.''' % (sys.argv[0],))

    # Check existence of folder
    directory = sys.argv[1]
    if not os.path.isdir(directory):
        sys.exit("Directory not found: %s" % directory)

    name_to_files = {}
    not_matched = []
    for item in os.listdir(directory):
        if not os.path.isfile(os.path.join(directory, item)):
            continue

        matches = re.findall("(.+?_\d+)_assignsubmission_file_(.+)$", item)

        if len(matches) == 0:
            not_matched.append(item)
        else:
            if matches[0][0] not in name_to_files:
                name_to_files[matches[0][0]] = []

            name_to_files[matches[0][0]].append(matches[0][1])

    for (name, files) in name_to_files.items():
        output_file_name = (name + "_files.tex").replace(" ", "_")
        output_file = open(output_file_name, "w")

        code2tex.makeTop(output_file)
        for file in files:
            full_file_name = name + "_assignsubmission_file_" + file
            full_file_path = os.path.join(directory, full_file_name)

            code2tex.addListing(full_file_path, file, output_file)
        code2tex.makeBottom(output_file)

        output_file.close()

        # Convert to PDF
        subprocess.call(["pdflatex", output_file_name])

    none_indicator = ["-----None-----"]
    print
    print "CONVERTED FILES FOR NAMES"
    for name in name_to_files.keys() or none_indicator:
        print name
    print
    print "FILES NOT MATCHED"
    for file in not_matched or none_indicator:
        print file
示例#5
0
def main():
    if len(sys.argv) != 2:
        sys.exit('''Usage: %s [DIRECTORY]
 Outputs .tex files and generate PDFs in CWD
 Languages (for syntax highlighting) determined from file extensions.''' % (sys.argv[0],))

    # Check existence of folder
    directory = Path(sys.argv[1])
    if not directory.is_dir():
        sys.exit("Directory not found: %s" % directory)

    matched = defaultdict(list)
    not_matched = []

    # Regexes for matching various LMS filenames
    patterns = {}
    patterns['Moodle'] = re.compile(r"([^/]+?_\d+)_assignsubmission_file_/(.+)$")
    patterns['Canvas'] = re.compile(r"([^/]+?_\d+)_\d+_(.+)$")

    # Gather all files in directory
    files = directory.glob('**/*')

    # Match filenames against any LMS patterns, storing those that match
    for f in files:
        if f.is_dir():
            continue

        for pattern in patterns.values():
            match = re.search(pattern, str(f))
            if match:
                matchinfo = (str(f), match.group(2))
                matched[match.group(1)].append(matchinfo)
                break
        else:
            # triggered if end of for loop reached, break *not* used
            not_matched.append(str(f))

    # Output .tex and create PDFs for all matched files, grouped by name
    for name in matched:
        output_file_name = (name + "_files.tex").replace(" ", "_")
        output_file = open(output_file_name, "w")

        code2tex.makeTop(output_file)
        for fullpath, filename in matched[name]:
            code2tex.addListing(fullpath, filename, output_file)
        code2tex.makeBottom(output_file)

        output_file.close()

        # Convert to PDF
        print("{}".format(output_file_name))
        subprocess.call(["pdflatex", "-interaction=batchmode", output_file_name])

    print()
    print("CONVERTED FILES FOR NAMES")
    for name in matched or ["---None---"]:
        print(name)
    print()
    print("FILES NOT MATCHED")
    for file in not_matched or ["---None---"]:
        print(file)
def main():
    if len(sys.argv) != 2:
        sys.exit('''Usage: %s [DIRECTORY]
 Outputs .tex files and generate PDFs in CWD
 Languages (for syntax highlighting) determined from file extensions.''' %
                 (sys.argv[0], ))

    # Check existence of folder
    directory = Path(sys.argv[1])
    if not directory.is_dir():
        sys.exit("Directory not found: %s" % directory)

    matched = defaultdict(list)
    not_matched = []

    # Regexes for matching various LMS filenames
    patterns = {}
    patterns['Moodle'] = re.compile(
        r"([^/]+?_\d+)_assignsubmission_file_/(.+)$")
    patterns['Canvas'] = re.compile(r"([^/]+?_\d+)_\d+_(.+)$")

    # Gather all files in directory
    files = directory.glob('**/*')

    # Match filenames against any LMS patterns, storing those that match
    for f in files:
        if f.is_dir():
            continue

        for pattern in patterns.values():
            match = re.search(pattern, str(f))
            if match:
                matchinfo = (str(f), match.group(2))
                matched[match.group(1)].append(matchinfo)
                break
        else:
            # triggered if end of for loop reached, break *not* used
            not_matched.append(str(f))

    # Output .tex and create PDFs for all matched files, grouped by name
    for name in matched:
        output_file_name = (name + "_files.tex").replace(" ", "_")
        output_file = open(output_file_name, "w")

        code2tex.makeTop(output_file)
        for fullpath, filename in matched[name]:
            code2tex.addListing(fullpath, filename, output_file)
        code2tex.makeBottom(output_file)

        output_file.close()

        # Convert to PDF
        print("{}".format(output_file_name))
        subprocess.call(
            ["pdflatex", "-interaction=batchmode", output_file_name])

    print()
    print("CONVERTED FILES FOR NAMES")
    for name in matched or ["---None---"]:
        print(name)
    print()
    print("FILES NOT MATCHED")
    for file in not_matched or ["---None---"]:
        print(file)