Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a bug in using TLES env variable #143

Merged
merged 3 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions doc/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,14 @@ Pyorbital has a module for parsing NORAD TLE-files
>>> tle.inclination
99.043499999999995

If no path is provided pyorbital first tries to read any local TLE files in the
directory given by the environment variable :envvar:`TLES`. If this variable is not
set Pyorbital will try get the earth observation TLE files over the internet
If no path is provided pyorbital first tries to read any local TLE files defined by the
environment variable :envvar:`TLES` giving a glob pattern that can be used to retrieve all relevant files:

.. code::

TLES=/path/to/tle_files/*/tle*txt

If this variable is not set Pyorbital will try get the earth observation TLE files over the internet
from `celestrak`_. Note this downloading only happens if no
specific TLE file is provided or if the :envvar:`TLES` environment variable is not set.

Expand Down
10 changes: 5 additions & 5 deletions pyorbital/tests/test_tlefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ def mock_env_tles_missing(monkeypatch):


@pytest.fixture
def mock_env_tles(monkeypatch):
def mock_env_tles(monkeypatch, fake_local_tles_dir):
"""Mock environment variable TLES."""
monkeypatch.setenv('TLES', '/path/to/local/tles')
monkeypatch.setenv('TLES', os.path.join(fake_local_tles_dir, '*'))


def test_get_config_path_no_env_defined(caplog, mock_env_ppp_config_dir_missing):
Expand Down Expand Up @@ -264,10 +264,10 @@ def test_get_local_tle_path_tle_env_missing(mock_env_tles_missing):
assert res is None


def test_get_local_tle_path(mock_env_tles):
def test_get_local_tle_path(mock_env_tles, fake_local_tles_dir):
"""Test getting the path to local TLE files."""
res = _get_local_tle_path_from_env()
assert res == '/path/to/local/tles'
assert res == os.path.join(fake_local_tles_dir, "*")


def test_get_uris_and_open_func_using_tles_env(caplog, fake_local_tles_dir, monkeypatch):
Expand All @@ -277,7 +277,7 @@ def test_get_uris_and_open_func_using_tles_env(caplog, fake_local_tles_dir, monk
"""
from collections.abc import Sequence

monkeypatch.setenv('TLES', str(fake_local_tles_dir))
monkeypatch.setenv('TLES', str(os.path.join(fake_local_tles_dir, "*")))
with caplog.at_level(logging.DEBUG):
uris, _ = _get_uris_and_open_func()

Expand Down
2 changes: 1 addition & 1 deletion pyorbital/tlefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ def _open(filename):
elif local_tle_path:
# TODO: get the TLE file closest in time to the actual satellite
# overpass, NOT the latest!
list_of_tle_files = glob.glob(os.path.join(local_tle_path, '*'))
list_of_tle_files = glob.glob(local_tle_path)
uris = (max(list_of_tle_files, key=os.path.getctime), )
LOGGER.debug("Reading TLE from %s", uris[0])
open_func = _open
Expand Down
Loading