def process_file(job_identifier, file_id):
    job_handler = JobHandler(job_identifier)
    if job_handler.file_ready_for_process(
            file_id) and job_handler.filematch_try_process(file_id):
        time.sleep(0.001)
        if job_handler.filematch_processing_id(file_id) != file_id:
            # In this case two threads are processing the same file match =>
            # Race Condition!
            return
        matched_files = job_handler.get_matched_files(file_id)
        for matched_file in matched_files:
            job_handler.set_file_processed(matched_file.file_id)

        source_path = job_handler.get_upload_folder_path()
        destination_path = job_handler.get_output_folder_path()
        export_format_name = job_handler.get_export_format_name()
        source_srs = job_handler.get_source_srs()
        target_srs = job_handler.get_target_srs()
        simplify_parameter = job_handler.get_simplify_parameter()
        additional_arguments = job_handler.get_shell_parameters()
        extract_base_path = job_handler.get_extract_folder_path()
        if matched_files[0].file_match.is_archive:
            file_name = matched_files[0].matched_file_name
            if job_handler.get_file_count() > 1:
                # Creates a sub folder in the extract folder
                extract_path = os.path.join(
                    extract_base_path,
                    os.path.splitext(file_name)[0])
            else:
                extract_path = extract_base_path
            process_archive(
                job_identifier,
                os.path.join(
                    source_path,
                    file_name),
                extract_base_path,
                extract_path,
                destination_path,
                export_format_name,
                source_srs,
                target_srs,
                simplify_parameter,
                additional_arguments,
                1)
        else:
            conversion.convert_files(
                job_identifier,
                source_path,
                matched_files,
                destination_path,
                export_format_name,
                source_srs,
                target_srs,
                simplify_parameter,
                additional_arguments)
def process_file(job_identifier, file_id):
    job_handler = JobHandler(job_identifier)
    if job_handler.file_ready_for_process(
            file_id) and job_handler.filematch_try_process(file_id):
        time.sleep(0.001)
        if job_handler.filematch_processing_id(file_id) != file_id:
            # In this case two threads are processing the same file match =>
            # Race Condition!
            return
        matched_files = job_handler.get_matched_files(file_id)
        for matched_file in matched_files:
            job_handler.set_file_processed(matched_file.file_id)

        source_path = job_handler.get_upload_folder_path()
        destination_path = job_handler.get_output_folder_path()
        export_format_name = job_handler.get_export_format_name()
        source_srs = job_handler.get_source_srs()
        target_srs = job_handler.get_target_srs()
        simplify_parameter = job_handler.get_simplify_parameter()
        additional_arguments = job_handler.get_shell_parameters()
        extract_base_path = job_handler.get_extract_folder_path()
        if matched_files[0].file_match.is_archive:
            file_name = matched_files[0].matched_file_name
            if job_handler.get_file_count() > 1:
                # Creates a sub folder in the extract folder
                extract_path = os.path.join(extract_base_path,
                                            os.path.splitext(file_name)[0])
            else:
                extract_path = extract_base_path
            process_archive(job_identifier,
                            os.path.join(source_path, file_name),
                            extract_base_path, extract_path, destination_path,
                            export_format_name, source_srs, target_srs,
                            simplify_parameter, additional_arguments, 1)
        else:
            conversion.convert_files(job_identifier, source_path,
                                     matched_files, destination_path,
                                     export_format_name, source_srs,
                                     target_srs, simplify_parameter,
                                     additional_arguments)
Exemple #3
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)