當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。