当前位置: 首页>>代码示例>>Python>>正文


Python fs.ensure_directory函数代码示例

本文整理汇总了Python中mapproxy.util.fs.ensure_directory函数的典型用法代码示例。如果您正苦于以下问题:Python ensure_directory函数的具体用法?Python ensure_directory怎么用?Python ensure_directory使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了ensure_directory函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _tile_location_quadkey

    def _tile_location_quadkey(self, tile, create_dir=False):
        """
        Return the location of the `tile`. Caches the result as ``location``
        property of the `tile`.

        :param tile: the tile object
        :param create_dir: if True, create all necessary directories
        :return: the full filename of the tile

        >>> from mapproxy.cache.tile import Tile
        >>> from mapproxy.cache.file import FileCache
        >>> c = FileCache(cache_dir='/tmp/cache/', file_ext='png', directory_layout='quadkey')
        >>> c.tile_location(Tile((3, 4, 2))).replace('\\\\', '/')
        '/tmp/cache/11.png'
        """
        if tile.location is None:
            x, y, z = tile.coord
            quadKey = ""
            for i in range(z, 0, -1):
                digit = 0
                mask = 1 << (i - 1)
                if (x & mask) != 0:
                    digit += 1
                if (y & mask) != 0:
                    digit += 2
                quadKey += str(digit)
            tile.location = os.path.join(self.cache_dir, quadKey + "." + self.file_ext)
        if create_dir:
            ensure_directory(tile.location)
        return tile.location
开发者ID:DirkThalheim,项目名称:mapproxy,代码行数:30,代码来源:file.py

示例2: _tile_location_tc

    def _tile_location_tc(self, tile, create_dir=False):
        """
        Return the location of the `tile`. Caches the result as ``location``
        property of the `tile`.

        :param tile: the tile object
        :param create_dir: if True, create all necessary directories
        :return: the full filename of the tile

        >>> from mapproxy.cache.tile import Tile
        >>> c = FileCache(cache_dir='/tmp/cache/', file_ext='png')
        >>> c.tile_location(Tile((3, 4, 2))).replace('\\\\', '/')
        '/tmp/cache/02/000/000/003/000/000/004.png'
        """
        if tile.location is None:
            x, y, z = tile.coord
            parts = (
                self._level_location(z),
                "%03d" % int(x / 1000000),
                "%03d" % (int(x / 1000) % 1000),
                "%03d" % (int(x) % 1000),
                "%03d" % int(y / 1000000),
                "%03d" % (int(y / 1000) % 1000),
                "%03d.%s" % (int(y) % 1000, self.file_ext),
            )
            tile.location = os.path.join(*parts)
        if create_dir:
            ensure_directory(tile.location)
        return tile.location
开发者ID:DirkThalheim,项目名称:mapproxy,代码行数:29,代码来源:file.py

示例3: ensure_mbtile

 def ensure_mbtile(self):
     if not os.path.exists(self.mbtile_file):
         with FileLock(os.path.join(os.path.dirname(self.mbtile_file), 'init.lck'),
             remove_on_unlock=True):
             if not os.path.exists(self.mbtile_file):
                 ensure_directory(self.mbtile_file)
                 self._initialize_mbtile()
开发者ID:Geodan,项目名称:mapproxy,代码行数:7,代码来源:mbtiles.py

示例4: _init_bundle

 def _init_bundle(self):
     log.info("Init Bundle %s" % self.filename)
     ensure_directory(self.filename)
     write_atomic(self.filename, struct.pack(*[self.BUNDLE_BYTEORDER + self.BUNDLE_HEADER_FORMAT + self.BUNDLE_INDEX_FORMAT] +
                                             list(self.header.values()) +
                                             self.index    # empty index
                                             ))
开发者ID:tjay,项目名称:mapproxy,代码行数:7,代码来源:compact.py

示例5: ensure_mbtile

 def ensure_mbtile(self):
     if not os.path.exists(self.mbtile_file):
         with FileLock(self.mbtile_file + '.init.lck',
             remove_on_unlock=REMOVE_ON_UNLOCK):
             if not os.path.exists(self.mbtile_file):
                 ensure_directory(self.mbtile_file)
                 self._initialize_mbtile()
开发者ID:tjay,项目名称:mapproxy,代码行数:7,代码来源:mbtiles.py

示例6: tile_location_mp

def tile_location_mp(tile, cache_dir, file_ext, create_dir=False):
    """
    Return the location of the `tile`. Caches the result as ``location``
    property of the `tile`.

    :param tile: the tile object
    :param create_dir: if True, create all necessary directories
    :return: the full filename of the tile

    >>> from mapproxy.cache.tile import Tile
    >>> tile_location_mp(Tile((3, 4, 2)), '/tmp/cache', 'png').replace('\\\\', '/')
    '/tmp/cache/02/0000/0003/0000/0004.png'
    >>> tile_location_mp(Tile((12345678, 98765432, 22)), '/tmp/cache', 'png').replace('\\\\', '/')
    '/tmp/cache/22/1234/5678/9876/5432.png'
    """
    if tile.location is None:
        x, y, z = tile.coord
        parts = (cache_dir,
                level_part(z),
                 "%04d" % int(x / 10000),
                 "%04d" % (int(x) % 10000),
                 "%04d" % int(y / 10000),
                 "%04d.%s" % (int(y) % 10000, file_ext))
        tile.location = os.path.join(*parts)
    if create_dir:
        ensure_directory(tile.location)
    return tile.location
开发者ID:LKajan,项目名称:mapproxy,代码行数:27,代码来源:path.py

示例7: ensure_mbtile

 def ensure_mbtile(self):
     if not os.path.exists(self.mbtile_file):
         with FileLock(os.path.join(self.lock_dir, 'init.lck'),
             timeout=self.lock_timeout,
             remove_on_unlock=True):
             if not os.path.exists(self.mbtile_file):
                 ensure_directory(self.mbtile_file)
                 self._initialize_mbtile()
开发者ID:Anderson0026,项目名称:mapproxy,代码行数:8,代码来源:mbtiles.py

示例8: _init_bundle

 def _init_bundle(self):
     ensure_directory(self.filename)
     header = list(BUNDLE_V1_HEADER)
     header[10], header[8] = self.tile_offsets
     header[11], header[9] = header[10]+127, header[8]+127
     write_atomic(self.filename,
         struct.pack(BUNDLE_V1_HEADER_STRUCT_FORMAT, *header) +
         # zero-size entry for each tile
         (b'\x00' * (BUNDLEX_V1_GRID_HEIGHT * BUNDLEX_V1_GRID_WIDTH * 4)))
开发者ID:LKajan,项目名称:mapproxy,代码行数:9,代码来源:compact.py

示例9: ensure_gpkg

 def ensure_gpkg(self):
     if not os.path.isfile(self.geopackage_file):
         with FileLock(self.geopackage_file + '.init.lck',
                       remove_on_unlock=REMOVE_ON_UNLOCK):
             ensure_directory(self.geopackage_file)
             self._initialize_gpkg()
     else:
         if not self.check_gpkg():
             ensure_directory(self.geopackage_file)
             self._initialize_gpkg()
开发者ID:tjay,项目名称:mapproxy,代码行数:10,代码来源:geopackage.py

示例10: _init_index

 def _init_index(self):
     self._initialized = True
     if os.path.exists(self.filename):
         return
     ensure_directory(self.filename)
     buf = BytesIO()
     buf.write(struct.pack(BUNDLE_V2_HEADER_STRUCT_FORMAT, *BUNDLE_V2_HEADER))
     # Empty index (ArcGIS stores an offset of 4 and size of 0 for missing tiles)
     buf.write(struct.pack('<%dQ' % BUNDLE_V2_TILES, *(4, ) * BUNDLE_V2_TILES))
     write_atomic(self.filename, buf.getvalue())
开发者ID:LKajan,项目名称:mapproxy,代码行数:10,代码来源:compact.py

示例11: _single_color_tile_location

 def _single_color_tile_location(self, color, create_dir=False):
     """
     >>> c = FileCache(cache_dir='/tmp/cache/', file_ext='png')
     >>> c._single_color_tile_location((254, 0, 4)).replace('\\\\', '/')
     '/tmp/cache/single_color_tiles/fe0004.png'
     """
     parts = (self.cache_dir, "single_color_tiles", "".join("%02x" % v for v in color) + "." + self.file_ext)
     location = os.path.join(*parts)
     if create_dir:
         ensure_directory(location)
     return location
开发者ID:DirkThalheim,项目名称:mapproxy,代码行数:11,代码来源:file.py

示例12: _init_index

 def _init_index(self):
     self._initialized = True
     if os.path.exists(self.filename):
         return
     ensure_directory(self.filename)
     buf = BytesIO()
     buf.write(BUNDLEX_HEADER)
     for i in range(BUNDLEX_GRID_WIDTH * BUNDLEX_GRID_HEIGHT):
         buf.write(struct.pack('<Q', (i*4)+BUNDLE_HEADER_SIZE)[:5])
     buf.write(BUNDLEX_FOOTER)
     write_atomic(self.filename, buf.getvalue())
开发者ID:olt,项目名称:mapproxy,代码行数:11,代码来源:compact.py

示例13: make_tile

    def make_tile(self, coord=(0, 0, 0), timestamp=None):
        """
        Create file for tile at `coord` with given timestamp.
        """
        tile_dir = os.path.join(self.dir, 'cache/one_EPSG4326/%02d/000/000/%03d/000/000/' %
                                (coord[2], coord[0]))

        ensure_directory(tile_dir)
        tile = os.path.join(tile_dir + '%03d.png' % coord[1])
        open(tile, 'wb').write(b'')
        if timestamp:
            os.utime(tile, (timestamp, timestamp))
        return tile
开发者ID:GeoDodo,项目名称:mapproxy,代码行数:13,代码来源:test_seed.py

示例14: store

    def store(self, legend):
        if legend.stored:
            return

        if legend.location is None:
            hash = legend_hash(legend.id, legend.scale)
            legend.location = os.path.join(self.cache_dir, hash) + '.' + self.file_ext
            ensure_directory(legend.location)

        data = legend.source.as_buffer(ImageOptions(format='image/' + self.file_ext), seekable=True)
        data.seek(0)
        log.debug('writing to %s' % (legend.location))
        write_atomic(legend.location, data.read())
        data.seek(0)
        legend.stored = True
开发者ID:LKajan,项目名称:mapproxy,代码行数:15,代码来源:legend.py

示例15: tile_location_arcgiscache

def tile_location_arcgiscache(tile, cache_dir, file_ext, create_dir=False):
    """
    Return the location of the `tile`. Caches the result as ``location``
    property of the `tile`.

    :param tile: the tile object
    :param create_dir: if True, create all necessary directories
    :return: the full filename of the tile

    >>> from mapproxy.cache.tile import Tile
    >>> tile_location_arcgiscache(Tile((1234567, 87654321, 9)), '/tmp/cache', 'png').replace('\\\\', '/')
    '/tmp/cache/L09/R05397fb1/C0012d687.png'
    """
    if tile.location is None:
        x, y, z = tile.coord
        parts = (cache_dir, 'L%02d' % z, 'R%08x' % y, 'C%08x.%s' % (x, file_ext))
        tile.location = os.path.join(*parts)
    if create_dir:
        ensure_directory(tile.location)
    return tile.location
开发者ID:LKajan,项目名称:mapproxy,代码行数:20,代码来源:path.py


注:本文中的mapproxy.util.fs.ensure_directory函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。