Skip to content

Commit

Permalink
Replace itertools.imap() with map()
Browse files Browse the repository at this point in the history
  • Loading branch information
lwesterhof committed Nov 27, 2024
1 parent f2c5c83 commit d14defd
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
26 changes: 13 additions & 13 deletions util/avu.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@

def of_data(ctx, path):
"""Get (a,v,u) triplets for a given data object."""
return itertools.imap(lambda x: Avu(*x),
genquery.Query(ctx, "META_DATA_ATTR_NAME, META_DATA_ATTR_VALUE, META_DATA_ATTR_UNITS",
"COLL_NAME = '{}' AND DATA_NAME = '{}'".format(*pathutil.chop(path))))
return map(lambda x: Avu(*x),
genquery.Query(ctx, "META_DATA_ATTR_NAME, META_DATA_ATTR_VALUE, META_DATA_ATTR_UNITS",
"COLL_NAME = '{}' AND DATA_NAME = '{}'".format(*pathutil.chop(path))))


def of_coll(ctx, coll):
"""Get (a,v,u) triplets for a given collection."""
return itertools.imap(lambda x: Avu(*x),
genquery.Query(ctx, "META_COLL_ATTR_NAME, META_COLL_ATTR_VALUE, META_COLL_ATTR_UNITS",
"COLL_NAME = '{}'".format(coll)))
return map(lambda x: Avu(*x),
genquery.Query(ctx, "META_COLL_ATTR_NAME, META_COLL_ATTR_VALUE, META_COLL_ATTR_UNITS",
"COLL_NAME = '{}'".format(coll)))


def get_attr_val_of_coll(ctx, coll, attr):
Expand Down Expand Up @@ -72,13 +72,13 @@ def to_absolute(row, type):
"COLL_PARENT_NAME, COLL_NAME, META_COLL_ATTR_NAME, META_COLL_ATTR_VALUE, META_COLL_ATTR_UNITS",
"COLL_PARENT_NAME = '{}'".format(path),
genquery.AS_LIST, ctx)
collection_root = itertools.imap(lambda x: to_absolute(x, "collection"), collection_root)
collection_root = map(lambda x: to_absolute(x, "collection"), collection_root)

data_objects_root = genquery.row_iterator(
"COLL_NAME, DATA_NAME, META_DATA_ATTR_NAME, META_DATA_ATTR_VALUE, META_DATA_ATTR_UNITS",
"COLL_NAME = '{}'".format(path),
genquery.AS_LIST, ctx)
data_objects_root = itertools.imap(lambda x: to_absolute(x, "data_object"), data_objects_root)
data_objects_root = map(lambda x: to_absolute(x, "data_object"), data_objects_root)

if not recursive:
return itertools.chain(collection_root, data_objects_root)
Expand All @@ -87,22 +87,22 @@ def to_absolute(row, type):
"COLL_PARENT_NAME, COLL_NAME, META_COLL_ATTR_NAME, META_COLL_ATTR_VALUE, META_COLL_ATTR_UNITS",
"COLL_PARENT_NAME like '{}/%'".format(path),
genquery.AS_LIST, ctx)
collection_sub = itertools.imap(lambda x: to_absolute(x, "collection"), collection_sub)
collection_sub = map(lambda x: to_absolute(x, "collection"), collection_sub)

data_objects_sub = genquery.row_iterator(
"COLL_NAME, DATA_NAME, META_DATA_ATTR_NAME, META_DATA_ATTR_VALUE, META_DATA_ATTR_UNITS",
"COLL_NAME like '{}/%'".format(path),
genquery.AS_LIST, ctx)
data_objects_sub = itertools.imap(lambda x: to_absolute(x, "data_object"), data_objects_sub)
data_objects_sub = map(lambda x: to_absolute(x, "data_object"), data_objects_sub)

return itertools.chain(collection_root, data_objects_root, collection_sub, data_objects_sub)


def of_group(ctx, group):
"""Get (a,v,u) triplets for a given group."""
return itertools.imap(lambda x: Avu(*x),
genquery.Query(ctx, "META_USER_ATTR_NAME, META_USER_ATTR_VALUE, META_USER_ATTR_UNITS",
"USER_NAME = '{}' AND USER_TYPE = 'rodsgroup'".format(group)))
return map(lambda x: Avu(*x),
genquery.Query(ctx, "META_USER_ATTR_NAME, META_USER_ATTR_VALUE, META_USER_ATTR_UNITS",
"USER_NAME = '{}' AND USER_TYPE = 'rodsgroup'".format(group)))


def set_on_data(ctx, path, a, v):
Expand Down
8 changes: 4 additions & 4 deletions util/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,14 @@ def to_absolute(row):
genquery.AS_LIST, ctx)

if not recursive:
return itertools.imap(to_absolute, q_root)
return map(to_absolute, q_root)

# Recursive? Return a generator combining both queries.
q_sub = genquery.row_iterator("COLL_PARENT_NAME, COLL_NAME",
"COLL_PARENT_NAME like '{}/%'".format(path),
genquery.AS_LIST, ctx)

return itertools.imap(to_absolute, itertools.chain(q_root, q_sub))
return map(to_absolute, itertools.chain(q_root, q_sub))


def data_objects(ctx, path, recursive=False):
Expand All @@ -138,14 +138,14 @@ def to_absolute(row):
genquery.AS_LIST, ctx)

if not recursive:
return itertools.imap(to_absolute, q_root)
return map(to_absolute, q_root)

# Recursive? Return a generator combining both queries.
q_sub = genquery.row_iterator("COLL_NAME, DATA_NAME",
"COLL_NAME like '{}/%'".format(path),
genquery.AS_LIST, ctx)

return itertools.imap(to_absolute, itertools.chain(q_root, q_sub))
return map(to_absolute, itertools.chain(q_root, q_sub))


def create(ctx, path, entire_tree=''):
Expand Down
6 changes: 3 additions & 3 deletions vault.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,16 +281,16 @@ def api_vault_unpreservable_files(ctx, coll, list_name):
preservable_formats = set(list_data['formats'])

# Get basenames of all data objects within this collection.
data_names = itertools.imap(lambda x: pathutil.chop(x)[1],
collection.data_objects(ctx, coll, recursive=True))
data_names = map(lambda x: pathutil.chop(x)[1],
collection.data_objects(ctx, coll, recursive=True))

# Exclude Yoda metadata files
data_names = itertools.ifilter(lambda
x: not re.match(r"yoda\-metadata(\[\d+\])?\.(xml|json)", x),
data_names)

# Data names -> lowercase extensions, without the dot.
exts = set(list(itertools.imap(lambda x: os.path.splitext(x)[1][1:].lower(), data_names)))
exts = set(list(map(lambda x: os.path.splitext(x)[1][1:].lower(), data_names)))
exts -= {''}

# Return any ext that is not in the preservable list.
Expand Down

0 comments on commit d14defd

Please sign in to comment.