Skip to content

Commit

Permalink
working version with last and first file functions
Browse files Browse the repository at this point in the history
  • Loading branch information
spepler committed Apr 8, 2024
1 parent e972014 commit 68bdbe4
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
38 changes: 35 additions & 3 deletions fbi_core/fbi_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,17 +228,49 @@ def lastest_file(directory):
:param str directory: path to search for last updated file
:return dict or None: Record for the last updated file.
"""
return top_file(directory, "last_modified")

# miss spelt
latest_file = lastest_file

def first_file(directory):
"""First file record in ES order of logical path under a path.
:param str directory: path to search.
:return dict or None: File Record.
"""
return top_file(directory, "path.keyword", order="asc")

def last_file(directory):
"""Last file record in ES order of logical path under a path.
:param str directory: path to search.
:return dict or None: File Record.
"""
return top_file(directory, "path.keyword")

def top_file(directory, order_by, order="desc"):
"""First file record in ES order of logical path under a path.
:param str directory: path to search.
:param str order_by: attribute to order on.
:param str directory:
:return dict or None: Record for the first file.
"""
query = all_under_query(directory, item_type="file")
sort = [{"last_modified": {"order": "desc"}}]
sort = [{order_by: {"order": order}}]
result = es.search(index=indexname, query=query, sort=sort, size=1, request_timeout=900)
if len(result["hits"]["hits"]) == 0:
return None
last_record = result["hits"]["hits"][0]["_source"]
if "last_modified" in last_record:

order_by = order_by.replace(".keyword", "")
if order_by in last_record:
return last_record
else:
return None


def links_to(target):
"""return list of links to an archive target."""
sort = [{ "path.keyword": "asc" }]
Expand Down Expand Up @@ -489,7 +521,7 @@ def update_file_location(path_list, location):
:param list pathlist: A list of paths to mark up.
:param str location: "on_disk", "on_tape" or "on_obstore"."""
assert location in ("on_disk", "on_tape", "on_obstore")
assert location in ("on_disk", "on_tape", "on_obstore", "on_cache")

for path in path_list:
rec = get_record(path)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

setup(
name='fbi-core',
version='1.3.1',
version='1.3.2',
description='File Based Index (FBI) core tools',
long_description=long_description,

Expand Down

0 comments on commit 68bdbe4

Please sign in to comment.