Skip to content

Commit

Permalink
Merge pull request #7 from intterra-io/bug/windows-path-bug
Browse files Browse the repository at this point in the history
Fix bug with windows directory slash direction
  • Loading branch information
tomeldar authored Aug 30, 2023
2 parents ee9677f + daafa2c commit cc3c67b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
26 changes: 15 additions & 11 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,25 +101,29 @@ def create_product_from_file_path(file_path: str) -> Product:
timezone.utc
)

if "images/" in file_path:
if "EO/" in file_path:
folders_in_path = file_path.split(os.path.sep)
# We only want to check the mission path, without filename and user's path
mission_path = folders_in_path[folders_in_path.index("missions") + 2 : -1]

if "images" in mission_path:
if "EO" in mission_path:
product = Product("image", "EO", last_modified_on)
if "HS/" in file_path:
if "HS" in mission_path:
product = Product("image", "HS", last_modified_on)
if "IR/" in file_path:
if "IR" in mission_path:
product = Product("image", "IR", last_modified_on)
elif "tactical/" in file_path:
if "Detection/" in file_path:
elif "tactical" in mission_path:
if "Detection" in mission_path:
product = Product("tactical", "Detection", last_modified_on)
if "HeatPerimeter/" in file_path:
if "HeatPerimeter" in mission_path:
product = Product("tactical", "HeatPerimeter", last_modified_on)
if "IntenseHeat/" in file_path:
if "IntenseHeat" in mission_path:
product = Product("tactical", "IntenseHeat", last_modified_on)
if "IsolatedHeat/" in file_path:
if "IsolatedHeat" in mission_path:
product = Product("tactical", "IsolatedHeat", last_modified_on)
if "ScatteredHeat/" in file_path:
if "ScatteredHeat" in mission_path:
product = Product("tactical", "ScatteredHeat", last_modified_on)
elif "videos/" in file_path:
elif "videos" in mission_path:
product = Product("video", None, last_modified_on)

if product is None:
Expand Down
10 changes: 5 additions & 5 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def test_get_mission_details_date_failure(self, mock_exit):

@patch("os.path.getmtime", return_value=1234567890.0)
def test_create_product_from_file_path_image(self, mock_getmtime):
file_path = "images/EO/some_image.tif"
file_path = "missions/name/images/EO/some_image.tif"
expected_product = Product(
"image", "EO", datetime.fromtimestamp(1234567890.0, tz=timezone.utc)
)
Expand All @@ -46,7 +46,7 @@ def test_create_product_from_file_path_image(self, mock_getmtime):
def test_create_product_from_file_path_image_with_wrong_type_in_path(
self, mock_getmtime
):
file_path = "images/EO/IRimage.tif"
file_path = "missions/name/images/EO/IRimage.tif"
expected_product = Product(
"image", "EO", datetime.fromtimestamp(1234567890.0, tz=timezone.utc)
)
Expand All @@ -59,7 +59,7 @@ def test_create_product_from_file_path_image_with_wrong_type_in_path(

@patch("os.path.getmtime", return_value=1234567890.0)
def test_create_product_from_file_path_tactical(self, mock_getmtime):
file_path = "tactical/Detection/some_detection.kml"
file_path = "missions/name/tactical/Detection/some_detection.kml"
expected_product = Product(
"tactical",
"Detection",
Expand All @@ -72,7 +72,7 @@ def test_create_product_from_file_path_tactical(self, mock_getmtime):

@patch("os.path.getmtime", return_value=1234567890.0)
def test_create_product_from_file_path_video(self, mock_getmtime):
file_path = "videos/some_video.ts"
file_path = "missions/name/videos/some_video.ts"
expected_product = Product(
"video", None, datetime.fromtimestamp(1234567890.0, tz=timezone.utc)
)
Expand All @@ -83,7 +83,7 @@ def test_create_product_from_file_path_video(self, mock_getmtime):

@patch("os.path.getmtime", return_value=1234567890.0)
def test_create_product_from_file_path_invalid(self, mock_getmtime):
file_path = "invalid_path/some_file.txt"
file_path = "missions/name/invalid_path/some_file.txt"
with self.assertRaises(ValueError):
create_product_from_file_path(file_path)

Expand Down

0 comments on commit cc3c67b

Please sign in to comment.