find_work_path()#

find_work_path(t, username)

This function can take a while and may not be necessary

This function searches for and returns the absolute work directory path for a given user inside the Tapis cloud.data system, which typically represents shared Work storage on DesignSafe.

Because the Work system is organized by group IDs, and these group folders may be nested under /work with many thousands of entries, it’s not possible to directly compute the user’s path.

Instead, this function iterates through batches of directories under /work, looks inside each group folder, and checks if it contains a subfolder named after the specified username. When it finds the match, it returns the Tapis file object containing the user’s workPath.


How it works, step by step#

  1. Loops through offset pages in chunks of 1000 to handle systems with large numbers of group directories (e.g. /work/05072, /work/01234, etc).

  2. For each group directory found under /work:

    • Lists its subfolders.

    • Checks if one of these subfolders matches the username.

  3. If it finds a folder named exactly like username, it:

    • Prints the path,

    • Returns the hereQ file object (from which you can get .path and other metadata).

  4. If it exhausts the offsets or directories, it exits.


Why this is useful#

On DesignSafe’s Tapis-backed cloud.data (the Work system), your actual path might look like:

/work/05072/jdoe

but the 05072 is a project or allocation group, which your script does not necessarily know ahead of time. This function automatically locates your specific work directory, regardless of which group or allocation ID it is under.


Example usage#

work_file_object = find_work_path(t, username='smazzoni')
print('Work path:', work_file_object.path)

This lets you build your scripts without hard-coding your group ID.

Files#

You can find these files in Community Data.

find_work_path.py
def find_work_path(t, username):
    """
    Locate the full work directory path for a user in the Tapis 'cloud.data' system.

    On DesignSafe (and similar Tapis platforms), the 'Work' storage system is organized
    by allocation or project group directories under '/work', with user directories 
    nested inside (e.g., /work/05072/smazzoni). This function searches through these
    nested folders to find the user's specific work path.

    It does this by paging through batches of group directories, then checking inside
    each one for a folder matching the given username.

    Parameters
    ----------
    t : Tapis
        An authenticated Tapis client (from connect_tapis()).

    username : str
        The Tapis username to search for under the '/work' hierarchy.

    Returns
    -------
    FileListing
        The Tapis file object corresponding to the user's work directory,
        from which you can access .path and other metadata.

    Example
    -------
    work_file_object = find_work_path(t, username='smazzoni')
    print('Work path:', work_file_object.path)
    """
    # code by Silvia Mazzoni, 2025
    from tapipy.tapis import Tapis
    Offmax = 30
    foundit = False
    for i in range(1,Offmax):
        offset = i*1000
        # print('offset',offset)
        allWorkBase = t.files.listFiles(systemId='cloud.data', path='/work',offset=offset)
        icnt = 0
        for thisQ in allWorkBase:
            icnt+=1
            newName = thisQ.name
            hereWorkBase = t.files.listFiles(systemId='cloud.data', path=f'/work/{newName}')
            for hereQ in hereWorkBase:
                if hereQ.name==username:
                    foundit = True
                    workPath = hereQ.path
                    returnQ = hereQ
                    print('Found it!!!',workPath)
                    # print(returnQ)
                    break
        if icnt ==0 or foundit:
            break
        print(f'searched {offset+icnt} folders')
    return returnQ