Move `filename` out of the way, archiving it by appending the current datetime
    Can be a file or a directory
761045
def archive_if_exists(filename):
    
    if os.path.exists(filename):
        current_time = datetime.datetime.now()
        dt_format = '%Y-%m-%dT%H:%M:%S%z'
        timestamp = current_time.strftime(dt_format)
        dst = filename + '_' + timestamp
        shutil.move(filename, dst)
1284635
def purge_archives(base_dir: str, retain_latest: bool = False) -> None:
        

        LOGGER.debug('purge_archives >>> base_dir: %s, retain_latest: %s', base_dir, retain_latest)

        if isdir(base_dir):
            timestamps = sorted([int(t) for t in listdir(base_dir) if t.isdigit()])
            if retain_latest and timestamps:
                timestamps.pop()
            for timestamp in timestamps:
                timestamp_dir = join(base_dir, str(timestamp))
                rmtree(timestamp_dir)
                LOGGER.info('Purged archive cache directory %s', timestamp_dir)

        LOGGER.debug('purge_archives <<<')
849639
def save(self, filename=None, ignore_discard=False, ignore_expires=False):
        ''''''
        if filename is None:
            if self.filename is not None:
                filename = self.filename
            else:
                raise ValueError(cookiejar.MISSING_FILENAME_TEXT)

        # TODO: obtain file lock, read contents of file, and merge with
        # current content.
        go_cookies = []
        now = time.time()
        for cookie in self:
            if not ignore_discard and cookie.discard:
                continue
            if not ignore_expires and cookie.is_expired(now):
                continue
            go_cookies.append(py_to_go_cookie(cookie))
        with open(filename, "w") as f:
            f.write(json.dumps(go_cookies))
112378
def get_last_modified_date(filename):
    
    if os.path.isfile(filename):
        t = os.path.getmtime(filename)
        return datetime.date.fromtimestamp(t).strftime('%d/%m/%Y')
    return None
918391
def filename(self, value):
        """"""
        warnings.warn(
            "The 'filename' attribute will be removed in future versions.  "
            "Use 'source' instead.",
            DeprecationWarning, stacklevel=2
        )
        self.source = value
876337
def cleanup_tmpdir(dirname):
    """"""
    if dirname is not None and os.path.exists(dirname):
        shutil.rmtree(dirname)
1255762
def _move_file_to_dest_dir(self, filename):
        ''''''
        assert self._params.move_to

        if os.path.isdir(self._params.move_to):
            _logger.debug('Moved {} to {}.', self._warc_filename,
                          self._params.move_to)
            shutil.move(filename, self._params.move_to)
        else:
            _logger.error('{} is not a directory; not moving {}.',
                          self._params.move_to, filename)
62435
function copyFile (oldName, newName) {
    let contents = fs.readFileSync (oldName, 'utf8')
    fs.truncateSync (newName)
    fs.writeFileSync (newName, contents)
}
446597
def upload_path(instance, filename):
    '''
    
    '''
    path_separator = "/"
    date_separator = "-"
    ext_separator = "."
    empty_string = ""
    # get the model name
    model_name = model_inspect(instance)['modelname']

    # get the string date
    date = datetime.now().strftime("%Y-%m-%d").split(date_separator)
    curr_day = date[2]
    curr_month = date[1]
    curr_year = date[0]

    split_filename = filename.split(ext_separator)
    filename = empty_string.join(split_filename[:-1])
    file_ext = split_filename[-1]

    new_filename = empty_string.join([filename, str(random.random()).split(ext_separator)[1]])
    new_filename = ext_separator.join([new_filename, file_ext])
    string_path = path_separator.join([model_name, curr_year, curr_month, curr_day, new_filename])
    # the path is built using the current date and the modelname
    return string_path
74363
def delete(self, filename=''):
        
        self._raise_if_none()
        fn = path_join(self.path, filename)

        try:
            if isfile(fn):
                remove(fn)
            else:
                removedirs(fn)
        except OSError as why:
            if why.errno == errno.ENOENT:
                pass
            else:
                raise why
994016
def write_to_disk(filename, delete=False, content=get_time()):
    
    if not os.path.exists(os.path.dirname(filename)):
        return
    if delete:
        if os.path.lexists(filename):
            os.remove(filename)
    else:
        with open(filename, 'wb') as f:
            f.write(content.encode('utf-8'))
597480
def move(self, dst, **kwargs):
        """"""
        _fs, filename = opener.parse(self.uri)
        _fs_dst, filename_dst = opener.parse(dst)
        movefile(_fs, filename, _fs_dst, filename_dst, **kwargs)
        self.uri = dst
61754
def get_archives_to_prune(archives, hook_data):
    """"""
    files_to_skip = []
    for i in ['current_archive_filename', 'old_archive_filename']:
        if hook_data.get(i):
            files_to_skip.append(hook_data[i])
    archives.sort(key=itemgetter('LastModified'),
                  reverse=False)  # sort from oldest to newest
    # Drop all but last 15 files
    return [i['Key'] for i in archives[:-15] if i['Key'] not in files_to_skip]
261930
def _append_date(self, value, _file):  # pylint: disable=no-self-use
        
        _text = value.strftime('%Y-%m-%dT%H:%M:%S.%fZ')
        _labs = ' "{text}"'.format(text=_text)
        _file.write(_labs)
959086
def on_close(self, filename):
        """"""
        shutil.move(filename, self.destination_folder)
        path, fn = os.path.split(filename)
        return os.path.join(self.destination_folder, fn)
446831
def save(self):
        
        with NamedTemporaryFile(
            dir=os.path.dirname(self.storage_path), delete=False
        ) as f:
            # we use protocol=2 for python 2/3 compatibility
            dump(self.data, f, protocol=2)
            f.flush()
            os.fsync(f.fileno())
            tmppath = f.name
        os.rename(tmppath, self.storage_path)
694111
function move(oldPath, newPath) {
  if (toDel[oldPath] || !fileExists(oldPath)) {
    log('Error: no file to move: ', 'red', oldPath);
    throw new Error('No file to move');
  }

  if (fileExists(newPath)) {
    log('Error: target file already exists: ', 'red', newPath);
    throw new Error('Target file already exists');
  }
  if (fileLines[oldPath]) {
    fileLines[newPath] = fileLines[oldPath];
    delete fileLines[oldPath];
  }

  // if (asts[oldPath]) {
  //   asts[newPath] = asts[oldPath];
  //   delete asts[oldPath];
  // }

  if (toSave[oldPath]) {
    toSave[newPath] = true;
    delete toSave[oldPath];
  }

  if (toDel[oldPath]) {
    delete toDel[oldPath];
  }
  // if the file has already been moved
  oldPath = _.findKey(mvs, s => s === oldPath) || oldPath;
  mvs[oldPath] = newPath;
}