def test_deconstruct_file_path():
    assert helpers.deconstruct_file_path(EMPTY_STRING) == (None, EMPTY_STRING,
                                                           None, None)

    name_and_format = f'{FILE_NAME}.{FILE_FORMAT}'
    assert helpers.deconstruct_file_path(join(FILE_PATH, name_and_format)) == \
        (FILE_PATH, FILE_NAME, None, FILE_FORMAT)

    timestamp = datetime_to_string(get_current_datetime())
    assert helpers.deconstruct_file_path(join(
        FILE_PATH, timestamp)) == (FILE_PATH, EMPTY_STRING, timestamp, None)
    assert helpers.deconstruct_file_path(join(FILE_PATH, f'{timestamp}.{name_and_format}')) \
        == (FILE_PATH, FILE_NAME, timestamp, FILE_FORMAT)
Exemplo n.º 2
0
def delta(first_input_path, second_input_path, output_path, compress):
    (_, output_name, _, _) = deconstruct_file_path(output_path)
    delta_path = create_delta(delta_path=definitions.DELTAS_PATH,
                              delta_name=output_name,
                              first_input_pbf_path=first_input_path,
                              second_input_pbf_path=second_input_path,
                              should_compress=compress)
    safe_copy(delta_path, output_path)
Exemplo n.º 3
0
def clip_polygon(input_path,
                 polygon_path,
                 input_timestamp,
                 base_output_path,
                 exist_ok=False):
    (_, input_name, _, _) = deconstruct_file_path(input_path)
    (_, polygon_name, _, _) = deconstruct_file_path(polygon_path)

    output_format = definitions.FORMATS_MAP['OSM_PBF']
    output_name = f'{input_name}.{polygon_name}.{input_timestamp}.{output_format}'
    output_path = os.path.join(base_output_path, output_name)

    if not exist_ok or not os.path.isfile(output_path):
        run_command_wrapper(command=f'{definitions.OSMOSIS_PATH} \
                        --read-pbf-fast file={input_path} outPipe.0=1 \
                        --bounding-polygon file={polygon_path} \
                        completeWays=true completeRelations=true inPipe.0=1 outPipe.0=2 \
                        --write-pbf file={output_path} inPipe.0=2 \
                        -v',
                            subprocess_name=SUBPROCESS_NAME)
    return output_path
Exemplo n.º 4
0
def apply_changes_by_polygon(base_output_path, input_path, change_path,
                             polygon_path):
    (_, input_name, _, _) = deconstruct_file_path(input_path)
    (_, _, changes_timestamps,
     changes_format) = deconstruct_file_path(change_path)

    compression_type = definitions.COMPRESSION_METHOD_MAP[changes_format]

    output_format = definitions.FORMATS_MAP['OSM_PBF']
    output_path = os.path.join(
        base_output_path, f'{input_name}.{changes_timestamps}.{output_format}')

    run_command_wrapper(command=f'{definitions.OSMOSIS_PATH} \
                    --read-pbf-fast file={input_path} outPipe.0=1 \
                    --read-xml-change compressionMethod={compression_type} file={change_path} outPipe.0=2 \
                    --apply-change inPipe.0=1 inPipe.1=2 outPipe.0=3 \
                    --bounding-polygon file={polygon_path} inPipe.0=3 outPipe.0=4 \
                    --write-pbf file={output_path} inPipe.0=4 \
                    -v',
                        subprocess_name=SUBPROCESS_NAME)
    return output_path
Exemplo n.º 5
0
def set_osm_file_timestamp(input_path, new_timestamp):
    (dir, name, _, input_format) = deconstruct_file_path(input_path)
    temp_path = os.path.join(dir, f'{str(uuid4())}.{input_format}')
    run_command_wrapper(command=f'{definitions.OSMCONVERT_PATH} \
                    {input_path} \
                    --timestamp={new_timestamp} \
                    -o={temp_path} \
                    --verbose',
                        subprocess_name=SUBPROCESS_NAME)
    output_name = f'{name}.{new_timestamp}.{input_format}'
    output_path = os.path.join(dir, output_name)
    os.rename(temp_path, output_path)
    return output_path
Exemplo n.º 6
0
def drop_author(input_path, output_path=None):
    (input_dir, _, _, input_format) = deconstruct_file_path(input_path)
    output_not_given = False
    if output_path is None:
        output_not_given = True
        output_path = os.path.join(input_dir, f'{str(uuid4())}.{input_format}')
    run_command_wrapper(command=f'{definitions.OSMCONVERT_PATH} \
                    --drop-author \
                    {input_path} \
                    -o={output_path} \
                    --verbose',
                        subprocess_name=SUBPROCESS_NAME)
    if output_not_given:
        os.rename(output_path, input_path)
        return input_path
    return output_path