Пример #1
0
def load_overlay_url(overlay, lang):
    loaded = None
    print("Info: Trying {}".format('src/{}/overlay/{}.md'.format(
        lang, overlay)))
    try:
        data = markjaml.load('src/{}/overlay/{}.md'.format(lang, overlay))

        loaded = data['data']
    except IOError:
        try:
            print("Warning: Falling back to {}".format(
                'src/{}/translate/{}.md'.format(lang, overlay)))
            data = markjaml.load('src/{}/translate/{}.md'.format(
                lang, overlay))
            loaded = data['data']
        except IOError:
            return None

    if loaded is None:
        print("Fatal: Invalid overlay formatting.")
        sys.exit(1)

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

    return overlay, loaded['page_url']
Пример #2
0
def load_overlay_url(overlay, lang):
    try:
        data = markjaml.load('src/{}/overlay/{}.md'.format(lang, overlay))

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

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

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

    return overlay, loaded['page_url']
Пример #3
0
def load_overlay_url(overlay, lang):
    try:
        data = markjaml.load('src/{}/overlay/{}.md'.format(lang, overlay))

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

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

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

    return overlay, loaded['page_url']
Пример #4
0
def load_overlay(overlay):
    try:
        data = markjaml.load('src/{}/overlay/{}.md'.format(lang, overlay))

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

    return loaded
Пример #5
0
def load_overlay_url(overlay, lang):
    try:
        data = markjaml.load("src/{}/overlay/{}.md".format(lang, overlay))

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

    if not "page_url" in loaded:
        loaded["page_url"] = url_slugify(loaded["name"])

    return overlay, loaded["page_url"]
Пример #6
0
def load_overlay(overlay):
    try:
        data = markjaml.load(overlay)['data']
        slug = slugify(data['name'])
        return {
            'name': data['name'],
            'class': data['class'],
            'detail': "/v1/detail/{}.json".format(slug),
            'url': "/pinout/{}".format(slug),
            #'pimoroni.shop-handle': pimoroni_get_shop_handle(slug)
        }
    except IOError:
        return None
Пример #7
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
Пример #8
0
def load_overlay(overlay):
    try:
        data = markjaml.load(overlay) 
        slug = slugify(data['data']['name'])

        filename = 'v1/detail/{}.json'.format(slug)
        web_url = "https://pinout.xyz/pinout/{}".format(slug),

        data['api_output_file'] = filename
        data['data']['pinout_url'] = web_url

        loaded = data
    except IOError:
        return None

    return loaded
Пример #9
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
Пример #10
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:
            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
Пример #11
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 '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
Пример #12
0
files = glob.glob("src/en/overlay/*.md")

pin_physical = str(find_pin)
pin_bcm = "bcm{}".format(pinout.physical_to_bcm(pin_physical))

msg = "Searching for pin: {physical}, {bcm}".format(physical=pin_physical,
                                                    bcm=pin_bcm)
print(msg)
print(''.join('-' for x in msg))

count = 0

for file in files:
    #print("Loading: {}".format(file))
    loaded = markjaml.load(file)

    if "data" not in loaded:
        continue

    data = loaded["data"]

    if "class" not in data or "pin" not in data:
        continue

    if data["class"] in ["board", "interface"]:
        pin = None

        if pin_bcm in data["pin"]:
            pin = data["pin"][pin_bcm]
Пример #13
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(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
Пример #14
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
Пример #15
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
Пример #16
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 '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
Пример #17
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
Пример #18
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
Пример #19
0
CUSTOM_REPO_DIR = '/usr/share/pinout.custom'
REPO_DIR = '/usr/share/Pinout.xyz'
os.chdir(REPO_DIR)

if CUSTOM_REPO is not None:
    sys.path.append(REPO_DIR)
    import markjaml

    OVERLAY_DIR = 'src/en/overlay'
    overlays = [os.path.join(OVERLAY_DIR, f) for f in os.listdir(OVERLAY_DIR)]

    devnull = open(os.devnull, 'w')

    print('Removing boards...')
    for overlay in overlays:
        data = markjaml.load(overlay)['data']
        if data['class'] != 'interface':
            name = os.path.basename(overlay).split('.', 1)[0]
            cmd = '{}/draft/unpublish.sh {}'.format(REPO_DIR, name)
            subprocess.call(cmd,
                            shell=True,
                            stdout=devnull,
                            stderr=subprocess.STDOUT)

    print('Adding boards...')
    subprocess.call(['git', 'clone', CUSTOM_REPO, CUSTOM_REPO_DIR])
    shutil.rmtree('draft/boards')
    shutil.rmtree('draft/overlay')
    shutil.copytree(os.path.join(CUSTOM_REPO_DIR, 'boards'), 'draft/boards')
    shutil.copytree(os.path.join(CUSTOM_REPO_DIR, 'overlay'), 'draft/overlay')
Пример #20
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:
        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