mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-21 23:46:18 -05:00
Allowing maintainer to change special directories.
This commit is contained in:
parent
00fe799b8f
commit
b05b2e7a6d
17 changed files with 499 additions and 195 deletions
|
|
@ -9,7 +9,7 @@ from sqlalchemy.orm import Session
|
|||
from modules.map.models import MapFile
|
||||
from wrolpi import flags
|
||||
from wrolpi.cmd import SUDO_BIN
|
||||
from wrolpi.common import get_media_directory, walk, logger
|
||||
from wrolpi.common import get_media_directory, walk, logger, get_wrolpi_config
|
||||
from wrolpi.dates import now, timedelta_to_timestamp, seconds_to_timestamp
|
||||
from wrolpi.db import optional_session, get_db_session
|
||||
from wrolpi.events import Events
|
||||
|
|
@ -23,14 +23,14 @@ IMPORTING = Manager().dict(dict(
|
|||
|
||||
|
||||
def get_map_directory() -> Path:
|
||||
map_directory = get_media_directory() / 'map'
|
||||
map_directory = get_media_directory() / get_wrolpi_config().map_directory
|
||||
if not map_directory.is_dir():
|
||||
map_directory.mkdir()
|
||||
map_directory.mkdir(parents=True)
|
||||
return map_directory
|
||||
|
||||
|
||||
def is_pbf_file(pbf: Path) -> bool:
|
||||
"""Uses file command to check type of a file. Returns True if a file is an OpenStreetMap PBF file."""
|
||||
"""Uses file command to check type of file. Returns True if a file is an OpenStreetMap PBF file."""
|
||||
cmd = ('/usr/bin/file', pbf)
|
||||
try:
|
||||
output = subprocess.check_output(cmd)
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ from unittest import mock
|
|||
import pytest
|
||||
|
||||
from modules.map import lib
|
||||
from wrolpi.common import get_wrolpi_config
|
||||
|
||||
|
||||
def test_get_map_paths(test_directory, make_files_structure):
|
||||
|
|
@ -101,3 +102,14 @@ def test_seconds_to_import_rpi4(size, expected):
|
|||
def test_seconds_to_import_rpi5(size, expected):
|
||||
with unittest.mock.patch('modules.map.lib.IS_RPI5', True):
|
||||
assert lib.seconds_to_import(size) == expected
|
||||
|
||||
|
||||
def test_get_custom_map_directory(test_directory, test_config):
|
||||
"""Custom directory can be used for map directory."""
|
||||
# Default location.
|
||||
assert lib.get_map_directory() == (test_directory / 'map')
|
||||
|
||||
get_wrolpi_config().map_directory = 'custom/deep/map/directory'
|
||||
|
||||
assert lib.get_map_directory() == (test_directory / 'custom/deep/map/directory')
|
||||
assert (test_directory / 'custom/deep/map/directory').is_dir()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue