Skip to content

Commit

Permalink
Add long form list
Browse files Browse the repository at this point in the history
  • Loading branch information
qubixes committed Nov 29, 2024
1 parent 852862f commit 1a43ba7
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
24 changes: 23 additions & 1 deletion ibridges/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,10 +340,32 @@ def ibridges_list():
help="Show metadata for each iRODS location.",
action="store_true",
)
parser.add_argument(
"-s", "--short",
help="Display available data objects/collections in short form.",
action="store_true"
)
parser.add_argument(
"-l", "--long",
help="Display available data objects/collections in long form.",
action="store_true",
)

args, _ = parser.parse_known_args()
with _cli_auth(ienv_path=_get_ienv_path()) as session:
_list_coll(session, _parse_remote(args.remote_path, session), args.metadata)
ipath = _parse_remote(args.remote_path, session)
if args.long:
for cur_path in ipath.walk(depth=1):
if str(cur_path) == str(ipath):
continue
if cur_path.collection_exists():
print(f"C- {cur_path.name}")
else:
print(f"{cur_path.checksum: <50} {cur_path.size: <12} {cur_path.name}")
elif args.short:
print(" ".join([x.name for x in ipath.walk(depth=1) if str(x) != str(ipath)]))
else:
_list_coll(session, ipath, args.metadata)


def ibridges_meta_show():
Expand Down
17 changes: 13 additions & 4 deletions ibridges/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,11 +455,12 @@ def walk(self, depth: Optional[int] = None) -> Iterable[IrodsPath]:
"""
all_data_objects: dict[str, list[IrodsPath]] = defaultdict(list)
for path, name, size, checksum in _get_data_objects(self.session, self.collection):
prc_data_objects = _get_data_objects(self.session, self.collection, depth=depth)
for path, name, size, checksum in prc_data_objects:
abs_path = IrodsPath(self.session, path).absolute()
ipath = CachedIrodsPath(self.session, size, True, checksum, path, name)
all_data_objects[str(abs_path)].append(ipath)
all_collections = _get_subcoll_paths(self.session, self.collection)
all_collections = _get_subcoll_paths(self.session, self.collection, depth=depth)
all_collections = sorted(all_collections, key=str)
sub_collections: dict[str, list[IrodsPath]] = defaultdict(list)
for cur_col in all_collections:
Expand Down Expand Up @@ -634,7 +635,8 @@ def collection_exists(self) -> bool:


def _get_data_objects(
session, coll: irods.collection.iRODSCollection
session, coll: irods.collection.iRODSCollection,
depth: Optional[int] = None,
) -> list[tuple[str, str, int, str]]:
"""Retrieve all data objects in a collection and all its subcollections.
Expand All @@ -653,6 +655,8 @@ def _get_data_objects(
"""
# all objects in the collection
objs = [(obj.collection.path, obj.name, obj.size, obj.checksum) for obj in coll.data_objects]
if depth == 1:
return objs

# all objects in subcollections
data_query = session.irods_session.query(
Expand All @@ -666,8 +670,13 @@ def _get_data_objects(
return objs


def _get_subcoll_paths(session, coll: irods.collection.iRODSCollection) -> list:
def _get_subcoll_paths(session, coll: irods.collection.iRODSCollection,
depth: Optional[int] = None) -> list:
"""Retrieve all sub collections in a sub tree starting at coll and returns their IrodsPaths."""
if depth == 1:
return [CachedIrodsPath(session, None, False, None, subcol.path)
for subcol in coll.subcollections]

coll_query = session.irods_session.query(icat.COLL_NAME)
coll_query = coll_query.filter(icat.LIKE(icat.COLL_NAME, coll.path + "/%"))

Expand Down

0 comments on commit 1a43ba7

Please sign in to comment.