Ejemplo n.º 1
0
def processOption(options, field, required=False, type='string'):
    if options.get(field, None) is None:
        if required:
            raise Exception(_('Missing %s option') % field)
        else:
            return None
    else:
        if type == 'string':
            return six.text_type(options[field])
        elif type == 'boolean':
            return 'true' if options[field] else 'false'
        elif type == 'people':
            return stringify_contact_info(options[field])
Ejemplo n.º 2
0
def processOption(options, field, required=False, type='string'):
    if options.get(field, None) is None:
        if required:
            raise Exception(_('Missing %s option') % field)
        else:
            return None
    else:
        if type == 'string':
            return six.text_type(options[field])
        elif type == 'boolean':
            return 'true' if options[field] else 'false'
        elif type == 'people':
            return stringify_contact_info(options[field])
Ejemplo n.º 3
0
def processOption(options, field, required=False, type='string'):
    if field not in options:
        if required:
            raise Exception(_('Missing %s option') % field)
        else:
            return None
    else:
        if type == 'string':
            return unicode(options[field])
        elif type == 'boolean':
            return 'true' if options[field] else 'false'
        elif type == 'people':
            return stringify_contact_info(options[field])
Ejemplo n.º 4
0
def build_xml_document(options):

    template = etree.Element('Template', xmlns="http://wirecloud.conwet.fi.upm.es/ns/template#")
    desc = etree.Element('Catalog.ResourceDescription')
    template.append(desc)
    etree.SubElement(desc, 'Vendor').text = options.get('vendor')
    etree.SubElement(desc, 'Name').text = options.get('name')
    etree.SubElement(desc, 'Version').text = options.get('version')
    etree.SubElement(desc, 'DisplayName').text = options.get('title')

    authors = options.get('authors', ())
    if len(authors) > 0:
        etree.SubElement(desc, 'Author').text = stringify_contact_info(authors)

    contributors = options.get('contributors', ())
    if len(contributors) > 0:
        etree.SubElement(desc, 'Contributors').text = stringify_contact_info(contributors)

    etree.SubElement(desc, 'Mail').text = options.get('email')
    etree.SubElement(desc, 'LongDescription').text = options.get('longdescription')
    etree.SubElement(desc, 'Description').text = options.get('description')
    etree.SubElement(desc, 'ImageURI').text = options.get('image', '')
    etree.SubElement(desc, 'iPhoneImageURI').text = options.get('smartphoneimage', '')
    etree.SubElement(desc, 'Homepage').text = options.get('homepage', '')
    etree.SubElement(desc, 'WikiURI').text = options.get('doc', '')
    etree.SubElement(desc, 'License').text = options.get('license', '')
    etree.SubElement(desc, 'LicenseURL').text = options.get('licenseurl', '')
    etree.SubElement(desc, 'IssueTracker').text = options.get('issuetracker', '')
    etree.SubElement(desc, 'ChangeLogURL').text = options.get('changelog', '')

    if len(options['requirements']) > 0:
        requirements = etree.SubElement(desc, 'Requirements')
        for requirement in options['requirements']:
            etree.SubElement(requirements, 'Feature', name=requirement['name'])

    if options['type'] == 'mashup':
        resources = etree.SubElement(desc, 'IncludedResources')
        for pref_name, pref_value in six.iteritems(options['preferences']):
            etree.SubElement(resources, 'Preference', name=pref_name, value=pref_value)
    else:

        if len(options['preferences']) > 0:

            preferences_element = etree.SubElement(template, 'Platform.Preferences')
            for pref in options['preferences']:
                pref_element = etree.SubElement(preferences_element, 'Preference',
                    name=pref['name'],
                    type=pref['type'],
                    label=pref['label'],
                    description=pref['description'],
                    readonly=str(pref['readonly']).lower(),
                    default=pref['default'])

                if pref['secure']:
                    pref_element.set('secure', 'true')

                if pref['type'] == 'list':
                    for option in pref['options']:
                        etree.SubElement(pref_element, 'Option', label=option['label'], value=option['value'])

                if pref['value'] is not None:
                    pref_element.set('value', pref['value'])

        if len(options['properties']) > 0:

            properties_element = etree.SubElement(template, 'Platform.StateProperties')
            for prop in options['properties']:
                etree.SubElement(properties_element, 'Property',
                    name=prop['name'],
                    type=prop['type'],
                    label=prop['label'],
                    description=prop['description'],
                    default=prop['default'],
                    secure=str(prop['secure']).lower())

    if options['type'] == 'mashup':
        write_mashup_tree(resources, options)

    # Wiring info
    wiring = etree.SubElement(template, 'Platform.Wiring')

    for output_endpoint in options['wiring']['outputs']:
        etree.SubElement(wiring, 'OutputEndpoint',
                name=output_endpoint['name'],
                type=output_endpoint['type'],
                label=output_endpoint['label'],
                description=output_endpoint['description'],
                friendcode=output_endpoint['friendcode'])

    for input_endpoint in options['wiring']['inputs']:
        etree.SubElement(wiring, 'InputEndpoint',
                name=input_endpoint['name'],
                type=input_endpoint['type'],
                label=input_endpoint['label'],
                description=input_endpoint['description'],
                actionlabel=input_endpoint['actionlabel'],
                friendcode=input_endpoint['friendcode'])

    if options['type'] == 'mashup':
        write_mashup_wiring_tree(wiring, options)
    else:
        # Widget code
        link = etree.SubElement(template, 'Platform.Link')
        xhtml = etree.SubElement(link, 'XHTML', href=options['contents']['src'])
        xhtml.set('content-type', options['contents']['contenttype'])
        xhtml.set('charset', options['contents']['charset'])
        if options['contents']['cacheable'] is False:
            xhtml.set('cacheable', 'false')
        if options['contents']['useplatformstyle']:
            xhtml.set('use-platform-style', 'true')

        for altcontents in options['altcontents']:
            altcontents_element = etree.SubElement(link, 'AltContents', scope=altcontents['scope'], href=altcontents['src'])
            altcontents_element.set('content-type', altcontents['contenttype'])
            altcontents_element.set('charset', altcontents['charset'])

        # Widget rendering
        etree.SubElement(template, 'Platform.Rendering', width=options['widget_width'], height=options['widget_height'])

    # Translations
    if len(options['translations']) > 0:

        translations_element = etree.SubElement(template, 'Translations', default=options['default_lang'])

        for lang, catalogue in six.iteritems(options['translations']):
            catalogue_element = etree.SubElement(translations_element, 'Translation', lang=lang)

            for msg_name, msg in six.iteritems(catalogue):
                msg_element = etree.SubElement(catalogue_element, 'msg', name=msg_name)
                msg_element.text = msg

    return template
Ejemplo n.º 5
0
def build_xml_document(options):

    template = etree.Element(
        'Template', xmlns="http://wirecloud.conwet.fi.upm.es/ns/template#")
    desc = etree.Element('Catalog.ResourceDescription')
    template.append(desc)
    etree.SubElement(desc, 'Vendor').text = options.get('vendor')
    etree.SubElement(desc, 'Name').text = options.get('name')
    etree.SubElement(desc, 'Version').text = options.get('version')
    etree.SubElement(desc, 'DisplayName').text = options.get('title')

    authors = options.get('authors', ())
    if len(authors) > 0:
        etree.SubElement(desc, 'Author').text = stringify_contact_info(authors)

    contributors = options.get('contributors', ())
    if len(contributors) > 0:
        etree.SubElement(
            desc, 'Contributors').text = stringify_contact_info(contributors)

    etree.SubElement(desc, 'Mail').text = options.get('email')
    etree.SubElement(desc,
                     'LongDescription').text = options.get('longdescription')
    etree.SubElement(desc, 'Description').text = options.get('description')
    etree.SubElement(desc, 'ImageURI').text = options.get('image', '')
    etree.SubElement(desc, 'iPhoneImageURI').text = options.get(
        'smartphoneimage', '')
    etree.SubElement(desc, 'Homepage').text = options.get('homepage', '')
    etree.SubElement(desc, 'WikiURI').text = options.get('doc', '')
    etree.SubElement(desc, 'License').text = options.get('license', '')
    etree.SubElement(desc, 'LicenseURL').text = options.get('licenseurl', '')
    etree.SubElement(desc,
                     'IssueTracker').text = options.get('issuetracker', '')
    etree.SubElement(desc, 'ChangeLogURL').text = options.get('changelog', '')

    if len(options['requirements']) > 0:
        requirements = etree.SubElement(desc, 'Requirements')
        for requirement in options['requirements']:
            etree.SubElement(requirements, 'Feature', name=requirement['name'])

    if options['type'] == 'mashup':
        resources = etree.SubElement(desc, 'IncludedResources')
        for pref_name, pref_value in six.iteritems(options['preferences']):
            etree.SubElement(resources,
                             'Preference',
                             name=pref_name,
                             value=pref_value)
    else:

        if len(options['preferences']) > 0:

            preferences_element = etree.SubElement(template,
                                                   'Platform.Preferences')
            for pref in options['preferences']:
                pref_element = etree.SubElement(
                    preferences_element,
                    'Preference',
                    name=pref['name'],
                    type=pref['type'],
                    label=pref['label'],
                    description=pref['description'],
                    readonly=str(pref['readonly']).lower(),
                    default=pref['default'])

                if pref['secure']:
                    pref_element.set('secure', 'true')

                if pref['type'] == 'list':
                    for option in pref['options']:
                        etree.SubElement(pref_element,
                                         'Option',
                                         label=option['label'],
                                         value=option['value'])

                if pref['value'] is not None:
                    pref_element.set('value', pref['value'])

        if len(options['properties']) > 0:

            properties_element = etree.SubElement(template,
                                                  'Platform.StateProperties')
            for prop in options['properties']:
                etree.SubElement(properties_element,
                                 'Property',
                                 name=prop['name'],
                                 type=prop['type'],
                                 label=prop['label'],
                                 description=prop['description'],
                                 default=prop['default'],
                                 secure=str(prop['secure']).lower())

    if options['type'] == 'mashup':
        write_mashup_tree(resources, options)

    # Wiring info
    wiring = etree.SubElement(template, 'Platform.Wiring')

    for output_endpoint in options['wiring']['outputs']:
        etree.SubElement(wiring,
                         'OutputEndpoint',
                         name=output_endpoint['name'],
                         type=output_endpoint['type'],
                         label=output_endpoint['label'],
                         description=output_endpoint['description'],
                         friendcode=output_endpoint['friendcode'])

    for input_endpoint in options['wiring']['inputs']:
        etree.SubElement(wiring,
                         'InputEndpoint',
                         name=input_endpoint['name'],
                         type=input_endpoint['type'],
                         label=input_endpoint['label'],
                         description=input_endpoint['description'],
                         actionlabel=input_endpoint['actionlabel'],
                         friendcode=input_endpoint['friendcode'])

    if options['type'] == 'mashup':
        write_mashup_wiring_tree(wiring, options)
    else:
        # Widget code
        link = etree.SubElement(template, 'Platform.Link')
        xhtml = etree.SubElement(link,
                                 'XHTML',
                                 href=options['contents']['src'])
        xhtml.set('content-type', options['contents']['contenttype'])
        xhtml.set('charset', options['contents']['charset'])
        if options['contents']['cacheable'] is False:
            xhtml.set('cacheable', 'false')
        if options['contents']['useplatformstyle']:
            xhtml.set('use-platform-style', 'true')

        for altcontents in options['altcontents']:
            altcontents_element = etree.SubElement(link,
                                                   'AltContents',
                                                   scope=altcontents['scope'],
                                                   href=altcontents['src'])
            altcontents_element.set('content-type', altcontents['contenttype'])
            altcontents_element.set('charset', altcontents['charset'])

        # Widget rendering
        etree.SubElement(template,
                         'Platform.Rendering',
                         width=options['widget_width'],
                         height=options['widget_height'])

    # Translations
    if len(options['translations']) > 0:

        translations_element = etree.SubElement(
            template, 'Translations', default=options['default_lang'])

        for lang, catalogue in six.iteritems(options['translations']):
            catalogue_element = etree.SubElement(translations_element,
                                                 'Translation',
                                                 lang=lang)

            for msg_name, msg in six.iteritems(catalogue):
                msg_element = etree.SubElement(catalogue_element,
                                               'msg',
                                               name=msg_name)
                msg_element.text = msg

    return template