コード例 #1
0
def check_uploaded_files(project, contractor):
    """Iterate over all files, get parsers for them, try the parsers
    on the files.

    Returned is a list of errors, in the form of 3-tuples
    (current-file-path, original-filename, error-message)."""

    files = current_files(all_measurements(project, contractor))
    specifics = project.specifics()

    errors = []

    for path in files:
        with MovedFile(path) as moved_file:
            filename = os.path.basename(moved_file)
            parsers = specifics.parsers(filename)

            for parser in parsers:
                parse_object = parser_factory(parser, project, contractor, moved_file)
                result = parse_object.parse(check_only=True)

                if result.success:
                    # Skip other parsers
                    break
                elif not result.error:
                    # Unsuccessful but no errors, parser not suited
                    continue
                else:
                    errors.append((path, filename, result.error))
                    break
            else:
                errors.append((path, filename, "No suitable parser found."))

    return errors
コード例 #2
0
def call_parser(uploaded_file, parser):
    """Actually call the parser. Open files. Return result."""

    parser_instance = specifics.parser_factory(
        parser,
        uploaded_file.project,
        uploaded_file.contractor,
        uploaded_file.path)
    parseresult = parser_instance.parse()
    return parseresult