Same as +sub+ except that the original file list is modified.
544975
def sub!(pat, rep)
      each_with_index { |fn, i| self[i] = fn.sub(pat, rep) }
      self
    end
429266
def sub_files(path, invisible=False):
    
    files = [x for x in os.listdir(path) if os.path.isfile(os.path.join(path, x))]
    if not invisible:
        files = [x for x in files if not x.startswith('.')]

    return files
490029
def _copy_replace(src, dst, replacements):
    """"""
    with src.open() as infile, dst.open('w') as outfile:
        outfile.write(re.sub(
            '|'.join(re.escape(k) for k in replacements),
            lambda m: str(replacements[m.group(0)]),
            infile.read()
        ))
95969
def tamper_file_at(path, pos=0, replace_str=None):
    
    if not replace_str:
        replace_str = "\x00"
    try:
        with open(path, "r+b") as fh:
            if pos < 0: # if negative, we calculate the position backward from the end of file
                fsize = os.fstat(fh.fileno()).st_size
                pos = fsize + pos
            fh.seek(pos)
            fh.write(replace_str)
    except IOError:
        return False
    finally:
        try:
            fh.close()
        except Exception:
            pass
    return True
166488
def *(other)
      result = @items * other
      case result
      when Array
        FileList.new.import(result)
      else
        result
      end
    end
1129896
def merge_modified_section_data(self):
        """"""
        
        for section in self.sections:
            section_data_start = adjust_FileAlignment( section.PointerToRawData,
                self.OPTIONAL_HEADER.FileAlignment )
            section_data_end = section_data_start+section.SizeOfRawData
            if section_data_start < len(self.__data__) and section_data_end < len(self.__data__):
                self.__data__ = self.__data__[:section_data_start] + section.get_data() + self.__data__[section_data_end:]
551160
def _merge_extra_filerefs(*args):
    '''
    
    '''
    ret = []
    for arg in args:
        if isinstance(arg, six.string_types):
            if arg:
                ret.extend(arg.split(','))
        elif isinstance(arg, list):
            if arg:
                ret.extend(arg)
    return ','.join(ret)
868943
def replace(self, infile):
        '''
        '''
        gf = infile[31:]
        same_size_index = []
        while len(same_size_index) <= 1:
            index = random.randint(0,len(gf)-1)
            index_len = len(gf[index])
            same_size_index = [i for (i,g) in enumerate(gf) if len(g) == index_len]
        else:
            same_size_index = random.choice(same_size_index[:])
        gf[index], gf[same_size_index] = gf[same_size_index], gf[index]
        return infile[:31] + gf
183829
def _dedup(items, insensitive):
    '''
    
    '''
    deduped = []
    if insensitive:
        i_deduped = []
        for item in items:
            lowered = item.lower()
            if lowered not in i_deduped:
                deduped.append(item)
                i_deduped.append(lowered)
    else:
        for item in items:
            if item not in deduped:
                deduped.append(item)
    return deduped
606191
def changes(self):
        """"""
        deleted = []
        for path in list(self.files):
            isdir = path.endswith(os.sep)
            abspath = os.path.join(self.path, path)
            try:
                is_deleted = (
                    not os.path.exists(abspath) or  # actually deleted
                    os.path.isdir(abspath) != isdir  # changed from / to folder
                )
            except EnvironmentError:
                # file is basically inaccessible at this point so we're gonna
                # assume that it was deleted
                is_deleted = True

            if is_deleted:
                deleted.append(path)
                del self.files[path]

        changed = []
        for folder, subfolders, subfiles in os.walk(self.path):
            for path in subfolders:
                path = os.path.join(folder, path)
                path = os.path.normcase(os.path.relpath(path, self.path))
                path += os.sep
                if path not in self.files:
                    # don't really care about folder mtime
                    self.files[path] = 0
                    changed.append(path)

            for path in subfiles:
                actual_path = path = os.path.join(folder, path)
                path = os.path.normcase(os.path.relpath(path, self.path))
                try:
                    mtime = os.path.getmtime(actual_path)
                    if path not in self.files:
                        # new file; set its mtime to 0 because it will be
                        # compared in the next few lines
                        self.files[path] = 0

                    if mtime > self.files[path]:
                        # file has been changed since last check
                        self.files[path] = mtime
                        changed.append(path)
                except EnvironmentError:
                    # in 99% of the cases the file has been deleted while
                    # iterating the parent folder; if the file was previously
                    # being handled, then stop handling it; otherwise ignore
                    if path in self.files:
                        deleted.append(path)
                        del self.files[path]

        self.updated = False
        return changed, deleted
675824
def print_modified_files(opts, anchors):
    
    print("Files with modifications:")
    for file_path in anchors:
        print("  " + strip_prefix(file_path, opts.abs_input))
    print("--------------------")
    print(str(len(anchors)) + " total\n")
112368
private int dedup(Tag[] src, int ss, Tag[] dst, int ds, int len) {
    if (len == 0) {
      return ds;
    } else {
      dst[ds] = src[ss];
      String k = src[ss].key();
      int j = ds;
      final int e = ss + len;
      for (int i = ss + 1; i < e; ++i) {
        if (k.equals(src[i].key())) {
          dst[j] = src[i];
        } else {
          k = src[i].key();
          dst[++j] = src[i];
        }
      }
      return j + 1;
    }
  }
368764
def _flatten_file_with_secondary(input, out_dir):
    
    out = []
    orig_dir = os.path.dirname(input["base"])
    for finfo in [input["base"]] + input.get("secondary", []):
        cur_dir = os.path.dirname(finfo)
        if cur_dir != orig_dir and cur_dir.startswith(orig_dir):
            cur_out_dir = os.path.join(out_dir, cur_dir.replace(orig_dir + "/", ""))
        else:
            cur_out_dir = out_dir
        out.append({"path": finfo, "dir": cur_out_dir})
    return out
806274
def _check_stems(files):
    """"""
    used = set()
    for fn in files:
        if os.path.basename(fn) in used:
            logger.warning("%s stem is multiple times in your file list, "
                         "so we don't know "
                         "how to assign it to the sample data in the CSV. "
                         "We are gonna use full path to make a difference, "
                         "that means paired files should be in the same folder. "
                         "If this is a problem, you should rename the files you want "
                         "to merge. Sorry, no possible magic here." % os.path.basename(fn)
                         )
            return True
        used.add(os.path.basename(fn))
    return False
991305
private void recomputeLoadSums() {
        loadsHaveChanged.set(false);
        for (int d = 0; d < nbDims; d++) {
            int sli = 0;
            int sls = 0;
            for (int b = 0; b < nbBins; b++) {
                sli += loads[d][b].getLB();
                sls += loads[d][b].getUB();
            }
            this.sumLoadInf[d].set(sli);
            this.sumLoadSup[d].set(sls);
        }
    }
1354617
def replace_in_files(dirname, replace):
    """"""
    filepath = os.path.abspath(dirname / "requirements.in")
    if os.path.isfile(filepath) and header_footer_exists(filepath):
        replaced = re.sub(Utils.exp, replace, get_file_string(filepath))
        with open(filepath, "w") as f:
            f.write(replaced)
        print(color(
            "Written to file: {}".format(filepath),
            fg='magenta', style='bold'))
590143
def action
      updated_list_filename = File.join(Configuration::application_root, 'upgrade_package_add_files.txt')
      removed_list_filename = File.join(Configuration::application_root, 'upgrade_package_remove_files.txt')
      mkdir_p Configuration::development_directory
      Configuration::enabled_subscriber_platforms.each { |each|
        RhoDevelopment.setup(Configuration::development_directory, each)
        puts "Check changes for #{each}".warning
        changed = RhoDevelopment.check_changes_from_last_build(updated_list_filename, removed_list_filename)
        if changed
          puts "Source code for platform #{each} was changed".primary
          WebServer.dispatch_task(PlatformPartialUpdateBuildingTask.new(each, @filename));
          Configuration::enabled_subscribers_by_platform(each).each { |subscriber|
            WebServer.dispatch_task(SubscriberPartialUpdateNotifyingTask.new(subscriber, @filename));
          }
        else
          puts "Source code for platform #{each} wasn't changed".primary
        end
      }
    end