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


Python fileutils.ensure_tree方法代码示例

本文整理汇总了Python中oslo_utils.fileutils.ensure_tree方法的典型用法代码示例。如果您正苦于以下问题:Python fileutils.ensure_tree方法的具体用法?Python fileutils.ensure_tree怎么用?Python fileutils.ensure_tree使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在oslo_utils.fileutils的用法示例。


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

示例1: __init__

# 需要导入模块: from oslo_utils import fileutils [as 别名]
# 或者: from oslo_utils.fileutils import ensure_tree [as 别名]
def __init__(self, root_directory, bucket_depth=0, mapper=None):
        if mapper is None:
            mapper = routes.Mapper()

        mapper.connect(
                '/',
                controller=lambda *a, **kw: RootHandler(self)(*a, **kw))
        mapper.connect(
                '/{bucket}/{object_name}',
                controller=lambda *a, **kw: ObjectHandler(self)(*a, **kw))
        mapper.connect(
                '/{bucket_name}',
                controller=lambda *a, **kw: BucketHandler(self)(*a, **kw),
                requirements={'bucket_name': '[^/]+/?'})
        self.directory = os.path.abspath(root_directory)
        fileutils.ensure_tree(self.directory)
        self.bucket_depth = bucket_depth
        super(S3Application, self).__init__(mapper) 
开发者ID:openstack,项目名称:ec2-api,代码行数:20,代码来源:s3server.py

示例2: put

# 需要导入模块: from oslo_utils import fileutils [as 别名]
# 或者: from oslo_utils.fileutils import ensure_tree [as 别名]
def put(self, bucket, object_name):
        object_name = parse.unquote(object_name)
        bucket_dir = os.path.abspath(os.path.join(
            self.application.directory, bucket))
        if (not bucket_dir.startswith(self.application.directory) or
                not os.path.isdir(bucket_dir)):
            self.set_404()
            return
        path = self._object_path(bucket, object_name)
        if not path.startswith(bucket_dir) or os.path.isdir(path):
            self.set_status(403)
            return
        directory = os.path.dirname(path)
        fileutils.ensure_tree(directory)
        object_file = open(path, "wb")
        object_file.write(self.request.body)
        object_file.close()
        self.set_header('ETag',
                        '"%s"' % utils.get_hash_str(self.request.body))
        self.finish() 
开发者ID:openstack,项目名称:ec2-api,代码行数:22,代码来源:s3server.py

示例3: __init__

# 需要导入模块: from oslo_utils import fileutils [as 别名]
# 或者: from oslo_utils.fileutils import ensure_tree [as 别名]
def __init__(self,
                 backend,
                 tenant_id,
                 storage,
                 basepath=None,
                 period=3600):
        self._backend = backend
        self._tenant_id = tenant_id
        self._storage = storage
        self._storage_state = storage_state.StateManager()
        self._basepath = basepath
        if self._basepath:
            fileutils.ensure_tree(self._basepath)
        self._period = period
        self._sm = state.DBStateManager(self._tenant_id,
                                        'writer_status')
        self._write_pipeline = []

        # State vars
        self.usage_start = None
        self.usage_end = None

        # Current total
        self.total = 0 
开发者ID:openstack,项目名称:cloudkitty,代码行数:26,代码来源:write_orchestrator.py

示例4: attach

# 需要导入模块: from oslo_utils import fileutils [as 别名]
# 或者: from oslo_utils.fileutils import ensure_tree [as 别名]
def attach(self, context, volmap):
        mountpoint = mount.get_mountpoint(volmap.volume.uuid)
        fileutils.ensure_tree(mountpoint)
        filename = '/'.join([mountpoint, volmap.volume.uuid])
        with open(filename, 'wb') as fd:
            content = utils.decode_file_data(volmap.contents)
            fd.write(content) 
开发者ID:openstack,项目名称:zun,代码行数:9,代码来源:driver.py

示例5: _mount_device

# 需要导入模块: from oslo_utils import fileutils [as 别名]
# 或者: from oslo_utils.fileutils import ensure_tree [as 别名]
def _mount_device(self, volmap, devpath):
        mountpoint = mount.get_mountpoint(volmap.volume.uuid)
        fileutils.ensure_tree(mountpoint)
        mount.do_mount(devpath, mountpoint, CONF.volume.fstype) 
开发者ID:openstack,项目名称:zun,代码行数:6,代码来源:driver.py

示例6: pull_image

# 需要导入模块: from oslo_utils import fileutils [as 别名]
# 或者: from oslo_utils.fileutils import ensure_tree [as 别名]
def pull_image(self, context, repo, tag, image_pull_policy, registry):
        image_loaded = False
        image = self._search_image_on_host(context, repo, tag)

        if not common_utils.should_pull_image(image_pull_policy, bool(image)):
            if image:
                if self._verify_md5sum_for_image(image):
                    image_loaded = True
                    return image, image_loaded
            else:
                message = _('Image %s not present with pull policy of Never'
                            ) % repo
                raise exception.ImageNotFound(message)

        LOG.debug('Pulling image from glance %s', repo)
        try:
            image_meta = utils.find_image(context, repo, tag)
            LOG.debug('Image %s was found in glance, downloading now...', repo)
            image_chunks = utils.download_image_in_chunks(context,
                                                          image_meta.id)
        except exception.ImageNotFound:
            LOG.error('Image %s was not found in glance', repo)
            raise
        except Exception as e:
            msg = _('Cannot download image from glance: {0}')
            raise exception.ZunException(msg.format(e))
        try:
            images_directory = CONF.glance.images_directory
            fileutils.ensure_tree(images_directory)
            out_path = os.path.join(images_directory, image_meta.id + '.tar')
            with open(out_path, 'wb') as fd:
                for chunk in image_chunks:
                    fd.write(chunk)
        except Exception as e:
            msg = _('Error occurred while writing image: {0}')
            raise exception.ZunException(msg.format(e))
        LOG.debug('Image %(repo)s was downloaded to path : %(path)s',
                  {'repo': repo, 'path': out_path})
        image = {'image': image_meta.name, 'tags': image_meta.tags,
                 'path': out_path}
        return image, image_loaded 
开发者ID:openstack,项目名称:zun,代码行数:43,代码来源:driver.py

示例7: _create_instance_file

# 需要导入模块: from oslo_utils import fileutils [as 别名]
# 或者: from oslo_utils.fileutils import ensure_tree [as 别名]
def _create_instance_file(self, id, name, data):
        file_dir = os.path.join(CONF.instances_path, id)
        fileutils.ensure_tree(file_dir)
        file = os.path.join(file_dir, name)
        with open(file, 'a') as f:
            f.write(data)
        os.chmod(file_dir, 0o700)
        os.chmod(file, 0o600)
        return file 
开发者ID:openstack,项目名称:zun,代码行数:11,代码来源:driver.py

示例8: ensure_config_dir

# 需要导入模块: from oslo_utils import fileutils [as 别名]
# 或者: from oslo_utils.fileutils import ensure_tree [as 别名]
def ensure_config_dir(self, vpnservice):
        """Create config directory if it does not exist."""
        fileutils.ensure_tree(self.config_dir, 0o755)
        for subdir in self.CONFIG_DIRS:
            dir_path = os.path.join(self.config_dir, subdir)
            fileutils.ensure_tree(dir_path, 0o755) 
开发者ID:openstack,项目名称:neutron-vpnaas,代码行数:8,代码来源:ipsec.py

示例9: _create_temp_file

# 需要导入模块: from oslo_utils import fileutils [as 别名]
# 或者: from oslo_utils.fileutils import ensure_tree [as 别名]
def _create_temp_file(self, *args, **kwargs):
        fileutils.ensure_tree(self._tmp_dir)
        fd, tmp = tempfile.mkstemp(dir=self._tmp_dir, *args, **kwargs)
        os.close(fd)
        return tmp 
开发者ID:openstack,项目名称:os-brick,代码行数:7,代码来源:vmware.py

示例10: _ensure_path

# 需要导入模块: from oslo_utils import fileutils [as 别名]
# 或者: from oslo_utils.fileutils import ensure_tree [as 别名]
def _ensure_path(self, path):
        with _storagefailure_wrapper():
            fileutils.ensure_tree(path) 
开发者ID:openstack,项目名称:taskflow,代码行数:5,代码来源:impl_dir.py

示例11: setUp

# 需要导入模块: from oslo_utils import fileutils [as 别名]
# 或者: from oslo_utils.fileutils import ensure_tree [as 别名]
def setUp(self):
        super(BaseFunctionalTestCase, self).setUp()
        logging.register_options(CONF)
        setup_logging(self.COMPONENT_NAME)
        fileutils.ensure_tree(DEFAULT_LOG_DIR, mode=0o755)
        log_file = sanitize_log_path(
            os.path.join(DEFAULT_LOG_DIR, "%s.txt" % self.id()))
        self.flags(log_file=log_file)
        privsep_helper = os.path.join(
            os.getenv('VIRTUAL_ENV', os.path.dirname(sys.executable)[:-4]),
            'bin', 'privsep-helper')
        self.flags(
            helper_command=' '.join(['sudo', '-E', privsep_helper]),
            group=self.PRIVILEGED_GROUP) 
开发者ID:openstack,项目名称:os-vif,代码行数:16,代码来源:base.py

示例12: store

# 需要导入模块: from oslo_utils import fileutils [as 别名]
# 或者: from oslo_utils.fileutils import ensure_tree [as 别名]
def store(self, project_id, function, data, md5sum=None):
        """Store the function package data to local file system.

        :param project_id: Project ID.
        :param function: Function ID.
        :param data: Package file content.
        :param md5sum: The MD5 provided by the user.
        :return: A tuple (if the package is updated, MD5 value of the package)
        """
        LOG.debug(
            'Store package, function: %s, project: %s', function, project_id
        )

        project_path = os.path.join(self.base_path, project_id)
        fileutils.ensure_tree(project_path)

        # Check md5
        md5_actual = common.md5(content=data)
        if md5sum and md5_actual != md5sum:
            raise exc.InputException("Package md5 mismatch.")

        func_zip = os.path.join(
            project_path,
            PACKAGE_NAME_TEMPLATE % (function, md5_actual)
        )
        if os.path.exists(func_zip):
            return False, md5_actual

        # Save package
        new_func_zip = os.path.join(project_path, '%s.zip.new' % function)
        with open(new_func_zip, 'wb') as fd:
            fd.write(data)

        if not zipfile.is_zipfile(new_func_zip):
            fileutils.delete_if_exists(new_func_zip)
            raise exc.InputException("Package is not a valid ZIP package.")

        os.rename(new_func_zip, func_zip)

        return True, md5_actual 
开发者ID:openstack,项目名称:qinling,代码行数:42,代码来源:file_system.py

示例13: test_ensure_tree

# 需要导入模块: from oslo_utils import fileutils [as 别名]
# 或者: from oslo_utils.fileutils import ensure_tree [as 别名]
def test_ensure_tree(self):
        tmpdir = tempfile.mkdtemp()
        try:
            testdir = '%s/foo/bar/baz' % (tmpdir,)
            fileutils.ensure_tree(testdir, TEST_PERMISSIONS)
            self.assertTrue(os.path.isdir(testdir))
            self.assertEqual(os.stat(testdir).st_mode,
                             TEST_PERMISSIONS | stat.S_IFDIR)
        finally:
            if os.path.exists(tmpdir):
                shutil.rmtree(tmpdir) 
开发者ID:openstack,项目名称:oslo.utils,代码行数:13,代码来源:test_fileutils.py

示例14: _pull_missing_image

# 需要导入模块: from oslo_utils import fileutils [as 别名]
# 或者: from oslo_utils.fileutils import ensure_tree [as 别名]
def _pull_missing_image(self, context, image_meta, instance):
        msg = 'Image name "%s" does not exist, fetching it...'
        LOG.debug(msg, image_meta.name)

        shared_directory = CONF.docker.shared_directory
        if (shared_directory and
                os.path.exists(os.path.join(shared_directory,
                                            image_meta.id))):
            LOG.debug('Found %s in shared_directory', image_meta.id)
            try:
                LOG.debug('Loading repository file into docker %s',
                          self._encode_utf8(image_meta.name))
                self.docker.load_repository_file(
                    self._encode_utf8(image_meta.name),
                    os.path.join(shared_directory, image_meta.id))
                return self.docker.inspect_image(
                    self._encode_utf8(image_meta.name))
            except Exception as e:
                # If failed to load image from shared_directory, continue
                # to download the image from glance then load.
                LOG.warning('Cannot load repository file from shared '
                            'directory: %s',
                            e, instance=instance, exc_info=True)

        # TODO(imain): It would be nice to do this with file like object
        # passing but that seems a bit complex right now.
        snapshot_directory = CONF.docker.snapshots_directory
        fileutils.ensure_tree(snapshot_directory)
        with utils.tempdir(dir=snapshot_directory) as tmpdir:
            try:
                out_path = os.path.join(tmpdir,
                                        uuidutils.generate_uuid(dashed=False))

                LOG.debug('Fetching image with id %s from glance',
                          image_meta.id)
                images.fetch(context, image_meta.id, out_path)
                LOG.debug('Loading repository file into docker %s',
                          self._encode_utf8(image_meta.name))
                self.docker.load_repository_file(
                    self._encode_utf8(image_meta.name),
                    out_path
                )
                return self.docker.inspect_image(
                    self._encode_utf8(image_meta.name))
            except Exception as e:
                LOG.warning('Cannot load repository file: %s',
                            e, instance=instance, exc_info=True)
                msg = _('Cannot load repository file: {0}')
                raise exception.NovaException(msg.format(e),
                                              instance_id=image_meta.name) 
开发者ID:openstack,项目名称:zun,代码行数:52,代码来源:driver.py


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