Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(8)  |  Call(4)  |  Derive(0)  |  Import(4)
write_atomic writes `data` to a random file in filename's directory
first and renames that file to the target filename afterwards.
Rename is atomic on all POSIX platforms.

Falls back to normal write on Windows.

        def write_atomic(filename, data):
    """
    write_atomic writes `data` to a random file in filename's directory
    first and renames that file to the target filename afterwards.
    Rename is atomic on all POSIX platforms.

    Falls back to normal write on Windows.
    """
    if not sys.platform.startswith('win'):
        # write to random filename to prevent concurrent writes in cases
        # where file locking does not work (network fs)
        path_tmp = filename + '.tmp-' + str(random.randint(0, 99999999))
        try:
            fd = os.open(path_tmp, os.O_EXCL | os.O_CREAT | os.O_WRONLY)
            with os.fdopen(fd, 'wb') as f:
                f.write(data)
            os.rename(path_tmp, filename)
        except OSError:
            try:
                os.unlink(path_tmp)
            except OSError:
                pass
            raise
    else:
        with open(filename, 'wb') as f:
            f.write(data)
        


src/m/a/MapProxy-1.6.0/mapproxy/cache/legend.py   MapProxy(Download)
from mapproxy.image import ImageSource
from mapproxy.image.opts import ImageOptions
from mapproxy.util.fs import ensure_directory, write_atomic
 
import logging
        data.seek(0)
        log.debug('writing to %s' % (legend.location))
        write_atomic(legend.location, data.read())
        data.seek(0)
        legend.stored = True

src/m/a/mapproxy-HEAD/mapproxy/cache/legend.py   mapproxy(Download)
from mapproxy.image import ImageSource
from mapproxy.image.opts import ImageOptions
from mapproxy.util.fs import ensure_directory, write_atomic
 
import logging
        data.seek(0)
        log.debug('writing to %s' % (legend.location))
        write_atomic(legend.location, data.read())
        data.seek(0)
        legend.stored = True

src/m/a/MapProxy-1.6.0/mapproxy/cache/file.py   MapProxy(Download)
import errno
 
from mapproxy.util.fs import ensure_directory, write_atomic
from mapproxy.image import ImageSource, is_single_color_image
from mapproxy.cache.base import TileCacheBase, FileBasedLocking, tile_buffer
        with tile_buffer(tile) as buf:
            log.debug('writing %r to %s' % (tile.coord, location))
            write_atomic(location, buf.read())
 
    def _store_single_color_tile(self, tile, tile_loc, color):

src/m/a/mapproxy-HEAD/mapproxy/cache/file.py   mapproxy(Download)
import errno
 
from mapproxy.util.fs import ensure_directory, write_atomic
from mapproxy.image import ImageSource, is_single_color_image
from mapproxy.cache.base import TileCacheBase, FileBasedLocking, tile_buffer
        with tile_buffer(tile) as buf:
            log.debug('writing %r to %s' % (tile.coord, location))
            write_atomic(location, buf.read())
 
    def _store_single_color_tile(self, tile, tile_loc, color):