コード例 #1
0
    def handle(self, *args, **options):
        if len(args) < 1 or len(args) > 2:
            raise CommandError('Wrong number of arguments')

        if options['dest_format'] not in ('json', 'rdf', 'xml'):
            raise CommandError('Invalid dest format: %s' %
                               options['dest_format'])

        try:
            template_file = open(args[0], "rb")
            template_contents = template_file.read()
            template_file.close()
            parsed_template = TemplateParser(template_contents)
            template_info = parsed_template.get_resource_info()
        except IOError as e:
            msg = 'Error opening description file: %s' % os.strerror(e.errno)
            raise CommandError(msg)

        if options['dest_format'] == 'rdf':
            converted_template = rdf.write_rdf_description(
                template_info, format=options['rdf_format'])
        elif options['dest_format'] == 'json':
            converted_template = json.write_json_description(template_info)
        else:  # if options['dest_format'] == 'xml':
            converted_template = xml.write_xml_description(template_info)

        if len(args) == 2:
            with open(args[1], "wb") as output_file:
                output_file.write(converted_template.encode('utf-8'))
        else:
            self.stdout.write(converted_template)
コード例 #2
0
        def wrapper(self, *args, **kwargs):

            owner_user = User.objects.get(username=owner)

            if shared:
                base = self.shared_test_data_dir
            else:
                base = self.test_data_dir

            with open(os.path.join(base, file_name), 'rb') as f:
                wgt = WgtFile(f)
                template = TemplateParser(wgt.get_template())

                resource_info = template.get_resource_processed_info(
                    process_urls=False)
                if resource_info["type"] != 'mashup':
                    raise Exception

                for embedded_resource in resource_info['embedded']:
                    if embedded_resource['src'].startswith('https://'):
                        resource_file = download_http_content(
                            embedded_resource['src'])
                    else:
                        resource_file = BytesIO(
                            wgt.read(embedded_resource['src']))

                    extra_resource_contents = WgtFile(resource_file)
                    install_resource_to_user(
                        owner_user, file_contents=extra_resource_contents)

                buildWorkspaceFromTemplate(template, owner_user)

            return test_func(self, *args, **kwargs)
コード例 #3
0
ファイル: models.py プロジェクト: yasuhi526/wirecloud
    def get_template(self,
                     request=None,
                     url_pattern_name='wirecloud_catalogue.media'):

        template_uri = self.get_template_url(request=request,
                                             url_pattern_name=url_pattern_name)
        parser = TemplateParser(self.json_description, base=template_uri)
        return parser
コード例 #4
0
def create_workspace(owner, f):

    from wirecloud.platform.workspace.mashupTemplateParser import buildWorkspaceFromTemplate

    wgt = f if isinstance(f, WgtFile) else WgtFile(f)
    template = TemplateParser(wgt.get_template())

    resource_info = template.get_resource_processed_info(process_urls=False)
    if resource_info["type"] != 'mashup':
        raise Exception

    for embedded_resource in resource_info['embedded']:
        if embedded_resource['src'].startswith('https://'):
            resource_file = download_http_content(embedded_resource['src'])
        else:
            resource_file = BytesIO(wgt.read(embedded_resource['src']))

        extra_resource_contents = WgtFile(resource_file)
        install_resource_to_user(owner, file_contents=extra_resource_contents)

    workspace, _ = buildWorkspaceFromTemplate(template, owner)
    return workspace
コード例 #5
0
ファイル: utils.py プロジェクト: yasuhi526/wirecloud
def create_workspace(owner,
                     f=None,
                     mashup=None,
                     new_name=None,
                     new_title=None,
                     preferences={},
                     searchable=True,
                     public=False):

    from wirecloud.platform.workspace.mashupTemplateParser import buildWorkspaceFromTemplate

    if mashup is not None and f is not None:
        raise Exception

    if f is not None:

        wgt = f if isinstance(f, WgtFile) else WgtFile(f)
        template = TemplateParser(wgt.get_template())

        resource_info = template.get_resource_processed_info(
            process_urls=False)
        if resource_info["type"] != 'mashup':
            raise Exception

        for embedded_resource in resource_info['embedded']:
            if embedded_resource['src'].startswith('https://'):
                resource_file = download_http_content(embedded_resource['src'])
            else:
                resource_file = BytesIO(wgt.read(embedded_resource['src']))

            extra_resource_contents = WgtFile(resource_file)
            install_resource_to_user(owner,
                                     file_contents=extra_resource_contents)
    else:
        values = mashup.split('/', 3)
        if len(values) != 3:
            raise TypeError(_('invalid mashup id'))

        (mashup_vendor, mashup_name, mashup_version) = values
        try:
            resource = CatalogueResource.objects.get(vendor=mashup_vendor,
                                                     short_name=mashup_name,
                                                     version=mashup_version)
            if not resource.is_available_for(
                    owner) or resource.resource_type() != 'mashup':
                raise CatalogueResource.DoesNotExist
        except CatalogueResource.DoesNotExist:
            raise Exception(
                _('Mashup not found: %(mashup)s') % {'mashup': mashup})

        base_dir = catalogue.wgt_deployer.get_base_dir(mashup_vendor,
                                                       mashup_name,
                                                       mashup_version)
        wgt_file = WgtFile(os.path.join(base_dir, resource.template_uri))
        template = TemplateParser(wgt_file.get_template())

    workspace, _foo = buildWorkspaceFromTemplate(template,
                                                 owner,
                                                 new_name=new_name,
                                                 new_title=new_title,
                                                 searchable=searchable,
                                                 public=public)

    if len(preferences) > 0:
        update_workspace_preferences(workspace,
                                     preferences,
                                     invalidate_cache=False)

    return workspace
コード例 #6
0
    def get_template(self, request=None):

        template_uri = self.get_template_url(request=request)
        parser = TemplateParser(self.json_description, base=template_uri)
        return parser