Skip to content

Commit

Permalink
[FEAT] macOS: Download mapwriter plugin during usage instead of manua…
Browse files Browse the repository at this point in the history
…lly copying during setup (#177)

* download mapwriter plugin on macOS identically to Windows

- one manuall step fewer

* move creation of win tooling dir

- function is independent of creating dir  before

* update unittests
  • Loading branch information
treee111 authored Feb 3, 2023
1 parent afb3d1e commit 1119db5
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 30 deletions.
10 changes: 0 additions & 10 deletions docs/QUICKSTART_ANACONDA.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,6 @@ brew install osmium-tool
brew install osmosis
```

3. Install mapsforge-map-writer plugin (Osmosis Plugin)
* Download the [mapsforge-map-writer](https://search.maven.org/search?q=a:mapsforge-map-writer) plugin, click on "file_download" and select "jar-with-dependecies.jar".
* Create this directory when it doesn't exist: `~/.openstreetmap/osmosis/plugins`. For example via terminal:
```
cd ~
mkdir -p .openstreetmap/osmosis/plugins
```
* Put the .jar into the `plugins` directory. You may have to enable showing hidden folders in finder via `Command + Shift + . (period)`
* more information: https://github.com/mapsforge/mapsforge/blob/master/docs/Getting-Started-Map-Writer.md#plugin-installation

# wahooMapsCreator
## Create Anaconda Environment
1. Open terminal (macOS/Linux) or **Anaconda Prompt** (Windows, via Startmenu)
Expand Down
28 changes: 24 additions & 4 deletions tests/test_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from wahoomc.downloader import older_than_x_days
from wahoomc.downloader import download_file
from wahoomc.downloader import get_osm_pbf_filepath_url
from wahoomc.downloader import download_tooling_win
from wahoomc.downloader import download_tooling
from wahoomc.downloader import Downloader
from wahoomc import constants
from wahoomc.constants_functions import get_tooling_win_path
Expand Down Expand Up @@ -158,17 +158,37 @@ def test_download_windows_files(self):
Test if Windows tooling files download is successful
"""
if platform.system() == "Windows":
path = os.path.join(constants.USER_TOOLING_WIN_DIR)
path = constants.USER_TOOLING_WIN_DIR

if os.path.exists(path):
shutil.rmtree(path)

os.makedirs(constants.USER_TOOLING_WIN_DIR, exist_ok=True)
download_tooling_win()
self.assertFalse(os.path.exists(path))

download_tooling()

self.assertTrue(os.path.exists(path))

self.assertTrue(
os.path.exists(get_tooling_win_path('osmfilter.exe', in_user_dir=True)))

def test_download_macos_files(self):
"""
Test if macOS tooling files download is successful
"""
if platform.system() != "Windows":
path = os.path.join(str(constants.USER_DIR), '.openstreetmap', 'osmosis',
'plugins', 'mapsforge-map-writer-0.18.0-jar-with-dependencies.jar')

if os.path.exists(path):
os.remove(path)

self.assertFalse(os.path.exists(path))

download_tooling()

self.assertTrue(os.path.exists(path))


if __name__ == '__main__':
unittest.main()
1 change: 1 addition & 0 deletions wahoomc/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from pathlib import Path

# User
USER_DIR = str(Path.home())
USER_WAHOO_MC = os.path.join(str(Path.home()), 'wahooMapsCreatorData')
USER_DL_DIR = os.path.join(USER_WAHOO_MC, '_download')
USER_MAPS_DIR = os.path.join(USER_DL_DIR, 'maps')
Expand Down
38 changes: 28 additions & 10 deletions wahoomc/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from wahoomc.constants import GEOFABRIK_PATH
from wahoomc.constants import OSMOSIS_WIN_FILE_PATH
from wahoomc.constants import USER_TOOLING_WIN_DIR
from wahoomc.constants import USER_DIR

log = logging.getLogger('main-logger')

Expand Down Expand Up @@ -92,32 +93,49 @@ def get_osm_pbf_filepath_url(country):
return map_file_path, url


def download_tooling_win():
def download_tooling():
"""
check for Windows tooling and download if not here already
this is done to bring down the filesize of the python module
Windows
- check for Windows tooling
- download if Windows tooling is not available
--> this is done to bring down the filesize of the python module
macOS
- check for mapwriter plugin and download if not existing
"""

mapwriter_plugin_url = 'https://search.maven.org/remotecontent?filepath=org/mapsforge/mapsforge-map-writer/0.18.0/mapsforge-map-writer-0.18.0-jar-with-dependencies.jar'

# Windows
if platform.system() == "Windows":
os.makedirs(USER_TOOLING_WIN_DIR, exist_ok=True)

if not os.path.isfile(OSMOSIS_WIN_FILE_PATH):
log.info('# Need to download Osmosis application for Windows')
download_file(OSMOSIS_WIN_FILE_PATH,
'https://github.com/openstreetmap/osmosis/releases/download/0.48.3/osmosis-0.48.3.zip',
get_tooling_win_path('Osmosis', in_user_dir=True))

mapwriter_plugin_path = os.path.join(USER_TOOLING_WIN_DIR,
'Osmosis', 'lib', 'default', 'mapsforge-map-writer-0.18.0-jar-with-dependencies.jar')
if not os.path.isfile(mapwriter_plugin_path):
log.info('# Need to download Osmosis mapwriter plugin for Windows')
download_file(mapwriter_plugin_path,
'https://search.maven.org/remotecontent?filepath=org/mapsforge/mapsforge-map-writer/0.18.0/mapsforge-map-writer-0.18.0-jar-with-dependencies.jar')

if not os.path.isfile(get_tooling_win_path('osmfilter.exe', in_user_dir=True)):
log.info('# Need to download osmfilter application for Windows')

download_file(get_tooling_win_path('osmfilter.exe', in_user_dir=True),
'http://m.m.i24.cc/osmfilter.exe')

mapwriter_plugin_path = os.path.join(USER_TOOLING_WIN_DIR,
'Osmosis', 'lib', 'default', 'mapsforge-map-writer-0.18.0-jar-with-dependencies.jar')

# Non-Windows
else:
mapwriter_plugin_path = os.path.join(
str(USER_DIR), '.openstreetmap', 'osmosis', 'plugins', 'mapsforge-map-writer-0.18.0-jar-with-dependencies.jar')

if not os.path.isfile(mapwriter_plugin_path):
log.info('# Need to download Osmosis mapwriter plugin')
# create plugins directory
os.makedirs(os.path.dirname(mapwriter_plugin_path), exist_ok=True)
download_file(mapwriter_plugin_path, mapwriter_plugin_url)


def get_latest_pypi_version():
"""
Expand Down
4 changes: 2 additions & 2 deletions wahoomc/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
check_installation_of_required_programs, write_config_file, \
adjustments_due_to_breaking_changes, copy_jsons_from_repo_to_user, \
check_installed_version_against_latest_pypi
from wahoomc.downloader import download_tooling_win
from wahoomc.downloader import download_tooling

from wahoomc.osm_maps_functions import OsmMaps
from wahoomc.osm_maps_functions import OsmData
Expand All @@ -36,7 +36,7 @@ def run(run_level):
check_installed_version_against_latest_pypi()
initialize_work_directories()
adjustments_due_to_breaking_changes()
download_tooling_win()
download_tooling()
check_installation_of_required_programs()

if run_level == 'init':
Expand Down
4 changes: 0 additions & 4 deletions wahoomc/setup_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
from wahoomc.constants import USER_OUTPUT_DIR
from wahoomc.constants import USER_CONFIG_DIR
from wahoomc.constants import VERSION
from wahoomc.constants import USER_TOOLING_WIN_DIR

log = logging.getLogger('main-logger')

Expand All @@ -41,9 +40,6 @@ def initialize_work_directories():
os.makedirs(USER_OUTPUT_DIR, exist_ok=True)
os.makedirs(USER_CONFIG_DIR, exist_ok=True)

if platform.system() == "Windows":
os.makedirs(USER_TOOLING_WIN_DIR, exist_ok=True)


def move_old_content_into_new_dirs():
"""
Expand Down

0 comments on commit 1119db5

Please sign in to comment.