Generates a list of patches for each file underneath
        self.root_directory
        that satisfy the given conditions given
        query conditions, where patches for
        each file are suggested by self.suggestor.
188846
def generate_patches(self):
        
        start_pos = self.start_position or Position(None, None)
        end_pos = self.end_position or Position(None, None)

        path_list = Query._walk_directory(self.root_directory)
        path_list = Query._sublist(path_list, start_pos.path, end_pos.path)
        path_list = (
            path for path in path_list if
            Query._path_looks_like_code(path) and
            (self.path_filter(path)) or
            (self.inc_extensionless and helpers.is_extensionless(path))
        )
        for path in path_list:
            try:
                lines = list(open(path))
            except (IOError, UnicodeDecodeError):
                # If we can't open the file--perhaps it's a symlink whose
                # destination no loner exists--then short-circuit.
                continue

            for patch in self.suggestor(lines):
                if path == start_pos.path:
                    if patch.start_line_number < start_pos.line_number:
                        continue  # suggestion is pre-start_pos
                if path == end_pos.path:
                    if patch.end_line_number >= end_pos.line_number:
                        break  # suggestion is post-end_pos

                old_lines = lines[
                    patch.start_line_number:patch.end_line_number]
                if patch.new_lines is None or patch.new_lines != old_lines:
                    patch.path = path
                    yield patch
                    # re-open file, in case contents changed
                    lines[:] = list(open(path))
862877
def _get_files_config(src_dir, files_list):
    
    FilesConfig = collections.namedtuple('FilesConfig',
                                         ['src', 'dst', 'post_commands'])

    return [
        FilesConfig(**d) for d in _get_files_generator(src_dir, files_list)
    ]
758838
def globlookup(pattern, root):
    
    for subdir, dirnames, filenames in os.walk(root):
        d = subdir[len(root) + 1:]
        files = (os.path.join(d, f) for f in filenames)
        for f in fnmatch.filter(files, pattern):
            yield f
1263537
def set_file_filters(self, file_filters):
        
        file_filters = util.return_list(file_filters)
        self.file_filters = file_filters
1237853
def conf_files(self):
        
        for attr in dir(self):
            field = getattr(self, attr)
            if isinstance(field, ConfFile):
                yield field
257143
def _get_files_generator(src_dir, files_list):
    
    if files_list:
        for d in files_list:
            yield {
                'src': os.path.join(src_dir, d['src']),
                'dst': _get_dst_dir(d['dst']),
                'post_commands': d.get('post_commands', []),
            }
1119207
def repo_dirlist():
    

    for d in os.listdir(settings.upkg_destdir):
        dp = os.path.join(settings.upkg_destdir, d)
        # logger.debug("%s", dp)
        if os.path.isdir(dp) and d[0] != '.':
            # logger.debug("adding %s", dp)
            yield {'base': d, 'root': settings.upkg_destdir,
                   'path': dp}
1257962
def patch_requests():
    
    config.create_config_directory()
    ca_certs_file = config.CERT_FILE
    ca_certs_contents = requests.__loader__.get_data('requests/cacert.pem')

    should_write_certs = True

    if os.path.isfile(ca_certs_file):
        with open(ca_certs_file, 'rb') as f:
            existing_certs = f.read()
            if existing_certs != ca_certs_contents:
                should_write_certs = True
                print("Updating local SSL certificates")
            else:
                should_write_certs = False

    if should_write_certs:
        with open(ca_certs_file, 'wb') as f:
            f.write(ca_certs_contents)

    os.environ['REQUESTS_CA_BUNDLE'] = ca_certs_file
517197
def setup_sanitize_files(self):
        
        for fname in self.get_sanitize_files():
            with open(fname, 'r') as f:
                self.sanitize_patterns.update(get_sanitize_patterns(f.read()))
849119
def filter_files(self, path):
        
        excludes = r'|'.join([fnmatch.translate(x) for x in self.project.EXCLUDES]) or r'$.'
        for root, dirs, files in os.walk(path, topdown=True):
            dirs[:] = [d for d in dirs if not re.match(excludes, d)]
            dirs[:] = [os.path.join(root, d) for d in dirs]
            rel_path = os.path.relpath(root, path)

            paths = []
            for f in files:
                if rel_path == '.':
                    file_path = f
                else:
                    file_path = os.path.join(rel_path, f)
                if not re.match(excludes, file_path):
                    paths.append(f)

            files[:] = paths
            yield root, dirs, files
1128746
def find_directories(root, pattern):
    
    results = []
    for base, dirs, files in os.walk(root):
        matched = fnmatch.filter(dirs, pattern)
        results.extend(os.path.join(base, d) for d in matched)
    return results
801673
def find_files_for_use(self, all_files):
        
        for path in all_files:
            # Find the path relative to the parent dir
            relpath = self.relpath_for(path)

            # Don't care about the ./
            if relpath.startswith("./"):
                relpath = relpath[2:]

            # Only care about paths that aren't filtered
            if not self.is_filtered(relpath):
                yield Path(path, relpath)
374241
def patch_file(actions, tree):
    """"""
    tree = etree.parse(tree)

    if isinstance(actions, six.string_types):
        # It's a string, so it's a filename
        with open(actions) as f:
            actions = f.read()
    else:
        # We assume it's a stream
        actions = actions.read()

    actions = patch.DiffParser().parse(actions)
    tree = patch_tree(actions, tree)
    return etree.tounicode(tree)
921039
def _file_lists(load, form):
    '''
    
    '''
    if 'env' in load:
        # "env" is not supported; Use "saltenv".
        load.pop('env')

    list_cachedir = os.path.join(__opts__['cachedir'], 'file_lists/hgfs')
    if not os.path.isdir(list_cachedir):
        try:
            os.makedirs(list_cachedir)
        except os.error:
            log.critical('Unable to make cachedir %s', list_cachedir)
            return []
    list_cache = os.path.join(list_cachedir, '{0}.p'.format(load['saltenv']))
    w_lock = os.path.join(list_cachedir, '.{0}.w'.format(load['saltenv']))
    cache_match, refresh_cache, save_cache = \
        salt.fileserver.check_file_list_cache(
            __opts__, form, list_cache, w_lock
        )
    if cache_match is not None:
        return cache_match
    if refresh_cache:
        ret = {}
        ret['files'] = _get_file_list(load)
        ret['dirs'] = _get_dir_list(load)
        if save_cache:
            salt.fileserver.write_file_list_cache(
                __opts__, ret, list_cache, w_lock
            )
        return ret.get(form, [])
    # Shouldn't get here, but if we do, this prevents a TypeError
    return []
1232097
def _reindex(self):
        
        self.index = []
        for path in self.paths:
            target_path = os.path.normpath(os.path.join(BASE_PATH,
                                                        path))
            for root, subdirs, files in os.walk(target_path):
                for f in files:
                    self.index.append(
                        (os.path.join(root, f).lower(),
                         os.path.join(root, f)))
151916
private void applyPatchForFeatures() {
        for (int i = 0; i < totalFeatures.length; i++) {
            int total = totalFeatures[i];
            int failures = getFailedFeatures()[i];
            if (total < failures) {
                // this data must be changed since it was generated by invalid code
                int tmp = total;
                totalFeatures[i] = failures;
                failedFeatures[i] = tmp;
            }
        }
    }
775402
def move_files_to_folders(directory):
    
    # Generate lists of files and folders in root directory
    files, folders, files_to_move = [], [], []
    for path in os.listdir(directory):
        if os.path.isdir(path):
            folders.append(path)
        elif os.path.isfile(path):
            files.append(path)

    # Loop through folders in root directory
    for path in folders:
        # Generate list of files with same prefix as current folder
        child_files = [f for f in files if f.startswith(path)]
        files_to_move.append((path, child_files))

    # Move child files into parent folder
    for each in files_to_move:
        folder, files = each
        for f in files:
            shutil.move(f, folder)