Skip to content

Commit

Permalink
Sort more recently modified files first
Browse files Browse the repository at this point in the history
Fixes #181
  • Loading branch information
luizribeiro committed Apr 17, 2021
1 parent 60412be commit 0ce3840
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 15 deletions.
4 changes: 3 additions & 1 deletion mariner/server/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ def list_files() -> str:
with os.scandir(path) as dir_entries:
files = []
directories = []
for dir_entry in dir_entries:
for dir_entry in sorted(
dir_entries, key=lambda t: t.stat().st_mtime, reverse=True
):
if dir_entry.is_file():
sliced_model_file: Optional[SlicedModelFile] = None
if dir_entry.name.endswith(tuple(get_supported_extensions())):
Expand Down
32 changes: 19 additions & 13 deletions mariner/tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pathlib
from unittest.mock import patch, ANY, Mock

from freezegun import freeze_time
from pyexpect import expect
from pyfakefs.fake_filesystem_unittest import TestCase
from werkzeug.datastructures import FileStorage
Expand Down Expand Up @@ -134,9 +135,14 @@ def test_print_status_while_idle(self) -> None:

def test_list_files(self) -> None:
self.fs.create_dir("/mnt/usb_share/subdir/")
self.fs.create_file("/mnt/usb_share/a.ctb", contents=self.ctb_file_contents)
self.fs.create_file("/mnt/usb_share/b.ctb", contents=self.ctb_file_contents)
self.fs.create_file("/mnt/usb_share/random_file.txt", contents="dummy content")
with freeze_time("2020-03-15"):
self.fs.create_file("/mnt/usb_share/a.ctb", contents=self.ctb_file_contents)
with freeze_time("2020-03-17"):
self.fs.create_file("/mnt/usb_share/b.ctb", contents=self.ctb_file_contents)
with freeze_time("2020-03-16"):
self.fs.create_file(
"/mnt/usb_share/random_file.txt", contents="dummy content"
)

response = self.client.get("/api/list_files")
expect(response.get_json()).to_equal(
Expand All @@ -149,12 +155,6 @@ def test_list_files(self) -> None:
"print_time_secs": 5621,
"can_be_printed": True,
},
{
"filename": "a.ctb",
"path": "a.ctb",
"print_time_secs": 5621,
"can_be_printed": True,
},
{
"filename": "b.ctb",
"path": "b.ctb",
Expand All @@ -166,6 +166,12 @@ def test_list_files(self) -> None:
"path": "random_file.txt",
"can_be_printed": False,
},
{
"filename": "a.ctb",
"path": "a.ctb",
"print_time_secs": 5621,
"can_be_printed": True,
},
],
}
)
Expand All @@ -185,14 +191,14 @@ def test_list_files_under_subdirectory(self) -> None:
"directories": [{"dirname": "subdir"}],
"files": [
{
"filename": "a.ctb",
"path": "foo/bar/a.ctb",
"filename": "b.ctb",
"path": "foo/bar/b.ctb",
"print_time_secs": 5621,
"can_be_printed": True,
},
{
"filename": "b.ctb",
"path": "foo/bar/b.ctb",
"filename": "a.ctb",
"path": "foo/bar/a.ctb",
"print_time_secs": 5621,
"can_be_printed": True,
},
Expand Down
44 changes: 43 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ whitenoise = "5.2.0"
[tool.poetry.dev-dependencies]
black = "20.8b1"
flake8 = "3.9.0"
freezegun = "1.1.0"
green = "3.2.5"
pyexpect = "1.0.21"
pyfakefs = "4.4.0"
Expand Down

0 comments on commit 0ce3840

Please sign in to comment.