Skip to content

Commit

Permalink
add api to get local path of resource
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff Fischer committed Jun 2, 2020
1 parent 88732d8 commit a5aa1e6
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion dataworkspaces/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ class ResourceInfo(NamedTuple):
local_path: Optional[str]


def get_resource_info(workspace_uri_or_path: Optional[str] = None, verbose: bool = False):
def get_resource_info(workspace_uri_or_path: Optional[str] = None, verbose: bool = False
) -> List[ResourceInfo]:
"""Returns a list of ResourceInfo instances, describing the resources
defined for this workspace.
"""
Expand All @@ -62,6 +63,18 @@ def get_resource_info(workspace_uri_or_path: Optional[str] = None, verbose: bool
for r in workspace.get_resources()
]

def get_local_path_for_resource(
name: str,
workspace_uri_or_path: Optional[str] = None,
verbose: bool = False
) -> Optional[str]:
"""If a local path is available for this resource, return it. Otherwise,
return None."""
workspace = find_and_load_workspace(True, verbose, workspace_uri_or_path)
r = workspace.get_resource(name)
return cast(LocalStateResourceMixin, r).get_local_path_if_any() \
if isinstance(r, LocalStateResourceMixin) \
else None

class SnapshotInfo(NamedTuple):
"""Named tuple represneting the results from a call
Expand Down

0 comments on commit a5aa1e6

Please sign in to comment.