labpack/platforms/localhost.py
def walk(self, walk_root='', reverse_order=False, previous_file=''):

        ''' a generator method of file paths on localhost from walk of directories

        :param walk_root: string with path from which to root walk of localhost directories
        :param reverse_order: boolean to determine alphabetical direction of walk
        :param previous_file: string with path of file after which to start walk
        :return: string with absolute path to file
        '''

        __name__ = '%s.walk(...)' % self.__class__.__name__

    # validate input
        input_kwargs = [walk_root, previous_file]
        input_names = ['.walk_root', '.previous_file']
        for i in range(len(input_kwargs)):
            if input_kwargs[i]:
                self.fields.validate(input_kwargs[i], input_names[i])

    # validate that previous file exists
        file_exists = False
        previous_found = False
        if previous_file:
            if os.path.exists(previous_file):
                if os.path.isfile(previous_file):
                    file_exists = True
                    previous_file = os.path.abspath(previous_file)
            if not file_exists:
                err_msg = __name__.replace('...', 'previous_file="%s"' % previous_file)
                raise ValueError('%s must be a valid file.' % err_msg)

    # construct empty result
        file_path = ''

    # determine root for walk
        if walk_root:
            if not os.path.isdir(walk_root):
                err_msg = __name__.replace('...', 'walk_root="%s"' % walk_root)
                raise ValueError('%s msut be a valid directory.' % err_msg)
        else:
            walk_root = './'

    # walk directory structure to find files
        for current_dir, sub_dirs, dir_files in os.walk(walk_root):
            dir_files.sort()
            sub_dirs.sort()
            if reverse_order:
                sub_dirs.reverse()
                dir_files.reverse()
            if previous_file and not previous_found:
                key_path = previous_file.split(os.sep)
                current_path = os.path.abspath(current_dir)
                for i in range(len(current_path.split(os.sep))):
                    del key_path[0]
                if key_path:
                    if key_path[0] in sub_dirs:
                        path_index = sub_dirs.index(key_path[0])
                        sub_dirs[0:path_index] = []
                        dir_files = []
                    elif key_path[0] in dir_files:
                        file_index = dir_files.index(key_path[0]) + 1
                        dir_files[0:file_index] = []
                        previous_found = True

    # yield file path
            for file in dir_files:
                file_path = os.path.join(os.path.abspath(current_dir), file)
                yield file_path
 a generator method of file paths on localhost from walk of directories

        :param walk_root: string with path from which to root walk of localhost directories
        :param reverse_order: boolean to determine alphabetical direction of walk
        :param previous_file: string with path of file after which to start walk
        :return: string with absolute path to file
        
a generator method of file paths on localhost from walk of directories
a generator method of file paths on localhost from walk of directories
def walk(self, walk_root='', reverse_order=False, previous_file=''):
        __name__ = '%s.walk(...)' % self.__class__.__name__
        input_kwargs = [walk_root, previous_file]
        input_names = ['.walk_root', '.previous_file']
        for i in range(len(input_kwargs)):
            if input_kwargs[i]:
                self.fields.validate(input_kwargs[i], input_names[i])
        file_exists = False
        previous_found = False
        if previous_file:
            if os.path.exists(previous_file):
                if os.path.isfile(previous_file):
                    file_exists = True
                    previous_file = os.path.abspath(previous_file)
            if not file_exists:
                err_msg = __name__.replace('...', 'previous_file="%s"' % previous_file)
                raise ValueError('%s must be a valid file.' % err_msg)
        file_path = ''
        if walk_root:
            if not os.path.isdir(walk_root):
                err_msg = __name__.replace('...', 'walk_root="%s"' % walk_root)
                raise ValueError('%s msut be a valid directory.' % err_msg)
        else:
            walk_root = './'
        for current_dir, sub_dirs, dir_files in os.walk(walk_root):
            dir_files.sort()
            sub_dirs.sort()
            if reverse_order:
                sub_dirs.reverse()
                dir_files.reverse()
            if previous_file and not previous_found:
                key_path = previous_file.split(os.sep)
                current_path = os.path.abspath(current_dir)
                for i in range(len(current_path.split(os.sep))):
                    del key_path[0]
                if key_path:
                    if key_path[0] in sub_dirs:
                        path_index = sub_dirs.index(key_path[0])
                        sub_dirs[0:path_index] = []
                        dir_files = []
                    elif key_path[0] in dir_files:
                        file_index = dir_files.index(key_path[0]) + 1
                        dir_files[0:file_index] = []
                        previous_found = True
            for file in dir_files:
                file_path = os.path.join(os.path.abspath(current_dir), file)
                yield file_path
def walk ( self , walk_root = '' , reverse_order = False , previous_file = '' ) : __name__ = '%s.walk(...)' % self . __class__ . __name__ input_kwargs = [ walk_root , previous_file ] input_names = [ '.walk_root' , '.previous_file' ] for i in range ( len ( input_kwargs ) ) : if input_kwargs [ i ] : self . fields . validate ( input_kwargs [ i ] , input_names [ i ] ) file_exists = False previous_found = False if previous_file : if os . path . exists ( previous_file ) : if os . path . isfile ( previous_file ) : file_exists = True previous_file = os . path . abspath ( previous_file ) if not file_exists : err_msg = __name__ . replace ( '...' , 'previous_file="%s"' % previous_file ) raise ValueError ( '%s must be a valid file.' % err_msg ) file_path = '' if walk_root : if not os . path . isdir ( walk_root ) : err_msg = __name__ . replace ( '...' , 'walk_root="%s"' % walk_root ) raise ValueError ( '%s msut be a valid directory.' % err_msg ) else : walk_root = './' for current_dir , sub_dirs , dir_files in os . walk ( walk_root ) : dir_files . sort ( ) sub_dirs . sort ( ) if reverse_order : sub_dirs . reverse ( ) dir_files . reverse ( ) if previous_file and not previous_found : key_path = previous_file . split ( os . sep ) current_path = os . path . abspath ( current_dir ) for i in range ( len ( current_path . split ( os . sep ) ) ) : del key_path [ 0 ] if key_path : if key_path [ 0 ] in sub_dirs : path_index = sub_dirs . index ( key_path [ 0 ] ) sub_dirs [ 0 : path_index ] = [ ] dir_files = [ ] elif key_path [ 0 ] in dir_files : file_index = dir_files . index ( key_path [ 0 ] ) + 1 dir_files [ 0 : file_index ] = [ ] previous_found = True for file in dir_files : file_path = os . path . join ( os . path . abspath ( current_dir ) , file ) yield file_path
a generator method of file paths on localhost from walk of directories
a generator method of file paths on localhost from walk of directories
''' a generator method of file paths on localhost from walk of directories

        :param walk_root: string with path from which to root walk of localhost directories
        :param reverse_order: boolean to determine alphabetical direction of walk
        :param previous_file: string with path of file after which to start walk
        :return: string with absolute path to file
        ''' # validate input # validate that previous file exists # construct empty result # determine root for walk # walk directory structure to find files # yield file path
string with absolute path to file
string with absolute path to file
self
walk_root
string with path from which to root walk of localhost directories
string with path from which to root walk of localhost directories
reverse_order
boolean to determine alphabetical direction of walk
boolean to determine alphabetical direction of walk
previous_file
string with path of file after which to start walk
string with path of file after which to start walk