コード例 #1
0
def load_overlay(overlay):
    try:
        data = markjaml.load(overlay)['data']
        slug = slugify(data['name'])
        data['slug'] = slug

        if "pin" in data:
            for pin in data["pin"].keys():
                if str(pin).startswith("bcm"):
                    data["pin"][pinout.bcm_to_physical(str(pin).replace("bcm",""))] = data["pin"][pin]

        return data
    except IOError:
        print('Not found: {}/src/{}/overlay/{}.md'.format(BASE_DIR, lang, overlay))
        return None
コード例 #2
0
ファイル: generate-html.py プロジェクト: LizardM4/Pinout2
def load_overlay(overlay):
    try:
        data = markjaml.load('src/{}/overlay/{}.md'.format(lang, overlay))

        loaded = data['data']
        loaded['long_description'] = data['html']
    except IOError:
        return None

    '''
    If this is not an info page, then build a collection of details and append them to long_description
    '''
    if 'type' not in loaded or loaded['type'] != 'info':
        details = []

        if 'type' not in loaded:
            loaded['type'] = 'addon'

        if 'manufacturer' in loaded:
            details.append(strings['made_by'].format(manufacturer=loaded['manufacturer']))

        if 'pincount' in loaded:
            '''
            Choose correct board type to be displayed based upon pincount and form factor.
            This could be a HAT, a pHAT or other...
            '''
            pincount = int(loaded['pincount'])
            if 'formfactor' in loaded:
                formfactor = str(loaded['formfactor'])
                if pincount == 40 and formfactor == 'HAT':
                    details.append(strings['type_hat'])
                elif pincount == 40 and formfactor == 'pHAT':
                    details.append(strings['type_phat'])
                elif pincount == 40 and formfactor == '40-way':
                    details.append(strings['pin_header'].format(pincount))
                else:
                    details.append(strings['pin_header'].format(pincount))
            elif pincount == 40:
                details.append(strings['type_hat'])
            elif pincount == 26:
                details.append(strings['type_classic'])
            else:
                details.append(strings['pin_header'].format(pincount))

        '''
        If the overlay includes a collection of pins then
        loop through them and count how many non-power pins are used
        '''
        if 'pin' in loaded:
            uses = 0
            for pin in loaded['pin']:
                pin = str(pin)
                if pin.startswith('bcm'):
                    pin = pinout.bcm_to_physical(pin[3:])

                if pin in pinout.pins:
                    actual_pin = pinout.pins[pin]

                    if actual_pin['type'] in ['+3v3', '+5v', 'GND'] and overlay != 'ground':
                        raise Exception(
                            "{} includes a reference to a {} pin, which isn't allowed".format(overlay, actual_pin['type']))
                    else:
                        uses += 1

            if uses > 0:
                details.append(strings['uses_n_gpio_pins'].format(uses))

            '''
            If the collection of pins includes pins 3 and 5 in i2c mode, then
            assume the board uses i2c communication
            '''
            if '3' in loaded['pin'] and '5' in loaded['pin']:
                pin_3 = loaded['pin']['3']
                pin_5 = loaded['pin']['5']
                if 'mode' in pin_3 and 'mode' in pin_5:
                    if pin_3['mode'] == 'i2c' and pin_5['mode'] == 'i2c':
                        details.append(strings['uses_i2c'])

        # A URL to more information about the add-on board, could be a GitHub readme or an about page
        if 'url' in loaded:
            details.append('[{text}]({url})'.format(text=strings['more_information'], url=loaded['url']))

        # Should only ever be a URL to the github repository with code supporting the product
        if 'github' in loaded:
            details.append('[{text}]({url})'.format(text=strings['github_repository'], url=loaded['github']))

        # A URL to a preferred place to buy the add-on board
        if 'buy' in loaded:
            details.append('[{text}]({url})'.format(text=strings['buy_now'], url=loaded['buy']))

        loaded['long_description'] = '{}\n{}'.format(loaded['long_description'],
                                                    markdown.markdown('\n'.join(map(lambda d: '* ' + d, details))))

    # Automatically generate a page slug from the name if none is specified
    if 'page_url' not in loaded:
        loaded['page_url'] = slugify(loaded['name'])

    loaded['rendered_html'] = render_overlay_page(loaded)
    loaded['src'] = overlay
    pages[loaded['page_url']] = loaded
    navs[loaded['page_url']] = render_nav(loaded['page_url'], overlay=loaded)

    return loaded
コード例 #3
0
def load_overlay(overlay):
    try:
        data = markjaml.load('src/{}/overlay/{}.md'.format(lang, overlay))

        loaded = data['data']
        loaded['source'] = "src/{}/translate/{}.md".format(lang, overlay)
        loaded['long_description'] = data['html']
    except IOError:
        try:
            data = markjaml.load('src/{}/translate/{}.md'.format(
                lang, overlay))

            loaded = data['data']
            loaded['source'] = "src/{}/translate/{}.md".format(lang, overlay)
            loaded[
                'long_description'] = strings['translate_msg'] + data['html']
            loaded['type'] = strings['group_other']
            #if 'formfactor' in loaded:
            #    if str(loaded['formfactor']) == 'Custom':
            #        loaded['formfactor'] = strings['form_undefined']
        except IOError:
            print('overlay {} missing in lang {}'.format(overlay, lang))
            return None

    print('>> Rendering: {src}'.format(src=loaded['source']))
    '''
    If this is not an info page, then build a collection of details and append them to long_description
    '''
    if 'type' not in loaded or loaded['type'] != 'info':
        details = []

        if 'type' not in loaded:
            loaded['type'] = strings['group_other']

        #if 'manufacturer' in loaded and 'collected' not in loaded:
        #manu_link = '<a href="/boards#manufacturer={manufacturer}">{manufacturer}</a>'.format(manufacturer=loaded['manufacturer'])
        #details.append(strings['made_by'].format(manufacturer=manu_link))
        #elif 'manufacturer' in loaded and 'collected' in loaded:
        #    details.append(strings['made_by'].format(manufacturer=loaded['manufacturer']))

        if 'pincount' in loaded:
            '''
            Choose correct board type to be displayed based upon pincount and form factor.
            This could be a HAT, a pHAT or other...
            '''
            pincount = int(loaded['pincount'])
            #if 'formfactor' in loaded:
            #formfactor = str(loaded['formfactor'])
            # if pincount == 40 and formfactor == 'HAT':
            #        details.append(strings['type_hat'])
            #    elif pincount == 40 and formfactor == 'pHAT':
            #        details.append(strings['type_phat'])
            #    elif pincount == 40 and formfactor == '40-way':
            #        details.append(strings['pin_header'].format(pincount))
            #    else:
            #        details.append(strings['pin_header'].format(pincount))
            #elif pincount == 40:
            #    details.append(strings['type_hat'])
            #elif pincount == 26:
            #    details.append(strings['type_classic'])
            #else:
            #    details.append(strings['pin_header'].format(pincount))

        #if 'eeprom' in loaded:
        #    eeprom = str(loaded['eeprom'])
        #    if eeprom == 'detect' or eeprom == 'True':
        #        details.append(strings['eeprom_detect'])
        #    if eeprom == 'setup':
        #        details.append(strings['eeprom_setup'])

        if 'power' not in loaded['type'] and 'power' in loaded:
            uses_5v = False
            uses_1v8 = False

            for pin in loaded['power']:
                pin = str(pin)
                if pin.startswith('bcm'):
                    pin = pinout.bcm_to_physical(pin[3:])

                if pin in ['37']:
                    uses_5v = True

                if pin in ['35']:
                    uses_1v8 = True

            if uses_5v and uses_1v8:
                details.append(strings['uses_5v_and_1v8'])
            elif uses_5v:
                details.append(strings['uses_5v'])
            elif uses_1v8:
                details.append(strings['uses_1v8'])
        '''
        If the overlay includes a collection of pins then
        loop through them and count how many non-power pins are used
        '''
        if 'pin' in loaded:
            uses_i2c = False
            uses_spi = False

            uses = 0
            for pin in loaded['pin']:
                data = loaded['pin'][pin]
                pin = str(pin)
                if pin.startswith('bcm'):
                    pin = pinout.bcm_to_physical(pin[3:])

                if pin in pinout.pins:
                    actual_pin = pinout.pins[pin]

                    if actual_pin['type'] in ['+1v8', '+5v', 'GND'
                                              ] and overlay != 'ground':
                        raise Exception(
                            "{} includes a reference to a {} pin ({}), which isn't allowed"
                            .format(overlay, actual_pin['type'], pin))
                    else:
                        uses += 1

                if data is not None and 'mode' in data:
                    if pin in ['15', '17', '19', '21'
                               ] and data['mode'] == 'i2c':
                        uses_i2c = True
                    if pin in ['8', '10', '12', '14'
                               ] and data['mode'] == 'spi':
                        uses_spi = True

            if uses > 0:
                details.append(strings['uses_n_gpio_pins'].format(uses))

            if uses_spi:
                details.append(strings['uses_spi'])

            if uses_i2c:
                details.append(strings['uses_i2c'])

        if 'i2c' in loaded:
            for addr in loaded['i2c']:
                data = loaded['i2c'][addr]
                addr = str(addr)
                dev = data['device'].upper()
                if data is not None and 'device' in data:
                    details.append('{address}: {device}'.format(address=addr,
                                                                device=dev))

        # A URL to more information about the add-on board, could be a GitHub readme or an about page
        if 'url' in loaded:
            details.append('[{text}]({url})'.format(
                text=strings['more_information'], url=loaded['url']))

        # Should only ever be a URL to the github repository with code supporting the product
        if 'github' in loaded:
            details.append('[{text}]({url})'.format(
                text=strings['github_repository'], url=loaded['github']))

        # A URL referencing the add-on board schematic
        if 'schematic' in loaded:
            details.append('[{text}]({url})'.format(
                text=strings['board_schematic'], url=loaded['schematic']))

        # A URL to a preferred place to buy the add-on board
        if 'buy' in loaded:
            details.append('[{text}]({url})'.format(text=strings['buy_now'],
                                                    url=loaded['buy']))

        details_html = markdown.markdown('\n'.join(
            map(lambda d: '* ' + d, details)))

        details_image = ''

        if 'image' in loaded:
            details_image = "<img src=\"/pinout/resources/boards/{}\" alt=\"{}\" />".format(
                loaded['image'], loaded['name'])

        details_html = "<table class=\"details\"><tr><td><h2>{}</h2>{}</td><td>{}</td></tr></table>".format(
            strings['details'], details_html, details_image)

        loaded['long_description'] = '{}\n{}'.format(
            loaded['long_description'], details_html)

    # Automatically generate a page slug from the name if none is specified
    if 'page_url' not in loaded:
        loaded['page_url'] = slugify(loaded['name'])

    loaded['rendered_html'] = render_overlay_page(loaded)
    loaded['src'] = overlay
    pages[loaded['page_url']] = loaded
    navs[loaded['page_url']] = render_nav(loaded['page_url'], overlay=loaded)

    return loaded
コード例 #4
0
ファイル: generate-html.py プロジェクト: uugear/Pinout2
def load_overlay(overlay):
    try:
        data = markjaml.load('src/{}/overlay/{}.md'.format(lang, overlay))


        loaded = data['data']
        loaded['source'] = "src/{}/translate/{}.md".format(lang, overlay)
        loaded['long_description'] = data['html']
    except IOError:
        try:
            data = markjaml.load('src/{}/translate/{}.md'.format(lang, overlay))


            loaded = data['data']
            loaded['source'] = "src/{}/translate/{}.md".format(lang, overlay)
            loaded['long_description'] = strings['translate_msg'] + data['html']
            loaded['type'] = strings['group_other']
            if 'formfactor' in loaded:
                if str(loaded['formfactor']) == 'Custom':
                    loaded['formfactor'] = strings['form_undefined']
        except IOError:
            print 'overlay {} missing in lang {}'.format(overlay, lang)
            return None

    print('>> Rendering: {src}'.format(src=loaded['source']))

    '''
    If this is not an info page, then build a collection of details and append them to long_description
    '''
    if 'type' not in loaded or loaded['type'] != 'info':
        details = []

        if 'type' not in loaded:
            loaded['type'] = strings['group_other']

        if 'manufacturer' in loaded:
            manu_link = '<a href="/boards#manufacturer={manufacturer}">{manufacturer}</a>'.format(manufacturer=loaded['manufacturer'])
            details.append(strings['made_by'].format(manufacturer=manu_link))

        if 'pincount' in loaded:
            '''
            Choose correct board type to be displayed based upon pincount and form factor.
            This could be a HAT, a pHAT or other...
            '''
            pincount = int(loaded['pincount'])
            if 'formfactor' in loaded:
                formfactor = str(loaded['formfactor'])
                if pincount == 40 and formfactor == 'HAT':
                    details.append(strings['type_hat'])
                elif pincount == 40 and formfactor == 'pHAT':
                    details.append(strings['type_phat'])
                elif pincount == 40 and formfactor == '40-way':
                    details.append(strings['pin_header'].format(pincount))
                else:
                    details.append(strings['pin_header'].format(pincount))
            elif pincount == 40:
                details.append(strings['type_hat'])
            elif pincount == 26:
                details.append(strings['type_classic'])
            else:
                details.append(strings['pin_header'].format(pincount))

        if 'eeprom' in loaded:
            eeprom = str(loaded['eeprom'])
            if eeprom == 'detect' or eeprom == 'True':
                details.append(strings['eeprom_detect'])
            if eeprom == 'setup':
                details.append(strings['eeprom_setup'])

        if 'power' in loaded:
            uses_5v = False
            uses_3v3 = False

            for pin in loaded['power']:
                pin = str(pin)
                if pin.startswith('bcm'):
                    pin = pinout.bcm_to_physical(pin[3:])

                if pin in ['2','4']:
                    uses_5v = True

                if pin in ['1','17']:
                    uses_3v3 = True

            if uses_5v and uses_3v3:
                details.append(strings['uses_5v_and_3v3'])
            elif uses_5v:
                details.append(strings['uses_5v'])
            elif uses_3v3:
                details.append(strings['uses_3v3'])

        '''
        If the overlay includes a collection of pins then
        loop through them and count how many non-power pins are used
        '''
        if 'pin' in loaded:
            uses_i2c = False
            uses_spi = False

            uses = 0
            for pin in loaded['pin']:
                data = loaded['pin'][pin]
                pin = str(pin)
                if pin.startswith('bcm'):
                    pin = pinout.bcm_to_physical(pin[3:])

                if pin in pinout.pins:
                    actual_pin = pinout.pins[pin]

                    if actual_pin['type'] in ['+3v3', '+5v', 'GND'] and overlay != 'ground':
                        raise Exception(
                            "{} includes a reference to a {} pin, which isn't allowed".format(overlay, actual_pin['type']))
                    else:
                        uses += 1

                if data is not None and 'mode' in data:
                    if pin in ['3','5'] and data['mode'] == 'i2c':
                        uses_i2c = True
                    if pin in ['19','21','23'] and data['mode'] == 'spi':
                        uses_spi = True

            if uses_i2c:
                details.append(strings['uses_i2c'])

            if uses_spi:
                details.append(strings['uses_spi'])

            if uses > 0:
                details.append(strings['uses_n_gpio_pins'].format(uses))

        # A URL to more information about the add-on board, could be a GitHub readme or an about page
        if 'url' in loaded:
            details.append('[{text}]({url})'.format(text=strings['more_information'], url=loaded['url']))

        # Should only ever be a URL to the github repository with code supporting the product
        if 'github' in loaded:
            details.append('[{text}]({url})'.format(text=strings['github_repository'], url=loaded['github']))

        # A URL referencing the add-on board schematic
        if 'schematic' in loaded:
            details.append('[{text}]({url})'.format(text=strings['board_schematic'], url=loaded['schematic']))

        # A URL to a preferred place to buy the add-on board
        if 'buy' in loaded:
            details.append('[{text}]({url})'.format(text=strings['buy_now'], url=loaded['buy']))

        details_html = markdown.markdown('\n'.join(map(lambda d: '* ' + d, details)))

        details_image = ''

        if 'image' in loaded:
            details_image = "<img src=\"/resources/boards/{}\" alt=\"{}\" />".format(loaded['image'],loaded['name'])

        details_html = "<table class=\"details\"><tr><td><h2>{}</h2>{}</td><td>{}</td></tr></table>".format(strings['details'],details_html,details_image)

        loaded['long_description'] = '{}\n{}'.format(loaded['long_description'],details_html)

    # Automatically generate a page slug from the name if none is specified
    if 'page_url' not in loaded:
        loaded['page_url'] = slugify(loaded['name'])

    loaded['rendered_html'] = render_overlay_page(loaded)
    loaded['src'] = overlay
    pages[loaded['page_url']] = loaded
    navs[loaded['page_url']] = render_nav(loaded['page_url'], overlay=loaded)

    return loaded
コード例 #5
0
ファイル: generate-html.py プロジェクト: rdmueller/Pinout2
def load_overlay(overlay):
    try:
        data = markjaml.load('src/{}/overlay/{}.md'.format(lang, overlay))

        loaded = data['data']
        loaded['long_description'] = data['html']
    except IOError:
        return None

    details = []

    if 'type' not in loaded:
        loaded['type'] = 'addon'

    if 'manufacturer' in loaded:
        details.append(strings['made_by'].format(manufacturer=loaded['manufacturer']))

    if 'pincount' in loaded:
        pincount = int(loaded['pincount'])
        if pincount == 40:
            details.append(strings['type_hat'])
        elif pincount == 26:
            details.append(strings['type_classic'])
        else:
            details.append(strings['pin_header'].format(pincount))

    if 'pin' in loaded:
        uses = 0
        for pin in loaded['pin']:
            pin = str(pin)
            if pin.startswith('bcm'):
                pin = pinout.bcm_to_physical(pin[3:])

            if pin in pinout.pins:
                actual_pin = pinout.pins[pin]

                if actual_pin['type'] in ['+3v3', '+5v', 'GND'] and overlay != 'ground':
                    raise Exception("{} includes a reference to a {} pin, which isn't allowed".format(overlay, actual_pin['type']))
                else:
                    uses += 1

        if uses > 0:
            details.append(strings['uses_n_gpio_pins'].format(uses))

        if '3' in loaded['pin'] and '5' in loaded['pin']:
            pin_3 = loaded['pin']['3']
            pin_5 = loaded['pin']['5']
            if 'mode' in pin_3 and 'mode' in pin_5:
                if pin_3['mode'] == 'i2c' and pin_5['mode'] == 'i2c':
                    details.append(strings['uses_i2c'])

    if 'url' in loaded:
        details.append('[{text}]({url})'.format(text=strings['more_information'], url=loaded['url']))

    if 'github' in loaded:
        details.append('[{text}]({url})'.format(text=strings['github_repository'], url=loaded['github']))

    if 'buy' in loaded:
        details.append('[{text}]({url})'.format(text=strings['buy_now'], url=loaded['buy']))

    if loaded['type'] != 'info':
        loaded['long_description'] = '{}\n{}'.format(loaded['long_description'], markdown.markdown('\n'.join(map(lambda d: '* ' + d, details))))

    if 'page_url' not in loaded:
        loaded['page_url'] = slugify(loaded['name'])

    loaded['rendered_html'] = render_overlay_page(loaded)
    loaded['src'] = overlay
    pages[loaded['page_url']] = loaded
    navs[loaded['page_url']] = render_nav(loaded['page_url'], overlay=loaded)
    select_overlays.append((loaded['page_url'], loaded['name']))
    return loaded
コード例 #6
0
ファイル: generate-html.py プロジェクト: ResonantWave/Pinout2
def load_overlay(overlay):
	try:
		data = markjaml.load('src/{}/overlay/{}.md'.format(lang,overlay))

		loaded = data['data']
		loaded['long_description'] = data['html']
	except IOError:
		return None


	details = []

	if 'manufacturer' in loaded:
		details.append(strings['made_by'].format(manufacturer=loaded['manufacturer']))

	if 'pincount' in loaded:
		pincount = int(loaded['pincount'])
		if pincount == 40:
			details.append(strings['type_hat'])
		elif pincount == 26:
			details.append(strings['type_classic'])
		else:
			details.append(strings['pin_header'].format(pincount))

	if 'pin' in loaded:
		uses_5v = False
		uses_3v = False
		uses = 0
		for pin in loaded['pin']:
			pin = str(pin)
			if pin.startswith('bcm'):
				pin = pinout.bcm_to_physical(pin[3:])

			if pin in pinout.pins:
				actual_pin = pinout.pins[pin]

				if actual_pin['type'] in ['+3v3','+5v','GND']:
					if actual_pin['type'] == '+3v3':
						uses_3v = True
					if actual_pin['type'] == '+5v':
						uses_5v = True
				else:
					uses += 1

		if uses > 0:
			details.append('* Uses {} GPIO pins'.format(uses))

		if '3' in loaded['pin'] and '5' in loaded['pin']:
			pin_3 = loaded['pin']['3']
			pin_5 = loaded['pin']['5']
			if 'mode' in pin_3 and 'mode' in pin_5:
				if pin_3['mode'] == 'i2c' and pin_5['mode'] == 'i2c':
					details.append(strings['uses_i2c'])

	if 'url' in loaded:
		details.append('* [More Information]({url})'.format(url=loaded['url']))

	if 'github' in loaded:
		details.append('* [GitHub Repository]({url})'.format(url=loaded['github']))

	if 'buy' in loaded:
		details.append('* [Buy Now]({url})'.format(url=loaded['buy']))


	loaded['long_description'] = '{}\n{}'.format(loaded['long_description'],markdown.markdown('\n'.join(details)))

	if not 'page_url' in loaded:
		loaded['page_url'] = slugify(loaded['name'])

	loaded['rendered_html'] = render_overlay_page(loaded)
	loaded['src'] = overlay
	pages[loaded['page_url']] = loaded
	navs[loaded['page_url']] = render_nav(loaded['page_url'], overlay=loaded)
	select_overlays.append((loaded['page_url'], loaded['name']))
 	return loaded
コード例 #7
0
def load_overlay(overlay):
    try:
        data = markjaml.load('src/{}/overlay/{}.md'.format(lang, overlay))

        loaded = data['data']
        loaded['long_description'] = data['html']
    except IOError:
        return None

    details = []

    if 'manufacturer' in loaded:
        details.append('* Made by ' + loaded['manufacturer'])

    if 'pincount' in loaded:
        pincount = int(loaded['pincount'])
        if pincount == 40:
            details.append('* HAT form-factor')
        elif pincount == 26:
            details.append('* Classic 26-pin')
        else:
            details.append('* {} pin header'.format(pincount))

    if 'pin' in loaded:
        uses_5v = False
        uses_3v = False
        uses = 0
        for pin in loaded['pin']:
            pin = str(pin)
            if pin.startswith('bcm'):
                pin = pinout.bcm_to_physical(pin[3:])

            if pin in pinout.pins:
                actual_pin = pinout.pins[pin]

                if actual_pin['type'] in ['+3v3', '+5v', 'GND']:
                    if actual_pin['type'] == '+3v3':
                        uses_3v = True
                    if actual_pin['type'] == '+5v':
                        uses_5v = True
                else:
                    uses += 1

        if uses > 0:
            details.append('* Uses {} GPIO pins'.format(uses))

        if '3' in loaded['pin'] and '5' in loaded['pin']:
            pin_3 = loaded['pin']['3']
            pin_5 = loaded['pin']['5']
            if 'mode' in pin_3 and 'mode' in pin_5:
                if pin_3['mode'] == 'i2c' and pin_5['mode'] == 'i2c':
                    details.append('* Uses I2C')

    if 'url' in loaded:
        details.append('* [More Information]({url})'.format(url=loaded['url']))

    if 'github' in loaded:
        details.append(
            '* [GitHub Repository]({url})'.format(url=loaded['github']))

    if 'buy' in loaded:
        details.append('* [Buy Now]({url})'.format(url=loaded['buy']))

    loaded['long_description'] = '{}\n{}'.format(
        loaded['long_description'], markdown.markdown('\n'.join(details)))

    if not 'page_url' in loaded:
        loaded['page_url'] = slugify(loaded['name'])

    loaded['rendered_html'] = render_overlay_page(loaded)
    pages[loaded['page_url']] = loaded
    navs[loaded['page_url']] = render_nav(loaded['page_url'], overlay=loaded)
    select_overlays.append((loaded['page_url'], loaded['name']))
    return loaded
コード例 #8
0
def load_overlay(overlay):
    try:
        data = markjaml.load('src/{}/overlay/{}.md'.format(lang, overlay))

        loaded = data['data']
    except IOError:
        return None

    details = []

    if 'manufacturer' in loaded:
        if loaded['manufacturer'] == "Pimoroni":
            if 'buy' in loaded:
                product_slug = loaded['buy'].split('/')[-1]
                product_map[product_slug] = slugify(loaded['name'])

        details.append('* Made by ' + loaded['manufacturer'])

    if 'pincount' in loaded:
        pincount = int(loaded['pincount'])
        if pincount == 40:
            details.append('* HAT form-factor')
        elif pincount == 38:
            details.append('* pHAT form-factor')
        elif pincount == 26:
            details.append('* Classic 26-pin')
        else:
            details.append('* {} pin header'.format(pincount))

    if 'pin' in loaded:
        uses_5v = False
        uses_3v = False
        uses = 0
        for pin in loaded['pin']:
            pin = str(pin)
            if pin.startswith('bcm'):
                pin = pinout.bcm_to_physical(pin[3:])

            if pin in pinout.pins:
                actual_pin = pinout.pins[pin]

                if actual_pin['type'] in ['+3v3', '+5v', 'GND']:
                    if actual_pin['type'] == '+3v3':
                        uses_3v = True
                    if actual_pin['type'] == '+5v':
                        uses_5v = True
                else:
                    uses += 1

        if uses > 0:
            details.append('* Uses {} GPIO pins'.format(uses))

        if '3' in loaded['pin'] and '5' in loaded['pin']:
            pin_3 = loaded['pin']['3']
            pin_5 = loaded['pin']['5']
            if pin_3 is not None and pin_5 is not None:
                if 'mode' in pin_3 and 'mode' in pin_5:
                    if pin_3['mode'] == 'i2c' and pin_5['mode'] == 'i2c':
                        details.append('* Uses I2C')

    if 'url' in loaded:
        details.append('* [More Information]({url})'.format(url=loaded['url']))

    if 'github' in loaded:
        details.append(
            '* [GitHub Repository]({url})'.format(url=loaded['github']))

    if 'buy' in loaded:
        details.append('* [Buy Now]({url})'.format(url=loaded['buy']))

    if not 'page_url' in loaded:
        loaded['page_url'] = slugify(loaded['name'])

    pages[loaded['page_url']] = loaded
    return loaded
コード例 #9
0
ファイル: generate-json.py プロジェクト: tanyingyu/Pinout2
def load_overlay(overlay):
    try:
        data = markjaml.load('src/{}/overlay/{}.md'.format(lang, overlay))

        loaded = data['data']
    except IOError:
        return None


    details = []

    if 'manufacturer' in loaded:
        details.append('* Made by ' + loaded['manufacturer'])

    if 'pincount' in loaded:
        pincount = int(loaded['pincount'])
        if pincount == 40:
            details.append('* HAT form-factor')
        elif pincount == 26:
            details.append('* Classic 26-pin')
        else:
            details.append('* {} pin header'.format(pincount))

    if 'pin' in loaded:
        uses_5v = False
        uses_3v = False
        uses = 0
        for pin in loaded['pin']:
            pin = str(pin)
            if pin.startswith('bcm'):
                pin = pinout.bcm_to_physical(pin[3:])

            if pin in pinout.pins:
                actual_pin = pinout.pins[pin]

                if actual_pin['type'] in ['+3v3', '+5v', 'GND']:
                    if actual_pin['type'] == '+3v3':
                        uses_3v = True
                    if actual_pin['type'] == '+5v':
                        uses_5v = True
                else:
                    uses += 1

        if uses > 0:
            details.append('* Uses {} GPIO pins'.format(uses))

        if '3' in loaded['pin'] and '5' in loaded['pin']:
            pin_3 = loaded['pin']['3']
            pin_5 = loaded['pin']['5']
            if 'mode' in pin_3 and 'mode' in pin_5:
                if pin_3['mode'] == 'i2c' and pin_5['mode'] == 'i2c':
                    details.append('* Uses I2C')

    if 'url' in loaded:
        details.append('* [More Information]({url})'.format(url=loaded['url']))

    if 'github' in loaded:
        details.append('* [GitHub Repository]({url})'.format(url=loaded['github']))

    if 'buy' in loaded:
        details.append('* [Buy Now]({url})'.format(url=loaded['buy']))

    if not 'page_url' in loaded:
        loaded['page_url'] = slugify(loaded['name'])

    pages[loaded['page_url']] = loaded
    return loaded
コード例 #10
0
def load_overlay(overlay):
    try:
        data = markjaml.load('src/{}/overlay/{}.md'.format(lang, overlay))

        loaded = data['data']
        loaded['long_description'] = data['html']
    except IOError:
        return None
    '''
    If this is not an info page, then build a collection of details and append them to long_description
    '''
    if 'type' not in loaded or loaded['type'] != 'info':
        details = []

        if 'type' not in loaded:
            loaded['type'] = 'addon'

        if 'manufacturer' in loaded:
            details.append(
                strings['made_by'].format(manufacturer=loaded['manufacturer']))

        if 'pincount' in loaded:
            '''
            Choose correct board type to be displayed based upon pincount and form factor.
            This could be a HAT, a pHAT or other...
            '''
            pincount = int(loaded['pincount'])
            if 'formfactor' in loaded:
                formfactor = str(loaded['formfactor'])
                if pincount == 40 and formfactor == 'HAT':
                    details.append(strings['type_hat'])
                elif pincount == 40 and formfactor == 'pHAT':
                    details.append(strings['type_phat'])
                elif pincount == 40 and formfactor == '40-way':
                    details.append(strings['pin_header'].format(pincount))
                else:
                    details.append(strings['pin_header'].format(pincount))
            elif pincount == 40:
                details.append(strings['type_hat'])
            elif pincount == 26:
                details.append(strings['type_classic'])
            else:
                details.append(strings['pin_header'].format(pincount))
        '''
        If the overlay includes a collection of pins then
        loop through them and count how many non-power pins are used
        '''
        if 'pin' in loaded:
            uses = 0
            for pin in loaded['pin']:
                pin = str(pin)
                if pin.startswith('bcm'):
                    pin = pinout.bcm_to_physical(pin[3:])

                if pin in pinout.pins:
                    actual_pin = pinout.pins[pin]

                    if actual_pin['type'] in ['+3v3', '+5v', 'GND'
                                              ] and overlay != 'ground':
                        raise Exception(
                            "{} includes a reference to a {} pin, which isn't allowed"
                            .format(overlay, actual_pin['type']))
                    else:
                        uses += 1

            if uses > 0:
                details.append(strings['uses_n_gpio_pins'].format(uses))
            '''
            If the collection of pins includes pins 3 and 5 in i2c mode, then
            assume the board uses i2c communication
            '''
            if '3' in loaded['pin'] and '5' in loaded['pin']:
                pin_3 = loaded['pin']['3']
                pin_5 = loaded['pin']['5']
                if 'mode' in pin_3 and 'mode' in pin_5:
                    if pin_3['mode'] == 'i2c' and pin_5['mode'] == 'i2c':
                        details.append(strings['uses_i2c'])

        # A URL to more information about the add-on board, could be a GitHub readme or an about page
        if 'url' in loaded:
            details.append('[{text}]({url})'.format(
                text=strings['more_information'], url=loaded['url']))

        # Should only ever be a URL to the github repository with code supporting the product
        if 'github' in loaded:
            details.append('[{text}]({url})'.format(
                text=strings['github_repository'], url=loaded['github']))

        # A URL to a preferred place to buy the add-on board
        if 'buy' in loaded:
            details.append('[{text}]({url})'.format(text=strings['buy_now'],
                                                    url=loaded['buy']))

        loaded['long_description'] = '{}\n{}'.format(
            loaded['long_description'],
            markdown.markdown('\n'.join(map(lambda d: '* ' + d, details))))

    # Automatically generate a page slug from the name if none is specified
    if 'page_url' not in loaded:
        loaded['page_url'] = slugify(loaded['name'])

    loaded['rendered_html'] = render_overlay_page(loaded)
    loaded['src'] = overlay
    pages[loaded['page_url']] = loaded
    navs[loaded['page_url']] = render_nav(loaded['page_url'], overlay=loaded)

    return loaded
コード例 #11
0
ファイル: generate-html.py プロジェクト: Naohiro2g/Pinout2
def load_overlay(overlay):
    try:
        data = markjaml.load('src/{}/overlay/{}.md'.format(lang, overlay))

        loaded = data['data']
        loaded['long_description'] = data['html']
    except IOError:
        return None

    details = []

    if 'type' not in loaded:
        loaded['type'] = 'addon'

    if 'manufacturer' in loaded:
        details.append(
            strings['made_by'].format(manufacturer=loaded['manufacturer']))

    if 'pincount' in loaded:
        pincount = int(loaded['pincount'])
        if 'formfactor' in loaded:
            formfactor = str(loaded['formfactor'])
            if pincount == 40 and formfactor == 'HAT':
                details.append(strings['type_hat'])
            elif pincount == 40 and formfactor == 'pHAT':
                details.append(strings['type_phat'])
            elif pincount == 40 and formfactor == '40-way':
                details.append(strings['pin_header'].format(pincount))
            else:
                details.append(strings['pin_header'].format(pincount))
        elif pincount == 40:
            details.append(strings['type_hat'])
        elif pincount == 26:
            details.append(strings['type_classic'])
        else:
            details.append(strings['pin_header'].format(pincount))

    if 'pin' in loaded:
        uses = 0
        for pin in loaded['pin']:
            pin = str(pin)
            if pin.startswith('bcm'):
                pin = pinout.bcm_to_physical(pin[3:])

            if pin in pinout.pins:
                actual_pin = pinout.pins[pin]

                if actual_pin['type'] in ['+3v3', '+5v', 'GND'
                                          ] and overlay != 'ground':
                    raise Exception(
                        "{} includes a reference to a {} pin, which isn't allowed"
                        .format(overlay, actual_pin['type']))
                else:
                    uses += 1

        if uses > 0:
            details.append(strings['uses_n_gpio_pins'].format(uses))

        if '3' in loaded['pin'] and '5' in loaded['pin']:
            pin_3 = loaded['pin']['3']
            pin_5 = loaded['pin']['5']
            if 'mode' in pin_3 and 'mode' in pin_5:
                if pin_3['mode'] == 'i2c' and pin_5['mode'] == 'i2c':
                    details.append(strings['uses_i2c'])

    if 'url' in loaded:
        details.append('[{text}]({url})'.format(
            text=strings['more_information'], url=loaded['url']))

    if 'github' in loaded:
        details.append('[{text}]({url})'.format(
            text=strings['github_repository'], url=loaded['github']))

    if 'buy' in loaded:
        details.append('[{text}]({url})'.format(text=strings['buy_now'],
                                                url=loaded['buy']))

    if loaded['type'] != 'info':
        loaded['long_description'] = '{}\n{}'.format(
            loaded['long_description'],
            markdown.markdown('\n'.join(map(lambda d: '* ' + d, details))))

    if 'page_url' not in loaded:
        loaded['page_url'] = slugify(loaded['name'])

    loaded['rendered_html'] = render_overlay_page(loaded)
    loaded['src'] = overlay
    pages[loaded['page_url']] = loaded
    navs[loaded['page_url']] = render_nav(loaded['page_url'], overlay=loaded)
    select_overlays.append((loaded['page_url'], loaded['name']))
    return loaded