Esempio n. 1
0
def listdir(directory_path,
            system_id=DEFAULT_SYSTEM_ID,
            root_dir='/',
            directories=True,
            dotfiles=False,
            page_size=DEFAULT_PAGE_SIZE,
            sort=True,
            agave=None,
            **kwargs):
    """Lists immediate contents of a Tapis files directory.

    Arguments:
        directory_path (str): Full or relative path of directory to walk
        system_id (str, optional): Tapis storageSystem for directory_path
        root_dir (str, optional): Base path if directory_path is relative
        directories (bool, optional): Whether result should include directories
        dotfiles (bool, optional): Whether result should include dotfiles
        agave (Agave, optional): Tapis (Agave) API client

    Returns:
        list: List of paths relative to directory_path

    Raises:
        TapisOperationFailed: Some error prevented the action from completing
    """
    logger.info('listdir: agave://{}{}'.format(system_id, directory_path))
    start_time = nanoseconds()

    resp = _walk(directory_path,
                 system_id=system_id,
                 root_dir=root_dir,
                 directories=directories,
                 dotfiles=dotfiles,
                 page_size=page_size,
                 recurse=False,
                 agave=agave)

    # filter dirname from paths to emulate os.listdir()
    if not directory_path.endswith('/'):
        directory_path_filter = directory_path + '/'
    else:
        directory_path_filter = directory_path

    listing = []
    for r in resp:
        r[PATH_KEY] = r[PATH_KEY].replace(directory_path_filter, '')
        listing.append(r)

    end_time = nanoseconds()
    elapsed = int((end_time - start_time) / 1000 / 1000)
    logger.debug('listdir: found {} elements in {} msec'.format(
        len(listing), elapsed))

    return listing
Esempio n. 2
0
def walk(directory_path,
         system_id=DEFAULT_SYSTEM_ID,
         root_dir='/',
         directories=False,
         dotfiles=False,
         sort=False,
         page_size=DEFAULT_PAGE_SIZE,
         agave=None,
         **kwargs):
    """Recursively lists contents of a Tapis files directory.

    Arguments:
        directory_path (str): Full or relative path of directory to walk
        system_id (str, optional): Tapis storageSystem for directory_path
        root_dir (str, optional): Base path if directory_path is relative
        directories (bool, optional): Whether result should include directories
        dotfiles (bool, optional): Whether result should include dotfiles
        page_size (int, optional): Override default Tapis files-list page size
        agave (Agave, optional): Tapis (Agave) API client

    Returns:
        list: List of Tapis-canonical absolute paths as AnnotatedFile objects

    Raises:
       TapisOperationFailed: An exception or error happened
    """
    logger.info('walk: agave://{}{}'.format(system_id, directory_path))
    start_time = nanoseconds()

    listing = _walk(directory_path,
                    system_id=system_id,
                    root_dir=root_dir,
                    directories=directories,
                    dotfiles=dotfiles,
                    page_size=page_size,
                    agave=agave)

    if sort:
        listing.sort()

    end_time = nanoseconds()
    elapsed = int((end_time - start_time) / 1000 / 1000)
    logger.debug('walk: found {} elements in {} msec'.format(
        len(listing), elapsed))

    return listing
Esempio n. 3
0
def _local_temp_filename(src_filename, dest_filename=None, atomic=False):
    """Compute local and temp-local filenames, allowing for atomic writes
    """
    file_name = dest_filename
    if file_name is None:
        file_name = os.path.basename(src_filename)
    if atomic:
        temp_file_name = '{0}-{1}'.format(file_name, nanoseconds())
    else:
        temp_file_name = file_name
    return file_name, temp_file_name