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)
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)
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']) 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() 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) elif options['dest_format'] == 'xml': converted_template = xml.write_xml_description(template_info) if len(args) == 2: output_file = open(args[1], "wb") output_file.write(converted_template) output_file.close() else: print(converted_template)
def test_xml_parser_writer_widget(self): xml_description = write_xml_description(self.widget_info) template = TemplateParser(xml_description) processed_info = template.get_resource_info() self.assertEqual(processed_info, self.widget_info)
def build_xml_template_from_workspace(options, workspace, user, raw=False): build_json_template_from_workspace(options, workspace, user) return xml.write_xml_description(options, raw=raw)
def build_xml_template_from_workspace(options, workspace, user, raw=False): build_json_template_from_workspace(options, workspace, user) return xml.write_xml_description(options, raw=raw)