Copy the old file to the location of the new file

    :param old: The file to copy
    :type old: :class:`JB_File`
    :param new: The JB_File for the new location
    :type new: :class:`JB_File`
    :returns: None
    :rtype: None
    :raises: None
186759
def copy_file(old, new):
    
    oldp = old.get_fullpath()
    newp = new.get_fullpath()
    log.info("Copying %s to %s", oldp, newp)
    new.create_directory()
    shutil.copy(oldp, newp)
131386
def move(self, filename, target):
        '''
        
        '''
        self.copy(filename, target)
        self.delete(filename)
1281244
def move(self, old_path, new_path, raise_if_exists=False):
        
        if raise_if_exists and os.path.exists(new_path):
            raise FileAlreadyExists('Destination exists: %s' % new_path)
        d = os.path.dirname(new_path)
        if d and not os.path.exists(d):
            self.mkdir(d)
        try:
            os.rename(old_path, new_path)
        except OSError as err:
            if err.errno == errno.EXDEV:
                new_path_tmp = '%s-%09d' % (new_path, random.randint(0, 999999999))
                shutil.copy(old_path, new_path_tmp)
                os.rename(new_path_tmp, new_path)
                os.remove(old_path)
            else:
                raise err
54802
def rename_file(old, new, path=None):
    
    cwd = os.getcwd()
    try:
        if path:
            os.chdir(path)
    except OSError:
        raise
    try:
        os.rename(old, new)
        os.chdir(cwd)
        return True
    except OSError:
        os.chdir(cwd)
        raise
1155802
def copyfile(self, target):
        
        shutil.copyfile(self.path, self._to_backend(target))
1187198
def write_file(self, new_text, filename, old_text, encoding=None):
        
        try:
            f = _open_with_encoding(filename, "w", encoding=encoding)
        except os.error as err:
            self.log_error("Can't create %s: %s", filename, err)
            return
        try:
            f.write(_to_system_newlines(new_text))
        except os.error as err:
            self.log_error("Can't write %s: %s", filename, err)
        finally:
            f.close()
        self.log_debug("Wrote changes to %s", filename)
        self.wrote = True
471393
def copy(self, new_fn):
        """"""
        new_file = self.__class__(fn=str(new_fn))
        new_file.write(data=self.read())
        new_file.utime(self.atime, self.mtime)
        return new_file
676548
def create_new(cls, oldvalue, *args):
    ""
    if oldvalue is not None:
        raise AlreadyExistsException('%r already exists' % (oldvalue,))
    return cls.create_instance(*args)
173853
def update(cls, zone_id, old_record, new_record):
        """"""
        cls.echo('Creating new zone file')
        new_version_id = Zone.new(zone_id)

        new_record = new_record.replace(' IN', '')
        new_record = new_record.split(' ', 4)
        params_newrecord = {'name': new_record[0], 'ttl': int(new_record[1]),
                            'type': new_record[2], 'value': new_record[3]}

        old_record = old_record.replace(' IN', '')
        old_record = old_record.split(' ', 4)
        try:
            params = {'name': old_record[0], 'ttl': int(old_record[1]),
                      'type': old_record[2], 'value': old_record[3]}
        except IndexError:
            # failed to retrieve all values, try only use the name
            params = {'name': old_record[0]}
        record = cls.call('domain.zone.record.list', zone_id, new_version_id,
                          params)

        if record:
            cls.echo('Updating zone records')
            try:
                cls.call('domain.zone.record.update', zone_id,
                         new_version_id, {'id': record[0]['id']},
                         params_newrecord)
                cls.echo('Activation of new zone version')
                Zone.set(zone_id, new_version_id)
                return new_version_id
            except Exception as err:
                cls.echo('An error as occured: %s' % err)
                Zone.delete(zone_id, new_version_id)
        else:
            cls.echo('The record to update does not exist. Check records'
                     ' already created with `gandi record list example.com'
                     ' --output`')
            return False
1362519
function filesPatch(oldFile, newFile, options) {
  let { diff, toFile } = utils;
  let opts = options || {};

  oldFile = toFile(oldFile, options);
  newFile = toFile(newFile, options);

  let nameA = oldFile.relative;
  let nameB = newFile.relative;

  let strA = oldFile.contents.toString();
  let strB = newFile.contents.toString();

  return diff.createTwoFilesPatch(nameA, nameB, strA, strB, opts.oldHeader, opts.newHeader, opts);
}
184555
def copy_file(self, dest_folder_id, source_file_id, on_duplicate=None):
        
        path = {}
        data = {}
        params = {}

        # REQUIRED - PATH - dest_folder_id
        """ID"""
        path["dest_folder_id"] = dest_folder_id

        # REQUIRED - source_file_id
        """The id of the source file"""
        data["source_file_id"] = source_file_id

        # OPTIONAL - on_duplicate
        """What to do if a file with the same name already exists at the destination.
        If such a file exists and this parameter is not given, the call will fail.
        
        "overwrite":: Replace an existing file with the same name
        "rename":: Add a qualifier to make the new filename unique"""
        if on_duplicate is not None:
            self._validate_enum(on_duplicate, ["overwrite", "rename"])
            data["on_duplicate"] = on_duplicate

        self.logger.debug("POST /api/v1/folders/{dest_folder_id}/copy_file with query params: {params} and form data: {data}".format(params=params, data=data, **path))
        return self.generic_request("POST", "/api/v1/folders/{dest_folder_id}/copy_file".format(**path), data=data, params=params, single_item=True)
481799
def copy_object(self, obj, new_container, new_obj_name=None,
            content_type=None):
        
        return self.manager.copy_object(self, obj, new_container,
                new_obj_name=new_obj_name, content_type=content_type)
302780
def update(oldrev=nil, newrev=nil)
      if index_file_exists? && oldrev != "0"*40
        hg([
            "log --debug -r ?:? --style ? >> ?",
            oldrev, newrev, Style.file_index, path
          ])
      else
        hg(["log --debug -r : --style ? > ?", Style.file_index, path])
      end
    end
53113
def new_file(self, path: str, checksum: str=None, to_archive: bool=False,
                 tags: List[models.Tag]=None) -> models.File:
        """"""
        new_file = self.File(path=path, checksum=checksum, to_archive=to_archive, tags=tags)
        return new_file
502692
def _migrate_ledger(data_directory,
                    old_ledger_file, new_ledger_file,
                    serializer: MappingSerializer = None):
    

    # we should have ChunkedFileStorage implementation of the Ledger
    if not os.path.isdir(os.path.join(data_directory, old_ledger_file)):
        msg = 'Could not find directory {} for migration.'.format(
            old_ledger_file)
        logger.error(msg)
        raise Exception(msg)

    # open the old ledger using the specified serializer
    old_ledger_file_backup = old_ledger_file + "_new"
    old_txn_log_store = ChunkedFileStore(data_directory,
                                         old_ledger_file_backup,
                                         isLineNoKey=True,
                                         storeContentHash=False)
    old_ledger = Ledger(CompactMerkleTree(),
                        dataDir=data_directory,
                        txn_serializer=serializer,
                        hash_serializer=serializer,
                        fileName=old_ledger_file_backup,
                        transactionLogStore=old_txn_log_store)

    # open the new ledger with new serialization
    new_ledger = Ledger(CompactMerkleTree(),
                        dataDir=data_directory,
                        fileName=new_ledger_file)
    logger.info("new size for {}: {}".format(
        old_ledger_file_backup, str(new_ledger.size)))

    # add all txns into the old ledger
    for _, txn in new_ledger.getAllTxn():
        old_ledger.add(txn)
    logger.info("old size for {}: {}".format(
        new_ledger_file, str(old_ledger.size)))

    old_ledger.stop()
    new_ledger.stop()

    # now that everything succeeded, remove the new files and move the old
    # files into place
    shutil.rmtree(
        os.path.join(data_directory, new_ledger_file))
    os.rename(
        os.path.join(data_directory, old_ledger_file_backup),
        os.path.join(data_directory, old_ledger_file))
1347664
def replace(old, new):
    
    parent = old.getparent()
    parent.replace(old, new)
1141890
def replace_in_file(self, file_path, old_exp, new_exp):
        
        self.term.print_info(u"Making replacement into {}"
                                 .format(self.term.text_in_color(file_path,
                                                                 TERM_GREEN)))
        # write the new version into a temporary file
        tmp_file = tempfile.NamedTemporaryFile(mode='w+t', delete=False)
        for filelineno, line in enumerate(io.open(file_path, encoding="utf-8")):
            if old_exp in line:
                line = line.replace(old_exp, new_exp)
            try:
                tmp_file.write(line.encode('utf-8'))
            except TypeError:
                tmp_file.write(line)

        name = tmp_file.name # keep the name
        tmp_file.close()
        shutil.copy(name, file_path) # replace the original one
        os.remove(name)