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


Python WgtFile.close方法代码示例

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


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

示例1: add_widget_from_wgt

# 需要导入模块: from wirecloud.commons.utils.wgt import WgtFile [as 别名]
# 或者: from wirecloud.commons.utils.wgt.WgtFile import close [as 别名]
def add_widget_from_wgt(file, user, wgt_file=None, template=None, deploy_only=False):

    close_wgt = False
    if wgt_file is None:
        wgt_file = WgtFile(file)
        close_wgt = True

    if template is None:
        template_contents = wgt_file.get_template()
        template = TemplateParser(template_contents)

    resource_id = (
        template.get_resource_vendor(),
        template.get_resource_name(),
        template.get_resource_version(),
    )
    file_name = '_'.join(resource_id) + '.wgt'
    local_dir = wgt_deployer.get_base_dir(*resource_id)
    local_wgt = os.path.join(local_dir, file_name)

    if not os.path.exists(local_dir):
        os.makedirs(local_dir)

    overrides = extract_resource_media_from_package(template, wgt_file, local_dir)
    if close_wgt:
        wgt_file.close()

    f = open(local_wgt, "wb")
    file.seek(0)
    f.write(file.read())
    f.close()

    if not deploy_only:
        return add_resource_from_template(file_name, template, user, fromWGT=True, overrides=overrides)
开发者ID:fispace,项目名称:wirecloud,代码行数:36,代码来源:utils.py

示例2: update_resource_catalogue_cache

# 需要导入模块: from wirecloud.commons.utils.wgt import WgtFile [as 别名]
# 或者: from wirecloud.commons.utils.wgt.WgtFile import close [as 别名]
def update_resource_catalogue_cache(orm=None):

    from wirecloud.catalogue.utils import wgt_deployer

    if orm is not None:
        resources = orm.CatalogueResource.objects.all()
    else:
        from wirecloud.catalogue.models import CatalogueResource
        resources = CatalogueResource.objects.all()

    for resource in resources:

        try:

            if resource.fromWGT:
                base_dir = wgt_deployer.get_base_dir(resource.vendor, resource.short_name, resource.version)
                wgt_file = WgtFile(os.path.join(base_dir, resource.template_uri))
                template = wgt_file.get_template()
                wgt_file.close()
            else:
                template = download_http_content(resource.template_uri)

            template_parser = TemplateParser(template)
            resource.json_description = json.dumps(template_parser.get_resource_info())
            resource.save()

        except TemplateParseException as e:

            from django.conf import settings

            if getattr(settings, 'WIRECLOUD_REMOVE_UNSUPPORTED_RESOURCES_MIGRATION', False) is not True:
                raise e

            print('    Removing %s' % (resource.vendor + '/' + resource.short_name + '/' + resource.version))
            resource.delete()
开发者ID:aarranz,项目名称:wirecloud,代码行数:37,代码来源:0004_refresh_resource_cache.py

示例3: _handle

# 需要导入模块: from wirecloud.commons.utils.wgt import WgtFile [as 别名]
# 或者: from wirecloud.commons.utils.wgt.WgtFile import close [as 别名]
    def _handle(self, *args, **options):
        if len(args) < 1:
            raise CommandError(_('Wrong number of arguments'))

        self.verbosity = int(options.get('verbosity', 1))

        users = []
        groups = []
        redeploy = options['redeploy']
        public = options['public']
        users_string = options['users'].strip()
        groups_string = options['groups'].strip()

        if redeploy is False and public is False and users_string == '' and groups_string == '':
            raise CommandError(_('You must use at least one of the following flags: --redeploy, --users, --groups or --public '))

        if not options['redeploy']:

            if users_string != '':
                for username in users_string.split(','):
                    users.append(User.objects.get(username=username))

            if groups_string != '':
                for groupname in groups_string.split(','):
                    groups.append(Group.objects.get(name=groupname))

        for file_name in args:
            try:
                f = open(file_name, 'rb')
                wgt_file = WgtFile(f)
            except:
                self.log(_('Failed to read from %(file_name)s') % {'file_name': file_name}, level=1)
                continue

            try:
                template_contents = wgt_file.get_template()
                template = TemplateParser(template_contents)
                if options['redeploy']:
                    add_packaged_resource(f, None, wgt_file=wgt_file, template=template, deploy_only=True)
                else:
                    for user in users:
                        install_resource_to_user(user, file_contents=wgt_file)

                    for group in groups:
                        install_resource_to_group(group, file_contents=wgt_file)

                    if public:
                        install_resource_to_all_users(file_contents=wgt_file)

                wgt_file.close()
                f.close()
                self.log(_('Successfully imported \"%(name)s\" from \"%(file_name)s\"') % {'name': template.get_resource_processed_info()['title'], 'file_name': file_name}, level=1)
            except:
                self.log(_('Failed to import the mashable application component from %(file_name)s') % {'file_name': file_name}, level=1)
开发者ID:perezdf,项目名称:wirecloud,代码行数:56,代码来源:addtocatalogue.py

示例4: add_packaged_resource

# 需要导入模块: from wirecloud.commons.utils.wgt import WgtFile [as 别名]
# 或者: from wirecloud.commons.utils.wgt.WgtFile import close [as 别名]
def add_packaged_resource(file, user, wgt_file=None, template=None, deploy_only=False):

    close_wgt = False
    if wgt_file is None:
        wgt_file = WgtFile(file)
        close_wgt = True

    if template is None:
        template_contents = wgt_file.get_template()
        template = TemplateParser(template_contents)

    resource_info = template.get_resource_info()

    resource_id = (
        resource_info['vendor'],
        resource_info['name'],
        resource_info['version'],
    )
    file_name = '_'.join(resource_id) + '.wgt'

    check_packaged_resource(wgt_file, resource_info)

    local_dir = wgt_deployer.get_base_dir(*resource_id)
    local_wgt = os.path.join(local_dir, file_name)

    if not os.path.exists(local_dir):
        os.makedirs(local_dir)

    overrides = extract_resource_media_from_package(template, wgt_file, local_dir)
    if close_wgt:
        wgt_file.close()

    f = open(local_wgt, "wb")
    file.seek(0)
    f.write(file.read())
    f.close()

    if not deploy_only:
        resource_info.update(overrides)

        resource = CatalogueResource.objects.create(
            short_name=resource_info['name'],
            vendor=resource_info['vendor'],
            version=resource_info['version'],
            type=CatalogueResource.RESOURCE_TYPES.index(resource_info['type']),
            creator=user,
            template_uri=file_name,
            creation_date=now(),
            popularity='0.0',
            json_description=json.dumps(resource_info)
        )

        return resource
开发者ID:Fiware,项目名称:apps.Wirecloud,代码行数:55,代码来源:utils.py

示例5: add_widget_from_wgt

# 需要导入模块: from wirecloud.commons.utils.wgt import WgtFile [as 别名]
# 或者: from wirecloud.commons.utils.wgt.WgtFile import close [as 别名]
def add_widget_from_wgt(file, user, wgt_file=None, template=None, deploy_only=False):

    close_wgt = False
    if wgt_file is None:
        wgt_file = WgtFile(file)
        close_wgt = True

    if template is None:
        template_contents = wgt_file.get_template()
        template = TemplateParser(template_contents)

    if template.get_resource_type() == 'widget':
        resource_info = template.get_resource_info()
        code_url = resource_info['code_url']
        if not code_url.startswith(('http://', 'https://')):
            code = wgt_file.read(code_url)
            try:
                unicode(code, resource_info['code_charset'])
            except UnicodeDecodeError:
                msg = _('%(file_name)s was not encoded using the specified charset (%(charset)s according to the widget descriptor file).')
                raise InvalidContents(msg % {'file_name': code_url, 'charset': resource_info['code_charset']})

    resource_id = (
        template.get_resource_vendor(),
        template.get_resource_name(),
        template.get_resource_version(),
    )
    file_name = '_'.join(resource_id) + '.wgt'
    local_dir = wgt_deployer.get_base_dir(*resource_id)
    local_wgt = os.path.join(local_dir, file_name)

    if not os.path.exists(local_dir):
        os.makedirs(local_dir)

    overrides = extract_resource_media_from_package(template, wgt_file, local_dir)
    if close_wgt:
        wgt_file.close()

    f = open(local_wgt, "wb")
    file.seek(0)
    f.write(file.read())
    f.close()

    if not deploy_only:
        return add_resource_from_template(file_name, template, user, fromWGT=True, overrides=overrides)
开发者ID:Robinlovelace,项目名称:wirecloud,代码行数:47,代码来源:utils.py

示例6: update_resource_catalogue_cache

# 需要导入模块: from wirecloud.commons.utils.wgt import WgtFile [as 别名]
# 或者: from wirecloud.commons.utils.wgt.WgtFile import close [as 别名]
def update_resource_catalogue_cache(orm=None):

    if orm is not None:
        resources = orm.CatalogueResource.objects.all()
    else:
        resources = CatalogueResource.objects.all()

    resources_to_remove = []
    for resource in resources:

        try:

            if getattr(resource, "fromWGT", True):
                base_dir = wgt_deployer.get_base_dir(resource.vendor, resource.short_name, resource.version)
                wgt_file = WgtFile(os.path.join(base_dir, resource.template_uri))
                template = wgt_file.get_template()
                wgt_file.close()
            else:
                # fromWGT attribute support was removed from Wirecloud in version 0.7.0
                template = download_http_content(resource.template_uri)

            template_parser = TemplateParser(template)
            resource.json_description = json.dumps(template_parser.get_resource_info())
            resource.save()

        except (IOError, TemplateParseException) as e:

            if isinstance(e, IOError) and e.errno != errno.ENOENT:
                raise e

            resources_to_remove.append(resource)

    if (
        len(resources_to_remove) > 0
        and getattr(settings, "WIRECLOUD_REMOVE_UNSUPPORTED_RESOURCES_MIGRATION", False) is False
    ):
        raise Exception(
            "There are some mashable application components that are not supported anymore (use WIRECLOUD_REMOVE_UNSUPPORTED_RESOURCES_MIGRATION for removing automatically them in the migration process"
        )

    for resource in resources_to_remove:
        print("    Removing %s" % (resource.vendor + "/" + resource.short_name + "/" + resource.version))
        resource.delete()
开发者ID:GreenIDer-Donati,项目名称:wirecloud,代码行数:45,代码来源:utils.py

示例7: handle

# 需要导入模块: from wirecloud.commons.utils.wgt import WgtFile [as 别名]
# 或者: from wirecloud.commons.utils.wgt.WgtFile import close [as 别名]
    def handle(self, *args, **options):
        if len(args) < 1:
            raise CommandError(_('Wrong number of arguments'))

        user = None
        if not options['deploy_only']:
            user = User.objects.get(pk=1)

        for file_name in args:
            try:
                f = open(file_name, 'rb')
                wgt_file = WgtFile(f)
            except:
                print _('Failed to read from %(file_name)s') % {'file_name': file_name}
                continue

            try:
                template_contents = wgt_file.get_template()
                template = TemplateParser(template_contents)
                try:
                    add_widget_from_wgt(f, user, wgt_file=wgt_file, template=template, deploy_only=options['deploy_only'])
                except IntegrityError:
                    if not options['reinstall']:
                        raise
                    else:
                        old_resource = CatalogueResource.objects.get(vendor=template.get_resource_vendor(),
                            short_name=template.get_resource_name(),
                            version=template.get_resource_version()
                        )
                        delete_resource(old_resource, user)
                        add_widget_from_wgt(f, user, wgt_file=wgt_file, template=template)

                wgt_file.close()
                f.close()
                print _('Successfully imported %(name)s widget') % {'name': template.get_resource_name()}
            except IntegrityError:
                print _('Version %(version)s of the %(name)s widget (from %(vendor)s) already exists') % {
                    'name': template.get_resource_name(),
                    'version': template.get_resource_version(),
                    'vendor': template.get_resource_vendor(),
                }
            except:
                print _('Failed to import widget from %(file_name)s') % {'file_name': file_name}
开发者ID:Robinlovelace,项目名称:wirecloud,代码行数:45,代码来源:addtocatalogue.py

示例8: handle

# 需要导入模块: from wirecloud.commons.utils.wgt import WgtFile [as 别名]
# 或者: from wirecloud.commons.utils.wgt.WgtFile import close [as 别名]
    def handle(self, *args, **options):
        if len(args) < 1:
            raise CommandError(_('Wrong number of arguments'))

        if not options['deploy_only']:
            user = User.objects.get(pk=1)
        else:
            user = FakeUser('admin')

        for file_name in args:
            try:
                wgt_file = WgtFile(file_name)
            except:
                print _('Failed to parse %(file_name)s') % {'file_name': file_name}
                continue

            try:
                template_contents = wgt_file.get_template()
                template = TemplateParser(template_contents)
                try:
                    create_widget_from_wgt(wgt_file, user, deploy_only=options['deploy_only'])
                except IntegrityError:
                    if not options['reinstall']:
                        raise
                    else:
                        deleteWidget(user, template.get_resource_name(),
                            template.get_resource_vendor(),
                            template.get_resource_version()
                        )
                        create_widget_from_wgt(wgt_file, user)

                wgt_file.close()
                print _('Successfully imported %(name)s widget') % {'name': template.get_resource_name()}
            except IntegrityError:
                print _('Version %(version)s of the %(name)s widget (from %(vendor)s) already exists') % {
                    'name': template.get_resource_name(),
                    'version': template.get_resource_version(),
                    'vendor': template.get_resource_vendor(),
                }
            except:
                print _('Failed to import widget from %(file_name)s') % {'file_name': file_name}
开发者ID:ciniguez,项目名称:FIREWA,代码行数:43,代码来源:addtoshowcase.py

示例9: update_resource_catalogue_cache

# 需要导入模块: from wirecloud.commons.utils.wgt import WgtFile [as 别名]
# 或者: from wirecloud.commons.utils.wgt.WgtFile import close [as 别名]
def update_resource_catalogue_cache(orm=None):

    from wirecloud.catalogue.utils import wgt_deployer

    if orm is not None:
        resources = orm.CatalogueResource.objects.all()
    else:
        from wirecloud.catalogue.models import CatalogueResource
        resources = CatalogueResource.objects.all()

    for resource in resources:

        if resource.fromWGT:
            base_dir = wgt_deployer.get_base_dir(resource.vendor, resource.short_name, resource.version)
            wgt_file = WgtFile(os.path.join(base_dir, resource.template_uri))
            template = wgt_file.get_template()
            wgt_file.close()
        else:
            template = download_http_content(resource.template_uri)

        template_parser = TemplateParser(template)
        resource.json_description = json.dumps(template_parser.get_resource_info())
        resource.save()
开发者ID:caernel,项目名称:wirecloud,代码行数:25,代码来源:0004_refresh_resource_cache.py

示例10: add_packaged_resource

# 需要导入模块: from wirecloud.commons.utils.wgt import WgtFile [as 别名]
# 或者: from wirecloud.commons.utils.wgt.WgtFile import close [as 别名]
def add_packaged_resource(file, user, wgt_file=None, template=None, deploy_only=False):

    close_wgt = False
    if wgt_file is None:
        wgt_file = WgtFile(file)
        close_wgt = True

    if template is None:
        template_contents = wgt_file.get_template()
        template = TemplateParser(template_contents)

    resource_info = template.get_resource_info()
    if resource_info['type'] == 'widget':
        code_url = resource_info['contents']['src']
        if not code_url.startswith(('http://', 'https://')):

            try:
                code = wgt_file.read(code_url)
            except KeyError:
                msg = _('Missing contents file: %(file_name)s.')
                raise InvalidContents(msg % {'file_name': code_url})

            try:
                unicode(code, resource_info['contents']['charset'])
            except UnicodeDecodeError:
                msg = _('%(file_name)s was not encoded using the specified charset (%(charset)s according to the widget descriptor file).')
                raise InvalidContents(msg % {'file_name': code_url, 'charset': resource_info['contents']['charset']})

    resource_id = (
        template.get_resource_vendor(),
        template.get_resource_name(),
        template.get_resource_version(),
    )
    file_name = '_'.join(resource_id) + '.wgt'
    local_dir = wgt_deployer.get_base_dir(*resource_id)
    local_wgt = os.path.join(local_dir, file_name)

    if not os.path.exists(local_dir):
        os.makedirs(local_dir)

    overrides = extract_resource_media_from_package(template, wgt_file, local_dir)
    if close_wgt:
        wgt_file.close()

    f = open(local_wgt, "wb")
    file.seek(0)
    f.write(file.read())
    f.close()

    if not deploy_only:
        resource_info.update(overrides)

        resource = CatalogueResource.objects.create(
            short_name=resource_info['name'],
            vendor=resource_info['vendor'],
            version=resource_info['version'],
            type=CatalogueResource.RESOURCE_TYPES.index(resource_info['type']),
            creator=user,
            template_uri=file_name,
            creation_date=now(),
            popularity='0.0',
            json_description=json.dumps(resource_info)
        )

        return resource
开发者ID:rockneurotiko,项目名称:wirecloud,代码行数:67,代码来源:utils.py

示例11: add_packaged_resource

# 需要导入模块: from wirecloud.commons.utils.wgt import WgtFile [as 别名]
# 或者: from wirecloud.commons.utils.wgt.WgtFile import close [as 别名]
def add_packaged_resource(file, user, wgt_file=None, template=None, deploy_only=False):

    close_wgt = False
    if wgt_file is None:
        wgt_file = WgtFile(file)
        close_wgt = True

    if template is None:
        template_contents = wgt_file.get_template()
        template = TemplateParser(template_contents)

    resource_info = template.get_resource_info()
    if resource_info["type"] == "widget":
        code_url = resource_info["contents"]["src"]
        if not code_url.startswith(("http://", "https://")):

            try:
                code = wgt_file.read(code_url)
            except KeyError:
                msg = _("Missing contents file: %(file_name)s.")
                raise InvalidContents(msg % {"file_name": code_url})

            try:
                code.decode(resource_info["contents"]["charset"])
            except UnicodeDecodeError:
                msg = _(
                    "%(file_name)s was not encoded using the specified charset (%(charset)s according to the widget descriptor file)."
                )
                raise InvalidContents(msg % {"file_name": code_url, "charset": resource_info["contents"]["charset"]})

    check_invalid_doc_content(wgt_file, resource_info, "longdescription")
    check_invalid_doc_content(wgt_file, resource_info, "doc")
    check_invalid_doc_content(wgt_file, resource_info, "changelog")

    resource_id = (template.get_resource_vendor(), template.get_resource_name(), template.get_resource_version())
    file_name = "_".join(resource_id) + ".wgt"
    local_dir = wgt_deployer.get_base_dir(*resource_id)
    local_wgt = os.path.join(local_dir, file_name)

    if not os.path.exists(local_dir):
        os.makedirs(local_dir)

    overrides = extract_resource_media_from_package(template, wgt_file, local_dir)
    if close_wgt:
        wgt_file.close()

    f = open(local_wgt, "wb")
    file.seek(0)
    f.write(file.read())
    f.close()

    if not deploy_only:
        resource_info.update(overrides)

        resource = CatalogueResource.objects.create(
            short_name=resource_info["name"],
            vendor=resource_info["vendor"],
            version=resource_info["version"],
            type=CatalogueResource.RESOURCE_TYPES.index(resource_info["type"]),
            creator=user,
            template_uri=file_name,
            creation_date=now(),
            popularity="0.0",
            json_description=json.dumps(resource_info),
        )

        return resource
开发者ID:GreenIDer-Donati,项目名称:wirecloud,代码行数:69,代码来源:utils.py


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