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)
def test_install_resource_to_group(self): wgt_file = self.build_simple_wgt('template1.xml', b'code', other_files=('images/catalogue.png', 'images/catalogue_iphone.png', 'doc/index.html')) added, resource = install_resource_to_group(self.group, file_contents=wgt_file) self.assertTrue(added) self.assertTrue(resource.is_available_for(self.user)) self.assertTrue(resource.is_available_for(self.user2))
def test_install_resource_to_group_duplicated(self): resource = CatalogueResource.objects.get(vendor='Test', short_name='Test Widget', version='1.0.0') resource.groups.add(self.group) wgt_file = self.build_simple_wgt('template10.xml', b'code') added, resource = install_resource_to_group(self.group, file_contents=wgt_file) self.assertFalse(added) self.assertTrue(resource.is_available_for(self.user)) self.assertTrue(resource.is_available_for(self.user2))
def test_install_resource_to_group(self): wgt_file = self.build_simple_wgt('template1.xml', b'code', other_files=('doc/index.html', )) added, resource = install_resource_to_group(self.group, file_contents=wgt_file) self.assertTrue(added) self.assertTrue(resource.is_available_for(self.user)) self.assertTrue(resource.is_available_for(self.user2))
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)