def _parse_ac_request(request): fileURL = None file_contents = None content_type = get_content_type(request)[0] data = parse_json_request(request) if 'url' not in data: return build_error_response(request, 400, _('Missing widget URL')) fileURL = data.get('url') id_4CaaSt = data.get('4CaaStID') if id_4CaaSt is None: return build_error_response(request, 400, _('Missing 4CaaStID')) if not isinstance(id_4CaaSt, string_types) or id_4CaaSt.strip() == '': return build_error_response(request, 400, _('Invalid 4CaaStID')) try: downloaded_file = download_http_content(fileURL) except: return build_error_response( request, 409, _('Mashable application component could not be downloaded')) downloaded_file = StringIO(downloaded_file) file_contents = WgtFile(downloaded_file) # Create a custom version of the resource template = TemplateParser(file_contents.get_template()) template_info = template.get_resource_info() template_info['name'] += '@' + id_4CaaSt for pref_name, pref_value in six.iteritems(data.get('preferences', {})): for widget_pref_index, widget_pref in enumerate( template_info['preferences']): if widget_pref['name'] == pref_name: template_info['preferences'][widget_pref_index][ 'readonly'] = True template_info['preferences'][widget_pref_index][ 'value'] = pref_value break # Write a new Wgt file new_file = StringIO() zin = zipfile.ZipFile(downloaded_file, 'r') zout = zipfile.ZipFile(new_file, 'w') zout.writestr('config.xml', write_rdf_description(template_info)) for item in zin.infolist(): if item.filename == 'config.xml': continue zout.writestr(item, zin.read(item.filename)) zin.close() zout.close() file_contents = WgtFile(new_file) return id_4CaaSt, file_contents, fileURL
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)
def create_widget_on_resource_creation(sender, instance, created, raw, **kwargs): from wirecloud.catalogue import utils as catalogue from wirecloud.platform.widget.utils import create_widget_from_wgt if not created or raw: return resource = instance if resource.resource_type() == 'widget': try: resource.widget except Widget.DoesNotExist: base_dir = catalogue.wgt_deployer.get_base_dir( resource.vendor, resource.short_name, resource.version) wgt_file = WgtFile(os.path.join(base_dir, resource.template_uri)) resource.widget = create_widget_from_wgt(wgt_file, resource.creator) # Restore any iwidget associated with this widget from wirecloud.platform.iwidget.models import IWidget IWidget.objects.filter(widget_uri=resource.local_uri_part).update( widget=resource.widget)
def process(self, request, to_ws_id): to_ws = get_object_or_404(Workspace, id=to_ws_id) if not request.user.is_superuser and to_ws.creator != request.user: return build_error_response(request, 403, _('You are not allowed to update this workspace')) data = parse_json_request(request) mashup_id = data.get('mashup', '') workspace_id = data.get('workspace', '') if mashup_id == '' and workspace_id == '': return build_error_response(request, 422, _('Missing workspace or mashup parameter')) elif mashup_id != '' and workspace_id != '': return build_error_response(request, 422, _('Workspace and mashup parameters cannot be used at the same time')) if mashup_id != '': values = mashup_id.split('/', 3) if len(values) != 3: return build_error_response(request, 422, _('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(request.user) or resource.resource_type() != 'mashup': raise CatalogueResource.DoesNotExist except CatalogueResource.DoesNotExist: return build_error_response(request, 422, _('Mashup not found: %(mashup_id)s') % {'mashup_id': mashup_id}) 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()) else: from_ws = get_object_or_404(Workspace, id=workspace_id) if not request.user.is_superuser and from_ws.creator != request.user: return build_error_response(request, 403, _('You are not allowed to read from workspace %s') % workspace_id) options = { 'vendor': 'api', 'name': 'merge_op', 'version': '1.0', 'title': '', 'description': 'Temporal mashup for merging operation', 'email': '*****@*****.**', } template = TemplateParser(build_json_template_from_workspace(options, from_ws, from_ws.creator)) try: check_mashup_dependencies(template, request.user) except MissingDependencies as e: details = { 'missingDependencies': e.missing_dependencies, } return build_error_response(request, 422, e, details=details) fillWorkspaceUsingTemplate(to_ws, template) return HttpResponse(status=204)
def test_basic_packaged_widget_deployment(self): wgt_file = WgtFile( os.path.join(os.path.dirname(__file__), 'test-data', 'basic_widget.wgt')) catalogue_deployment_path = catalogue.wgt_deployer.get_base_dir( 'Wirecloud', 'Test', '0.1') deployment_path = wirecloud.platform.widget.utils.wgt_deployer.get_base_dir( 'Wirecloud', 'Test', '0.1') added, resource = install_resource_to_user(self.user, file_contents=wgt_file) resource.widget self.assertTrue(added) self.assertTrue(os.path.isdir(deployment_path)) self.assertTrue(os.path.isdir(catalogue_deployment_path)) self.assertTrue(resource.is_available_for(self.user)) resource.delete() self.assertRaises(CatalogueResource.DoesNotExist, CatalogueResource.objects.get, vendor='Wirecloud', short_name='Test', version='0.1') self.assertFalse(os.path.exists(deployment_path)) self.assertFalse(os.path.exists(catalogue_deployment_path))
def test_install_resource_restricted_authorized_user(self): file_contents = WgtFile( BytesIO( self.read_file("..", "..", "..", "commons", "test-data", "Wirecloud_Test_Selenium_1.0.wgt"))) install_resource(file_contents, self.user2, restricted=True)
def create(self, request): file_contents = None if request.mimetype == 'multipart/form-data': public = request.POST.get('public', 'true').strip().lower() == 'true' if 'file' not in request.FILES: return build_error_response( request, 400, _('Missing component file in the request')) downloaded_file = request.FILES['file'] else: # if request.mimetype == 'application/octet-stream' downloaded_file = BytesIO(request.body) public = request.GET.get('public', 'true').strip().lower() == 'true' try: file_contents = WgtFile(downloaded_file) except zipfile.BadZipfile: return build_error_response( request, 400, _('The uploaded file is not a zip file')) try: added, resource = install_component(file_contents, executor_user=request.user, public=public, users=(request.user, ), restricted=True) if not added: return build_error_response(request, 409, _('Resource already exists')) except OSError as e: if e.errno == errno.EACCES: return build_error_response( request, 500, _('Error writing the resource into the filesystem. Please, contact the server administrator.' )) else: raise except TemplateParseException as e: msg = "Error parsing config.xml descriptor file" return build_error_response(request, 400, msg, details=str(e)) except InvalidContents as e: details = e.details if hasattr(e, 'details') else None return build_error_response(request, 400, e, details=str(details)) response = HttpResponse(status=(201 if added else 204)) response['Location'] = resource.get_template_url() return response
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
def backwards(self, orm): for resource in orm['catalogue.CatalogueResource'].objects.filter( type=2, fromWGT=True): base_dir = catalogue_utils.wgt_deployer.get_base_dir( resource.vendor, resource.short_name, resource.version) wgt_file = WgtFile(os.path.join(base_dir, resource.template_uri)) catalogue_utils.wgt_deployer.deploy(wgt_file)
def populate(self, wirecloud_user, log): updated = False if not CatalogueResource.objects.filter(vendor="CoNWeT", short_name="bae-browser", version="0.1.1", public=True).exists(): updated = True log('Installing bae-browser widget... ', 1, ending='') install_resource_to_all_users( file_contents=WgtFile(BAE_BROWSER_WIDGET)) log('DONE', 1) if not CatalogueResource.objects.filter(vendor="CoNWeT", short_name="bae-details", version="0.1.1", public=True).exists(): updated = True log('Installing bae-details widget... ', 1, ending='') install_resource_to_all_users( file_contents=WgtFile(BAE_DETAILS_WIDGET)) log('DONE', 1) if not CatalogueResource.objects.filter( vendor="CoNWeT", short_name="bae-search-filters", version="0.1.1", public=True).exists(): updated = True log('Installing bae-search-filters widget... ', 1, ending='') install_resource_to_all_users( file_contents=WgtFile(BAE_SEARCH_FILTERS_WIDGET)) log('DONE', 1) if not CatalogueResource.objects.filter(vendor="CoNWeT", short_name="bae-marketplace", version="0.1.1", public=True).exists(): updated = True log('Installing bae-marketplace mashup... ', 1, ending='') install_resource_to_all_users(file_contents=WgtFile(BAE_MASHUP)) log('DONE', 1) return updated
def build_simple_wgt(self, other_files=()): f = BytesIO() zf = zipfile.ZipFile(f, 'w') zf.writestr('config.xml', b'') zf.writestr('test.html', b'') for of in other_files: zf.writestr(of, b'') zf.close() return WgtFile(f)
def test_mashup_with_invalid_embedded_resources(self): file_contents = WgtFile( BytesIO( self.read_file("..", "..", "..", "commons", "test-data", "Wirecloud_mashup-with-invalid-macs_1.0.wgt"))) try: install_resource_to_user(self.user, file_contents=file_contents) self.fail('InvalidContents exception not raised') except InvalidContents as e: self.assertIn('Invalid embedded file: ', e.message)
def test_install_resource_restricted_not_authorized_user(self): file_contents = WgtFile( BytesIO( self.read_file("..", "..", "..", "commons", "test-data", "Wirecloud_Test_Selenium_1.0.wgt"))) self.assertRaises(PermissionDenied, install_resource, file_contents, self.user, restricted=True)
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
def deploy_operators_on_resource_creation(sender, instance, created, raw, **kwargs): from wirecloud.catalogue import utils as catalogue_utils import wirecloud.platform.widget.utils as showcase_utils resource = instance if not created or raw or resource.resource_type() != 'operator': return base_dir = catalogue_utils.wgt_deployer.get_base_dir( resource.vendor, resource.short_name, resource.version) wgt_file = WgtFile(os.path.join(base_dir, resource.template_uri)) showcase_utils.wgt_deployer.deploy(wgt_file)
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()
def build_simple_wgt(self, template_name, html_content=None, other_files=()): template = self.read_file(template_name) f = BytesIO() zf = zipfile.ZipFile(f, 'w') zf.writestr('config.xml', template) zf.writestr('test.html', html_content or BASIC_HTML_GADGET_CODE) zf.writestr('doc/', b'') # TODO for of in other_files: zf.writestr(of, b'') zf.close() return WgtFile(f)
def prepare_temporal_resource_directories(cls): from django.conf import settings cls.tmp_dir = mkdtemp() # Whoosh indexes cls.old_index_dir = settings.WIRECLOUD_INDEX_DIR settings.WIRECLOUD_INDEX_DIR = os.path.join(cls.tmp_dir, 'whoosh_indexes') # catalogue deployer cls.old_catalogue_deployer = catalogue.wgt_deployer cls.catalogue_tmp_dir_backup = os.path.join(cls.tmp_dir, 'catalogue_backup') cls.catalogue_tmp_dir = os.path.join(cls.tmp_dir, 'catalogue') catalogue.wgt_deployer = WgtDeployer(cls.catalogue_tmp_dir) # showcase deployer cls.old_deployer = showcase.wgt_deployer cls.localcatalogue_tmp_dir_backup = os.path.join(cls.tmp_dir, 'localcatalogue_backup') cls.localcatalogue_tmp_dir = os.path.join(cls.tmp_dir, 'localcatalogue') showcase.wgt_deployer = WgtDeployer(cls.localcatalogue_tmp_dir) # deploy resource files for resource_file in cls.base_resources: resource_file = open( os.path.join(cls.shared_test_data_dir, resource_file), 'rb') resource_wgt = WgtFile(resource_file) catalogue.add_packaged_resource(resource_file, None, wgt_file=resource_wgt, deploy_only=True) showcase.wgt_deployer.deploy(resource_wgt) resource_file.close() # And freeze the resource files backup directories if os.path.exists(cls.localcatalogue_tmp_dir): os.rename(cls.localcatalogue_tmp_dir, cls.localcatalogue_tmp_dir_backup) else: os.mkdir(cls.localcatalogue_tmp_dir_backup) if os.path.exists(cls.catalogue_tmp_dir): os.rename(cls.catalogue_tmp_dir, cls.catalogue_tmp_dir_backup) else: os.mkdir(cls.catalogue_tmp_dir_backup)
def populate_component(self, wirecloud_user, log, vendor, name, version, wgt): if not CatalogueResource.objects.filter( vendor=vendor, short_name=name, version=version).exists(): updated = True log('Installing the %(name)s widget... ' % {"name": name}, 1, ending='') added, component = install_resource_to_user( wirecloud_user, file_contents=WgtFile(wgt)) IWidget.objects.filter( widget__resource__vendor=vendor, widget__resource__short_name=name).exclude( widget__resource__version=version).update( widget=component.widget, widget_uri=component.local_uri_part) log('DONE', 1)
def process(self, request): data = parse_json_request(request) (resource_vendor, resource_name, resource_version) = data['resource'].split('/') resource = get_object_or_404(CatalogueResource, vendor=resource_vendor, short_name=resource_name, version=resource_version) if not resource.is_available_for(request.user): return build_error_response( request, 403, _('You are not allowed to delete this market')) base_dir = catalogue.wgt_deployer.get_base_dir(resource_vendor, resource_name, resource_version) wgt_file = WgtFile(os.path.join(base_dir, resource.template_uri)) market_managers = get_market_managers(request.user) errors = {} for market_endpoint in data['marketplaces']: try: market_managers[market_endpoint['market']].publish( market_endpoint, wgt_file, request.user, request=request) except Exception as e: errors[market_endpoint['market']] = text_type(e) if len(errors) == 0: return HttpResponse(status=204) elif len(errors) == len(data['marketplaces']): return build_error_response( request, 502, _('Something went wrong (see details for more info)'), details=errors) else: return build_error_response( request, 200, _('Something went wrong (see details for more info)'), details=errors)
def create_widget_on_resource_creation(sender, instance, created, raw, **kwargs): from wirecloud.catalogue import utils as catalogue from wirecloud.platform.widget.utils import create_widget_from_wgt if not created or raw: return resource = instance if resource.resource_type() == 'widget': try: resource.widget except Widget.DoesNotExist: base_dir = catalogue.wgt_deployer.get_base_dir( resource.vendor, resource.short_name, resource.version) wgt_file = WgtFile(os.path.join(base_dir, resource.template_uri)) resource.widget = create_widget_from_wgt(wgt_file, resource.creator)
def test_invalid_packaged_widget_deployment(self): wgt_file = WgtFile( os.path.join(os.path.dirname(__file__), 'test-data', 'invalid_widget.wgt')) catalogue_deployment_path = catalogue.wgt_deployer.get_base_dir( 'Wirecloud', 'Test', '0.1') deployment_path = wirecloud.platform.widget.utils.wgt_deployer.get_base_dir( 'Wirecloud', 'Test', '0.1') self.assertRaises(TemplateParseException, install_resource, wgt_file, self.user) self.assertRaises(CatalogueResource.DoesNotExist, CatalogueResource.objects.get, vendor='Wirecloud', short_name='Test', version='0.1') self.assertFalse(os.path.exists(deployment_path)) self.assertFalse(os.path.exists(catalogue_deployment_path))
def check_invalid_embedded_resources(wgt_file, resource_info): if resource_info['type'] != 'mashup': return files = wgt_file.namelist() for embedded_resource in resource_info['embedded']: if embedded_resource['src'] not in files: raise InvalidContents('Missing embedded file: %s' % embedded_resource['src']) try: embedded_wgt = WgtFile( BytesIO(wgt_file.read(embedded_resource['src']))) check_packaged_resource(embedded_wgt) except Exception as e: raise InvalidContents('Invalid embedded file: %s' % embedded_resource['src'], details=e)
def populate_component(self, wirecloud_user, log, vendor, name, version, wgt): if not CatalogueResource.objects.filter( vendor=vendor, short_name=name, version=version).exists(): log('Installing the %(name)s widget... ' % {"name": name}, 1, ending='') added, component = install_component(WgtFile(wgt), executor_user=wirecloud_user, users=[wirecloud_user]) IWidget.objects.filter( widget__resource__vendor=vendor, widget__resource__short_name=name).exclude( widget__resource__version=version).update( widget=component.widget, widget_uri=component.local_uri_part) log('DONE', 1) return True return False
def test_basic_packaged_mashup_deployment(self): wgt_file = WgtFile( os.path.join(os.path.dirname(wirecloud.commons.__file__), 'test-data', 'Wirecloud_PackagedTestMashup_1.0.zip')) deployment_path = catalogue.wgt_deployer.get_base_dir( 'Wirecloud', 'PackagedTestMashup', '1.0') install_resource_to_user(self.user, file_contents=wgt_file) resource = CatalogueResource.objects.get( vendor='Wirecloud', short_name='PackagedTestMashup', version='1.0') self.assertTrue(os.path.isdir(deployment_path)) resource.delete() self.assertRaises(CatalogueResource.DoesNotExist, CatalogueResource.objects.get, vendor='Wirecloud', short_name='PackagedTestMashup', version='1.0') self.assertFalse(os.path.exists(deployment_path))
def prepare_temporal_resource_directories(cls): cls.tmp_dir = mkdtemp() # catalogue deployer cls.old_catalogue_deployer = catalogue.wgt_deployer._root_dir cls.catalogue_tmp_dir_backup = os.path.join(cls.tmp_dir, 'catalogue_backup') cls.catalogue_tmp_dir = os.path.join(cls.tmp_dir, 'catalogue') catalogue.wgt_deployer._root_dir = cls.catalogue_tmp_dir # showcase deployer cls.old_deployer = showcase.wgt_deployer._root_dir cls.localcatalogue_tmp_dir_backup = os.path.join(cls.tmp_dir, 'localcatalogue_backup') cls.localcatalogue_tmp_dir = os.path.join(cls.tmp_dir, 'localcatalogue') showcase.wgt_deployer._root_dir = cls.localcatalogue_tmp_dir # deploy resource files for resource_file in cls.base_resources: resource_file = open( os.path.join(cls.shared_test_data_dir, resource_file), 'rb') resource_wgt = WgtFile(resource_file) catalogue.add_packaged_resource(resource_file, None, wgt_file=resource_wgt, deploy_only=True) showcase.wgt_deployer.deploy(resource_wgt) resource_file.close() # And freeze the resource files backup directories if os.path.exists(cls.localcatalogue_tmp_dir): os.rename(cls.localcatalogue_tmp_dir, cls.localcatalogue_tmp_dir_backup) else: os.mkdir(cls.localcatalogue_tmp_dir_backup) if os.path.exists(cls.catalogue_tmp_dir): os.rename(cls.catalogue_tmp_dir, cls.catalogue_tmp_dir_backup) else: os.mkdir(cls.catalogue_tmp_dir_backup)
def test_basic_packaged_operator_deployment(self): wgt_file = WgtFile( os.path.join(os.path.dirname(wirecloud.commons.__file__), 'test-data', 'Wirecloud_TestOperator_1.0.zip')) deployment_path = catalogue.wgt_deployer.get_base_dir( 'Wirecloud', 'TestOperator', '1.0') install_component(wgt_file, users=[self.user]) resource = CatalogueResource.objects.get(vendor='Wirecloud', short_name='TestOperator', version='1.0') self.assertTrue(os.path.isdir(deployment_path)) resource.delete() self.assertRaises(CatalogueResource.DoesNotExist, CatalogueResource.objects.get, vendor='Wirecloud', short_name='TestOperator', version='1.0') self.assertFalse(os.path.exists(deployment_path))
def wrapper(self, *args, **kwargs): if shared: base = self.shared_test_data_dir else: base = self.test_data_dir final_creator = User.objects.get( username=creator) if creator is not None else None final_users = tuple( User.objects.get(username=user) for user in users) final_groups = tuple( Group.objects.get(name=group) for group in groups) for resource in resources: wgt_file = open(os.path.join(base, resource), 'rb') wgt = WgtFile(wgt_file) fix_dev_version(wgt, final_creator) if deploy_only: catalogue.add_packaged_resource(wgt.get_underlying_file(), final_creator, wgt_file=wgt, deploy_only=True) wgt_file.close() continue resource = install_resource(wgt, final_creator) if public: resource.public = True resource.save() resource.users.add(*final_users) resource.groups.add(*final_groups) wgt_file.close() return test_func(self, *args, **kwargs)
def _handle(self, *args, **options): updated = False self.verbosity = int(options.get('verbosity', 1)) with atomic(): wirecloud_user, created = User.objects.get_or_create( username='******', defaults={'password': '******'}) if created: updated = True self.log('Creating a wirecloud user... DONE', 1) if not CatalogueResource.objects.filter( vendor="WireCloud", short_name="workspace-browser", version="0.1.1").exists(): updated = True self.log('Installing the workspace-browser widget... ', 1, ending='') install_resource_to_user( wirecloud_user, file_contents=WgtFile(WORKSPACE_BROWSER)) self.log('DONE', 1) if not Workspace.objects.filter(creator__username="******", name="home").exists(): updated = True self.log( 'Creating a initial version of the wirecloud/home workspace... ', 1, ending='') with open(INITIAL_HOME_DASHBOARD_FILE, 'rb') as f: workspace = create_workspace(wirecloud_user, f) workspace.public = True workspace.save() self.log('DONE', 1) if not updated: self.log('Already up-to-date.', 1)
def wrapper(self, *args, **kwargs): if shared: base = self.shared_test_data_dir else: base = self.test_data_dir for resource in resources: wgt_file = open(os.path.join(base, resource), 'rb') wgt = WgtFile(wgt_file) if deploy_only: catalogue.add_packaged_resource(wgt_file, None, wgt_file=wgt, deploy_only=True) wgt_file.close() continue resource = install_resource(wgt, None) if public: resource.public = True resource.save() final_users = (User.objects.get(username=user) for user in users) resource.users.add(*final_users) final_groups = (Group.objects.get(name=group) for group in groups) resource.groups.add(*final_groups) wgt_file.close() return test_func(self, *args, **kwargs)