Ejemplo n.º 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)
Ejemplo n.º 2
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)
Ejemplo n.º 3
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'])

        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)
Ejemplo n.º 4
0
def fix_dev_version(wgt_file, user):

    template_contents = wgt_file.get_template()
    template = TemplateParser(template_contents)

    resource_info = template.get_resource_info()

    # Add user name to the version if the component is in development
    if '-dev' in resource_info['version']:

        # User name added this way to prevent users to upload a version
        # *.*-devAnotherUser that would be accepted but might collide with
        # AnotherUser's development version
        resource_info['version'] = re.sub('-dev.*$', '-dev' + user.username, resource_info['version'])
        template_string = write_json_description(resource_info)
        wgt_file.update_config(template_string)
Ejemplo n.º 5
0
def fix_dev_version(wgt_file, user):

    template_contents = wgt_file.get_template()
    template = TemplateParser(template_contents)

    resource_info = template.get_resource_info()

    # Add user name to the version if the component is in development
    if '-dev' in resource_info['version']:

        # User name added this way to prevent users to upload a version
        # *.*-devAnotherUser that would be accepted but might collide with
        # AnotherUser's development version
        resource_info['version'] = re.sub('-dev.*$', '-dev' + user.username, resource_info['version'])
        template_string = write_json_description(resource_info)
        wgt_file.update_config(template_string)
Ejemplo n.º 6
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"):
            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)

        if len(args) == 2:
            output_file = open(args[1], "wb")
            output_file.write(converted_template)
            output_file.close()
        else:
            print(converted_template)