• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python fs.ensure_directory函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: _tile_location_tms

    def _tile_location_tms(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', directory_layout='tms')
        >>> c.tile_location(Tile((3, 4, 2))).replace('\\\\', '/')
        '/tmp/cache/2/3/4.png'
        """
        if tile.location is None:
            x, y, z = tile.coord
            tile.location = os.path.join(self.level_location(str(z)), str(x), str(y) + "." + self.file_ext)
        if create_dir:
            ensure_directory(tile.location)
        return tile.location
开发者ID:DirkThalheim,项目名称:mapproxy,代码行数:20,代码来源:file.py


示例17: tile_location_reverse_tms

def tile_location_reverse_tms(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_reverse_tms(Tile((3, 4, 2)), '/tmp/cache', 'png').replace('\\\\', '/')
    '/tmp/cache/4/3/2.png'
    """
    if tile.location is None:
        x, y, z = tile.coord
        tile.location = os.path.join(
            cache_dir, str(y), str(x), str(z) + '.' + file_ext
        )
    if create_dir:
        ensure_directory(tile.location)
    return tile.location
开发者ID:LKajan,项目名称:mapproxy,代码行数:21,代码来源:path.py


示例18: do_POST

            def do_POST(self):
                length = int(self.headers['content-length'])
                json_data = self.rfile.read(length)
                task = json.loads(json_data.decode('utf-8'))
                eq_(task['command'], 'tile')
                eq_(task['tiles'], [[10, 20, 6]])
                eq_(task['cache_identifier'], 'tms_cache_GLOBAL_MERCATOR')
                eq_(task['priority'], 100)
                # this id should not change for the same tile/cache_identifier combination
                eq_(task['id'], 'cf35c1c927158e188d8fbe0db380c1772b536da9')

                # manually create tile renderd should create
                tile_filename = os.path.join(test_self.config['cache_dir'],
                    'tms_cache_EPSG900913/06/000/000/010/000/000/020.png')
                ensure_directory(tile_filename)
                with open(tile_filename, 'wb') as f:
                    f.write(b"foobaz")

                self.send_response(200)
                self.send_header('Content-type', 'application/json')
                self.end_headers()
                self.wfile.write(b'{"status": "ok"}')
开发者ID:GeoDodo,项目名称:mapproxy,代码行数:22,代码来源:test_renderd_client.py


示例19: _tile_location_arcgiscache

    def _tile_location_arcgiscache(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='arcgis')
        >>> c.tile_location(Tile((1234567, 87654321, 9))).replace('\\\\', '/')
        '/tmp/cache/L09/R05397fb1/C0012d687.png'
        """
        if tile.location is None:
            x, y, z = tile.coord
            parts = (self._level_location_arcgiscache(z), "R%08x" % y, "C%08x.%s" % (x, self.file_ext))
            tile.location = os.path.join(*parts)
        if create_dir:
            ensure_directory(tile.location)
        return tile.location
开发者ID:DirkThalheim,项目名称:mapproxy,代码行数:22,代码来源:file.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python context.get函数代码示例发布时间:2022-05-27
下一篇:
Python coverage.load_limited_to函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap