def recursive_generator(conn, credentials, path, prefix='', pretty=True): 'A generator function for the `ls` function when used recursively.' maxsize = 10**7 # 10 million files should be sufficient try: parent = fs.read_directory(conn, credentials, maxsize, path, None)[0] # An exception is raised if that is not a directory! pretty_path = parent['path'] if prefix != '' and pretty: pretty_path = prefix + name_only(pretty_path) yield bold(pretty_path) if parent['child_count'] > 0: prefix += ' ' for child in parent['files']: child_path = child['path'] if child['type'] == 'FS_FILE_TYPE_DIRECTORY': for i in recursive_generator(conn, credentials, child_path, prefix, pretty): yield i else: if pretty: child_path = prefix + name_only(child_path) yield child_path except request.RequestError: yield red('Unable to access {0}'.format(bold(path)))
def listing_generator(conn, credentials, path, pretty=True): 'A generator function for the `ls` function' maxsize = 10**7 # 10 million files should be sufficient parent = fs.read_directory(conn, credentials, maxsize, path, None)[0] # An exception is raised if that is not a directory! yield bold(parent['path']) if parent['child_count'] > 0: for child in parent['files']: child_path = child['path'] if pretty: child_path = ' ' + name_only(parent['path'], child_path) yield child_path
def main(conninfo, credentials, args): if args.id and args.path: raise ValueError("--path conflicts with --id") elif not args.id and not args.path: raise ValueError("Must specify --path or --id") elif args.page_size is not None and args.page_size < 1: raise ValueError("Page size must be greater than 0") page = fs.read_directory(conninfo, credentials, args.page_size, args.path, args.id) print page next_uri = json.loads(str(page))["paging"]["next"] while next_uri != "": page = request.rest_request(conninfo, credentials, "GET", next_uri) print page next_uri = json.loads(str(page))["paging"]["next"]