Ejemplo n.º 1
0
def process_folder(job_identifier,
                   source_path,
                   file_dict,
                   destination_path,
                   export_format_name,
                   source_srs,
                   target_srs,
                   simplify_parameter,
                   additional_arguments,
                   archive_depth=1):
    job_handler = JobHandler(job_identifier)
    file_matcher = FileMatcher(file_dict)

    for file_match in file_matcher.get_matches():
        # Rename files
        for file_id, new_file_name in file_match.get_file_dict().items():
            original_file_name = file_matcher.get_original_file_name(file_id)
            if original_file_name != new_file_name:
                filemanager.rename_file(source_path, original_file_name,
                                        new_file_name)

    for file_match in file_matcher.get_matches():
        job_handler.add_file_match(source_path, file_match.get_file_dict(),
                                   file_match.get_ogr_format_name(),
                                   file_match.is_archive(),
                                   file_match.is_valid())

    for file_match in file_matcher.get_matches():
        file_id = list(file_match.get_file_dict().keys())[0]
        if not job_handler.get_file_processed(file_id):
            matched_files = job_handler.get_matched_files(file_id)
            for matched_file in matched_files:
                job_handler.set_file_processed(matched_file.file_id)

        if matched_files[0].file_match.is_archive:
            # Process nested archive
            archive_file_name_without_extension = os.path.splitext(
                matched_files[0].file_name)[0]
            archive_path = os.path.join(source_path,
                                        matched_files[0].file_name)
            unpack_path = os.path.join(source_path,
                                       archive_file_name_without_extension)
            output_path = os.path.join(destination_path,
                                       archive_file_name_without_extension)
            process_archive(job_identifier, archive_path, unpack_path,
                            unpack_path, output_path, export_format_name,
                            source_srs, target_srs, simplify_parameter,
                            additional_arguments, archive_depth + 1)
        else:
            conversion.convert_files(job_identifier, source_path,
                                     matched_files, destination_path,
                                     export_format_name, source_srs,
                                     target_srs, simplify_parameter,
                                     additional_arguments)
Ejemplo n.º 2
0
def start_conversion_job(request, client_job_token):
    if request.method == 'POST':
        # Read POST values
        POST_dict = request.POST.dict()
        export_format_name = POST_dict['export_format'].strip()
        del POST_dict['export_format']
        source_srs = POST_dict['source_srs'].strip()
        del POST_dict['source_srs']
        target_srs = POST_dict['target_srs'].strip()
        del POST_dict['target_srs']
        simplify_parameter = POST_dict['simplify_parameter'].strip()
        del POST_dict['simplify_parameter']
        download_name = POST_dict['download_name'].strip()
        del POST_dict['download_name']
        if len(download_name) > 10:
            download_name = download_name[0:7] + '...'
        client_ip = get_client_ip(request)
        client_language = get_client_language(request)
        client_user_agent = get_client_user_agent(request)

        session_key = request.session.session_key
        job_identifier = jobidentification.get_new_job_identifier_by_client_job_token(
            session_key, client_job_token)
        job_id = job_identifier.job_id
        if job_id == '':
            return HttpResponseServerError('Error: Job Token is not valid.')

        job_handler = JobHandler(job_identifier)
        log_handler = LogHandler(job_identifier)
        download_handler = DownloadHandler(job_identifier)

        file_matcher = FileMatcher(POST_dict)
        for file_match in file_matcher.get_matches():
            job_handler.add_file_match(
                job_handler.get_upload_folder_path(),
                file_match.get_file_dict(),
                file_match.get_ogr_format_name(),
                file_match.is_archive(),
                file_match.is_valid())

        format_information = OgrFormat.get_format_information_by_name(
            export_format_name)
        if format_information is not None:
            job_handler.set_export_format_name(format_information.ogr_name)
            for shell_parameter in format_information.additional_parameters:
                if shell_parameter.use_for_writing:
                    job_handler.add_shell_parameter(
                        shell_parameter.prefix,
                        shell_parameter.parameter_name,
                        shell_parameter.parameter_value,
                        shell_parameter.value_quotation_marks)

        for global_shell_parameter in GlobalOgrShellParameter.get_active_parameters():
            job_handler.add_shell_parameter_object(global_shell_parameter)

        job_handler.set_export_format_name(export_format_name)
        job_handler.set_source_srs(source_srs)
        job_handler.set_target_srs(target_srs)
        job_handler.set_simplify_parameter(simplify_parameter)

        download_handler.set_download_caption(download_name)

        log_handler.set_start_time()
        log_handler.set_client_ip(client_ip)
        log_handler.set_client_language(client_language)
        log_handler.set_client_user_agent(client_user_agent)
        log_handler.set_input_type('files')
        log_handler.set_export_format_name(
            job_handler.get_export_format_name())
        log_handler.set_source_srs(job_handler.get_source_srs())
        log_handler.set_target_srs(job_handler.get_target_srs())
        log_handler.set_simplify_parameter(
            job_handler.get_simplify_parameter())

        jobprocessing.initialize_conversion_job(job_identifier)

        return HttpResponse('success')
    else:
        return redirect_to_main_page(request)
Ejemplo n.º 3
0
def process_folder(
        job_identifier,
        source_path,
        file_dict,
        destination_path,
        export_format_name,
        source_srs,
        target_srs,
        simplify_parameter,
        additional_arguments,
        archive_depth=1):
    job_handler = JobHandler(job_identifier)
    file_matcher = FileMatcher(file_dict)

    for file_match in file_matcher.get_matches():
        # Rename files
        for file_id, new_file_name in file_match.get_file_dict().items():
            original_file_name = file_matcher.get_original_file_name(file_id)
            if original_file_name != new_file_name:
                filemanager.rename_file(
                    source_path,
                    original_file_name,
                    new_file_name)

    for file_match in file_matcher.get_matches():
        job_handler.add_file_match(
            source_path,
            file_match.get_file_dict(),
            file_match.get_ogr_format_name(),
            file_match.is_archive(),
            file_match.is_valid())

    for file_match in file_matcher.get_matches():
        file_id = list(file_match.get_file_dict().keys())[0]
        if not job_handler.get_file_processed(file_id):
            matched_files = job_handler.get_matched_files(file_id)
            for matched_file in matched_files:
                job_handler.set_file_processed(matched_file.file_id)

        if matched_files[0].file_match.is_archive:
            # Process nested archive
            archive_file_name_without_extension = os.path.splitext(
                matched_files[0].file_name)[0]
            archive_path = os.path.join(
                source_path,
                matched_files[0].file_name)
            unpack_path = os.path.join(
                source_path,
                archive_file_name_without_extension)
            output_path = os.path.join(
                destination_path,
                archive_file_name_without_extension)
            process_archive(
                job_identifier,
                archive_path,
                unpack_path,
                unpack_path,
                output_path,
                export_format_name,
                source_srs,
                target_srs,
                simplify_parameter,
                additional_arguments,
                archive_depth + 1)
        else:
            conversion.convert_files(
                job_identifier,
                source_path,
                matched_files,
                destination_path,
                export_format_name,
                source_srs,
                target_srs,
                simplify_parameter,
                additional_arguments)