Skip to content

Commit

Permalink
Merge pull request #483 from cat-bro/bioblend_galaxy_histories_time_f…
Browse files Browse the repository at this point in the history
…ilters

Time filters for histories.get_histories
  • Loading branch information
nsoranzo committed Dec 11, 2023
2 parents 20ae9d0 + f665f80 commit b598f55
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 3 deletions.
11 changes: 11 additions & 0 deletions bioblend/_tests/TestGalaxyHistories.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,17 @@ def test_get_histories(self):
histories = self.gi.histories.get_histories(name=self.default_history_name)
assert len([h for h in histories if h["id"] == self.history["id"]]) == 1

# Test for time filters. We expect all histories to have been created an updated within the last few minutes
new_histories = self.gi.histories.get_histories(
create_time_min="2023-07-04T11:00:01", update_time_min="2023-08-06T11:00:05"
)
assert len(new_histories) == len(all_histories)

old_histories = self.gi.histories.get_histories(
create_time_max="2023-07-04T11:00:01", update_time_max="2023-08-06T11:00:05"
)
assert len(old_histories) == 0

# TODO: check whether deleted history is returned correctly
# At the moment, get_histories() returns only not-deleted histories
# and get_histories(deleted=True) returns only deleted histories,
Expand Down
82 changes: 79 additions & 3 deletions bioblend/galaxy/histories/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ def _get_histories(
filter_user_published: Optional[bool] = None,
get_all_published: bool = False,
slug: Optional[str] = None,
create_time_min: Optional[str] = None,
create_time_max: Optional[str] = None,
update_time_min: Optional[str] = None,
update_time_max: Optional[str] = None,
all: Optional[bool] = False,
) -> List[Dict[str, Any]]:
"""
Expand All @@ -105,6 +109,18 @@ def _get_histories(
if slug is not None:
params.setdefault("q", []).append("slug")
params.setdefault("qv", []).append(slug)
if create_time_min:
params.setdefault("q", []).append("create_time-ge")
params.setdefault("qv", []).append(create_time_min)
if create_time_max:
params.setdefault("q", []).append("create_time-le")
params.setdefault("qv", []).append(create_time_max)
if update_time_min:
params.setdefault("q", []).append("update_time-ge")
params.setdefault("qv", []).append(update_time_min)
if update_time_max:
params.setdefault("q", []).append("update_time-le")
params.setdefault("qv", []).append(update_time_max)
if all:
params["all"] = True

Expand All @@ -122,6 +138,10 @@ def get_histories(
deleted: bool = False,
published: Optional[bool] = None,
slug: Optional[str] = None,
create_time_min: Optional[str] = None,
create_time_max: Optional[str] = None,
update_time_min: Optional[str] = None,
update_time_max: Optional[str] = None,
all: Optional[bool] = False,
) -> List[Dict[str, Any]]:
"""
Expand All @@ -145,6 +165,22 @@ def get_histories(
:type slug: str
:param slug: History slug to filter on
:type create_time_min: str
:param create_time_min: Return histories created after the provided
time and date, which should be formatted as ``YYYY-MM-DDTHH-MM-SS``.
:type create_time_max: str
:param create_time_max: Return histories created before the provided
time and date, which should be formatted as ``YYYY-MM-DDTHH-MM-SS``.
:type update_time_min: str
:param update_time_min: Return histories last updated after the provided
time and date, which should be formatted as ``YYYY-MM-DDTHH-MM-SS``.
:type update_time_max: str
:param update_time_max: Return histories last updated before the provided
time and date, which should be formatted as ``YYYY-MM-DDTHH-MM-SS``.
:type all: bool
:param all: Whether to include histories from other users. This
parameter works only on Galaxy 20.01 or later and can be specified
Expand All @@ -162,11 +198,27 @@ def get_histories(
"The history_id parameter has been removed, use the show_history() method to view details of a history for which you know the ID.",
)
return self._get_histories(
name=name, deleted=deleted, filter_user_published=published, get_all_published=False, slug=slug, all=all
name=name,
deleted=deleted,
filter_user_published=published,
get_all_published=False,
slug=slug,
all=all,
create_time_min=create_time_min,
create_time_max=create_time_max,
update_time_min=update_time_min,
update_time_max=update_time_max,
)

def get_published_histories(
self, name: Optional[str] = None, deleted: bool = False, slug: Optional[str] = None
self,
name: Optional[str] = None,
deleted: bool = False,
slug: Optional[str] = None,
create_time_min: Optional[str] = None,
create_time_max: Optional[str] = None,
update_time_min: Optional[str] = None,
update_time_max: Optional[str] = None,
) -> List[Dict[str, Any]]:
"""
Get all published histories (by any user), or select a subset by
Expand All @@ -182,11 +234,35 @@ def get_published_histories(
:type slug: str
:param slug: History slug to filter on
:type create_time_min: str
:param create_time_min: Return histories created after the provided
time and date, which should be formatted as ``YYYY-MM-DDTHH-MM-SS``.
:type create_time_max: str
:param create_time_max: Return histories created before the provided
time and date, which should be formatted as ``YYYY-MM-DDTHH-MM-SS``.
:type update_time_min: str
:param update_time_min: Return histories last updated after the provided
time and date, which should be formatted as ``YYYY-MM-DDTHH-MM-SS``.
:type update_time_max: str
:param update_time_max: Return histories last updated before the provided
time and date, which should be formatted as ``YYYY-MM-DDTHH-MM-SS``.
:rtype: list
:return: List of history dicts.
"""
return self._get_histories(
name=name, deleted=deleted, filter_user_published=None, get_all_published=True, slug=slug
name=name,
deleted=deleted,
filter_user_published=None,
get_all_published=True,
slug=slug,
create_time_min=create_time_min,
create_time_max=create_time_max,
update_time_min=update_time_min,
update_time_max=update_time_max,
)

@overload
Expand Down

0 comments on commit b598f55

Please sign in to comment.