-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #59 from lsst/tickets/PREOPS-4685
tickets/PREOPS-4685: use lsst.resources for loading data in the prenight briefing
- Loading branch information
Showing
10 changed files
with
131 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,5 +15,7 @@ dependencies: | |
- uranography | ||
- param | ||
- git | ||
- pip | ||
- wget | ||
- pip | ||
- pip: | ||
- lsst.resources |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,6 @@ dependencies: | |
- firefox | ||
- geckodriver | ||
- build | ||
- pip | ||
- pip: | ||
- lsst.resources |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,7 @@ dependencies = [ | |
"param", | ||
"pytz", | ||
"rubin-scheduler", | ||
"lsst.resources", | ||
"uranography >= 1.1.0 ", | ||
] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,3 +11,4 @@ param | |
pytz | ||
uranography | ||
rubin-scheduler | ||
pip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from lsst.resources import ResourcePath | ||
|
||
|
||
def find_file_resources(base_resource_uri, file_filter=None): | ||
"""Find matching files in a resource. | ||
Parameters | ||
---------- | ||
base_resource_uri : `str` | ||
The uri of the resource to search | ||
file_filter : `str` or `re.Pattern`, optional | ||
Regex to filter out files from the list before it is returned. | ||
Returns | ||
------- | ||
files : `list` of `str` | ||
The list of matching files available at the resource. | ||
""" | ||
base_resource = ResourcePath(base_resource_uri) | ||
accumulated_files = [] | ||
for dir_path, dir_names, file_names in base_resource.walk(file_filter=file_filter): | ||
for file_name in file_names: | ||
qualified_file_name = dir_path.join(file_name).geturl() | ||
if qualified_file_name not in accumulated_files: | ||
accumulated_files.append(qualified_file_name) | ||
|
||
return accumulated_files |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import unittest | ||
from pathlib import Path | ||
from tempfile import TemporaryDirectory | ||
|
||
from schedview.collect.resources import find_file_resources | ||
|
||
|
||
class TestResources(unittest.TestCase): | ||
def test_find_file_resources(self): | ||
# Generate some test files | ||
test_file_names = ["foo/bar.txt", "foo/baz.txt", "foo/qux/moo.txt"] | ||
made_files = [] | ||
with TemporaryDirectory() as temp_dir_name: | ||
temp_dir = Path(temp_dir_name) | ||
for file_name in test_file_names: | ||
file_path = temp_dir.joinpath(file_name) | ||
file_path.parent.mkdir(parents=True, exist_ok=True) | ||
made_files.append(file_path.as_uri()) | ||
with open(file_path, "w") as file_io: | ||
file_io.write("Test content.") | ||
|
||
# Verify that we found exactly the files we made | ||
found_files = find_file_resources(temp_dir) | ||
|
||
assert set(made_files) == set(found_files) |