コード例 #1
0
def buildWorkspaceFromTemplate(template, user, allow_renaming=False, new_name=None, new_title=None, searchable=True, public=False):

    if not isinstance(template, TemplateParser):
        template = TemplateParser(template)

    if template.get_resource_type() != 'mashup':
        raise TypeError('Unsupported resource type: %s' % template.get_resource_type())

    if (new_name is None or new_name.strip() == '') and (new_title is None or new_title.strip() == ''):
        processed_info = template.get_resource_processed_info(process_urls=False)
        new_name = processed_info['name']
        new_title = processed_info['title']
    elif new_title is None or new_title.strip() == '':
        new_title = new_name
    elif new_name is None or new_name.strip() == '':
        new_name = URLify(new_title)

    # Workspace creation
    workspace = Workspace(title=new_title, name=new_name, creator=user, searchable=searchable, public=public)
    if allow_renaming:
        save_alternative(Workspace, 'name', workspace)
    else:
        workspace.save()

    # Adding user reference to workspace in the many to many relationship
    user_workspace = UserWorkspace(user=user, workspace=workspace)
    user_workspace.save()

    fillWorkspaceUsingTemplate(workspace, template)

    return (workspace, user_workspace)
コード例 #2
0
def buildWorkspaceFromTemplate(template,
                               user,
                               allow_renaming=False,
                               new_name=None):

    if not isinstance(template, TemplateParser):
        template = TemplateParser(template)

    if template.get_resource_type() != 'mashup':
        raise TypeError('Unsupported resource type: %s' %
                        template.get_resource_type())

    if new_name is not None:
        name = new_name
    else:
        name = template.get_resource_processed_info(
            process_urls=False)['title']

    # Workspace creation
    workspace = Workspace(name=name, creator=user)
    if allow_renaming:
        save_alternative(Workspace, 'name', workspace)
    else:
        workspace.save()

    # Adding user reference to workspace in the many to many relationship
    user_workspace = UserWorkspace(user=user,
                                   workspace=workspace,
                                   active=False)
    user_workspace.save()

    fillWorkspaceUsingTemplate(workspace, template)

    return (workspace, user_workspace)
コード例 #3
0
def buildWorkspaceFromTemplate(template, user, allow_renaming=False, new_name=None):

    if not isinstance(template, TemplateParser):
        template = TemplateParser(template)

    if template.get_resource_type() != 'mashup':
        raise TypeError('Unsupported resource type: %s' % template.get_resource_type())

    if new_name is not None:
        name = new_name
    else:
        name = template.get_resource_processed_info(process_urls=False)['title']

    # Workspace creation
    workspace = Workspace(name=name, creator=user)
    if allow_renaming:
        save_alternative(Workspace, 'name', workspace)
    else:
        workspace.save()

    # Adding user reference to workspace in the many to many relationship
    user_workspace = UserWorkspace(user=user, workspace=workspace, active=False)
    user_workspace.save()

    fillWorkspaceUsingTemplate(workspace, template)

    return (workspace, user_workspace)
コード例 #4
0
def buildWorkspaceFromTemplate(template, user, allow_renaming=False, new_name=None, new_title=None, searchable=True, public=False):

    if not isinstance(template, TemplateParser):
        template = TemplateParser(template)

    if template.get_resource_type() != 'mashup':
        raise TypeError('Unsupported resource type: %s' % template.get_resource_type())

    if (new_name is None or new_name.strip() == '') and (new_title is None or new_title.strip() == ''):
        processed_info = template.get_resource_processed_info(process_urls=False)
        new_name = processed_info['name']
        new_title = processed_info['title']
    elif new_title is None or new_title.strip() == '':
        new_title = new_name
    elif new_name is None or new_name.strip() == '':
        new_name = URLify(new_title)

    # Workspace creation
    workspace = Workspace(title=new_title, name=new_name, creator=user, searchable=searchable, public=public)
    if allow_renaming:
        save_alternative(Workspace, 'name', workspace)
    else:
        workspace.save()

    # Adding user reference to workspace in the many to many relationship
    user_workspace = UserWorkspace(user=user, workspace=workspace)
    user_workspace.save()

    fillWorkspaceUsingTemplate(workspace, template)

    return (workspace, user_workspace)
コード例 #5
0
    def publish(self, endpoint, wgt_file, user, request=None, template=None):

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

        resource_info = template.get_resource_processed_info(lang='en')

        mimetypes = {
            'widget': 'application/x-widget+mashable-application-component',
            'operator': 'application/x-operator+mashable-application-component',
            'mashup': 'application/x-mashup+mashable-application-component',
        }

        store = endpoint['store']
        adaptor = get_market_adaptor(self._user, self._name)
        user_data = get_market_user_data(user, self._user, self._name)
        storeclient = adaptor.get_store(store)

        store_token_key = store + '/token'
        if store_token_key in user_data:
            token = user_data[store_token_key]
        else:
            token = user_data['idm_token']

        wirecloud_plugin_supported = False
        try:
            supported_plugins = storeclient.get_supported_plugins(token)
            for plugin in supported_plugins:
                if plugin.get('name', '').lower() == 'wirecloud component':
                    wirecloud_plugin_supported = True
        except UnexpectedResponse as e:
            if e.status != 404:
                raise e

        if wirecloud_plugin_supported:
            storeclient.upload_resource(
                    resource_info['title'],
                    resource_info['version'],
                    "_".join((resource_info['vendor'], resource_info['name'], resource_info['version'])) + '.wgt',
                    resource_info['description'],
                    "Mashable application component",
                    wgt_file.get_underlying_file(),
                    token,
                    resource_type="Wirecloud component")
        else:
            storeclient.upload_resource(
                    resource_info['title'],
                    resource_info['version'],
                    "_".join((resource_info['vendor'], resource_info['name'], resource_info['version'])) + '.wgt',
                    resource_info['description'],
                    mimetypes[resource_info['type']],
                    wgt_file.get_underlying_file(),
                    token)
コード例 #6
0
    def publish(self, endpoint, wgt_file, user, request=None, template=None):

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

        resource_info = template.get_resource_processed_info(lang='en')

        mimetypes = {
            'widget': 'application/x-widget+mashable-application-component',
            'operator':
            'application/x-operator+mashable-application-component',
            'mashup': 'application/x-mashup+mashable-application-component',
        }

        store = endpoint['store']
        adaptor = get_market_adaptor(self._user, self._name)
        user_data = get_market_user_data(user, self._user, self._name)
        storeclient = adaptor.get_store(store)

        store_token_key = store + '/token'
        if store_token_key in user_data:
            token = user_data[store_token_key]
        else:
            token = user_data['idm_token']

        wirecloud_plugin_supported = False
        try:
            supported_plugins = storeclient.get_supported_plugins(token)
            for plugin in supported_plugins:
                if plugin.get('name', '').lower() == 'wirecloud component':
                    wirecloud_plugin_supported = True
        except UnexpectedResponse as e:
            if e.status != 404:
                raise e

        if wirecloud_plugin_supported:
            storeclient.upload_resource(
                resource_info['title'],
                resource_info['version'],
                "_".join((resource_info['vendor'], resource_info['name'],
                          resource_info['version'])) + '.wgt',
                resource_info['description'],
                "Mashable application component",
                wgt_file.get_underlying_file(),
                token,
                resource_type="Wirecloud component")
        else:
            storeclient.upload_resource(
                resource_info['title'], resource_info['version'], "_".join(
                    (resource_info['vendor'], resource_info['name'],
                     resource_info['version'])) + '.wgt',
                resource_info['description'], mimetypes[resource_info['type']],
                wgt_file.get_underlying_file(), token)
コード例 #7
0
    def _handle(self, *args, **options):

        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 options['files']:
            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:
                    install_component(wgt_file,
                                      public=public,
                                      users=users,
                                      groups=groups)

                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)
コード例 #8
0
ファイル: addtocatalogue.py プロジェクト: perezdf/wirecloud
    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)