Skip to content

Commit

Permalink
[BREAKING] X/Y coordinates can be given as input parameters (e.g. for…
Browse files Browse the repository at this point in the history
… testing!) & refactoring of GUI & CLI processing (#99)

This PR makes it possible to provide X/Y coordinates via command line as input parameter to create the corresponding map

* change start of the tool via two parsers

- to distinct between GUI and CLI processing clearer
- to be able to implement input of X/Y coordinates in the future

* refactor input processing

* adjust input processing (differentiate input further)

- incl. adjusting relevat unit tests

* implement input as X/Y coordinates

- functions to provide the functionality
- call of them

* different changes

- tests
- country-name without "/" for X/Y coordinates

* update documentation and launch config

* PR review findings

* implement multiple x/y combinations as input parameters

- in coding & tests
- launch config: malta as x/y + multiple x/y comb

* update documentation for CLI usage in USAGE.md

* do not log each .json file

BREAKING CHANGE:
The GUI and CLI of wahooMapsCreator will now be called differently than
before:
- `python wahoo_map_creator.py gui` and
- `python wahoo_map_creator.py cli -co malta`

This will ensure better control over the CLI input parameters, help
messages and is more consistent now!
  • Loading branch information
treee111 committed Apr 9, 2022
1 parent 528bf44 commit dabe117
Show file tree
Hide file tree
Showing 10 changed files with 444 additions and 154 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ osmconvert_tempfile.*
**/__pycache__/*
**/*.pyc
**/*.DS_Store
**/*.py*.tmp

# mac/unix

Expand Down
56 changes: 55 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
"program": "${workspaceRoot}/wahoo_map_creator.py",
"console": "integratedTerminal",
"args": [
"cli",
"-fi",
"${workspaceRoot}/tests/json/germany-only1.json",
"-md",
"100",
Expand All @@ -23,6 +25,8 @@
"program": "${workspaceRoot}/wahoo_map_creator.py",
"console": "integratedTerminal",
"args": [
"cli",
"-fi",
"${workspaceRoot}/tests/json/germany-only1.json",
"-tag",
"tag-wahoo-hidrive2.xml",
Expand All @@ -40,6 +44,8 @@
"program": "${workspaceRoot}/wahoo_map_creator.py",
"console": "integratedTerminal",
"args": [
"cli",
"-fi",
"${workspaceRoot}/tests/json/germany-only2.json",
"-md",
"100",
Expand All @@ -55,6 +61,8 @@
"program": "${workspaceRoot}/wahoo_map_creator.py",
"console": "integratedTerminal",
"args": [
"cli",
"-co",
"germany"
]
},
Expand All @@ -65,6 +73,8 @@
"program": "${workspaceRoot}/wahoo_map_creator.py",
"console": "integratedTerminal",
"args": [
"cli",
"-co",
"malta",
"-tag",
"tag-wahoo.xml",
Expand All @@ -81,6 +91,8 @@
"program": "${workspaceRoot}/wahoo_map_creator.py",
"console": "integratedTerminal",
"args": [
"cli",
"-co",
"malta",
"-tag",
"tag-wahoo.xml",
Expand All @@ -97,7 +109,9 @@
"request": "launch",
"program": "${workspaceRoot}/wahoo_map_creator.py",
"console": "integratedTerminal",
"args": []
"args": [
"gui"
]
},
{
"name": "cli help",
Expand All @@ -116,6 +130,8 @@
"program": "${workspaceRoot}/wahoo_map_creator.py",
"console": "integratedTerminal",
"args": [
"cli",
"-co",
"malta",
"-tag",
"tag-wahoo.xml",
Expand All @@ -132,6 +148,8 @@
"program": "${workspaceRoot}/wahoo_map_creator.py",
"console": "integratedTerminal",
"args": [
"cli",
"-co",
"liechtenstein",
"-tag",
"tag-wahoo.xml",
Expand Down Expand Up @@ -162,6 +180,42 @@
"C:\\VSCode\\python\\wahooMapsCreator\\output\\138\\100\\land.shp",
"C:\\VSCode\\python\\wahooMapsCreator\\output\\138\\100\\land1.osm"
]
},
{
"name": "x/y: 133/88",
"type": "python",
"request": "launch",
"program": "${workspaceRoot}/wahoo_map_creator.py",
"console": "integratedTerminal",
"args": [
"cli",
"-xy",
"133/88"
]
},
{
"name": "x/y: 138/100 (malta)",
"type": "python",
"request": "launch",
"program": "${workspaceRoot}/wahoo_map_creator.py",
"console": "integratedTerminal",
"args": [
"cli",
"-xy",
"138/100"
]
},
{
"name": "x/y: 138/100,133/88 (two tiles)",
"type": "python",
"request": "launch",
"program": "${workspaceRoot}/wahoo_map_creator.py",
"console": "integratedTerminal",
"args": [
"cli",
"-xy",
"138/100,133/88"
]
}
]
}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ Using Anaconda to setup a virtual Python environment is the fastest way to get w
## Run wahooMapsCreator
via GUI
```
python wahoo_map_creator.py
python wahoo_map_creator.py gui
```
via CLI
```
python wahoo_map_creator.py malta
python wahoo_map_creator.py cli -co malta
```

A detailled description of the usage is documented [:computer: here](docs/USAGE.md#usage-of-wahoomapscreator)
Expand Down
54 changes: 48 additions & 6 deletions common_python/file_directory_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# import official python packages
import json
import os
from os.path import isfile, join
import subprocess
import sys
import zipfile
Expand Down Expand Up @@ -83,11 +84,12 @@ def create_empty_directories(tiles_from_json):
os.makedirs(outdir)


def read_json_file(json_file_path):
def read_json_file(json_file_path, logging = True):
"""
read the tiles from the given json file
"""
print('\n# Read json file')
if logging:
print('\n# Read json file')

with open(json_file_path) as json_file:
tiles_from_json = json.load(json_file)
Expand All @@ -96,10 +98,11 @@ def read_json_file(json_file_path):
print('! Json file could not be opened.')
sys.exit()

# logging
print(
f'+ Use json file {json_file.name} with {len(tiles_from_json)} tiles')
print('# Read json file: OK')
if logging:
# logging
print(
f'+ Use json file {json_file.name} with {len(tiles_from_json)} tiles')
print('# Read json file: OK')

return tiles_from_json

Expand All @@ -124,3 +127,42 @@ def write_to_file(file_path, request):
with open(file_path, 'wb') as file_handle:
for chunk in request.iter_content(chunk_size=1024*100):
file_handle.write(chunk)


def get_folders_in_folder(folder):
"""
return foldernames of given folder without path as list
"""
onlyfolders = [f for f in os.listdir(
folder) if not isfile(join(folder, f))]

return onlyfolders


def get_files_in_folder(folder):
"""
return filenames of given folder without path as list
"""
onlyfiles = [f for f in os.listdir(folder) if isfile(join(folder, f))]

return onlyfiles


def get_filenames_of_jsons_in_folder(folder):
"""
return json-file filenames of given folder without path as list
"""
# log.debug('function: get_filenames_of_jsons_in_folder')
# log.debug('# Read available json files from directory: "%s"', folder)

json_files = []

for file in get_files_in_folder(folder):
if file.endswith('.json'):
# filename = file.split('.')[0]
filename = os.path.splitext(file)[0]
json_files.extend([filename])

# log.debug('# Read available json files from directory: "%s" : OK', folder)

return json_files
Loading

0 comments on commit dabe117

Please sign in to comment.