2015-11-18 17:16:17 +02:00
# Copyright 2014-2015 Ivan Kravets <me@ikravets.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
2015-03-11 18:12:58 +02:00
2015-03-13 19:06:35 +02:00
from math import ceil
2015-03-11 18:12:58 +02:00
from os . path import dirname , join , realpath
from sys import exit as sys_exit
2015-03-13 19:06:35 +02:00
from sys import path
2015-03-11 18:12:58 +02:00
path . append ( " .. " )
2015-03-13 19:06:35 +02:00
2015-03-11 18:12:58 +02:00
from platformio import util
2015-03-14 00:02:09 +02:00
from platformio . platforms . base import PlatformFactory , get_packages
2015-03-11 18:12:58 +02:00
2015-03-20 21:44:26 +02:00
def is_compat_platform_and_framework ( platform , framework ) :
p = PlatformFactory . newPlatform ( platform )
for pkg in p . get_packages ( ) . keys ( ) :
if pkg . startswith ( " framework- %s " % framework ) :
return True
return False
2015-03-11 18:12:58 +02:00
def generate_boards ( boards ) :
def _round_memory_size ( size ) :
size = ceil ( size )
for b in ( 64 , 32 , 16 , 8 , 4 , 2 , 1 ) :
if b < size :
return int ( ceil ( size / b ) * b )
assert NotImplemented ( )
lines = [ ]
lines . append ( """
.. list-table::
:header-rows: 1
* - Type ``board``
- Name
- Microcontroller
- Frequency
- Flash
- RAM """ )
for board in sorted ( boards ) :
for type_ , data in board . iteritems ( ) :
assert type_ in util . get_boards ( )
board_ram = float ( data [ ' upload ' ] [ ' maximum_ram_size ' ] ) / 1024
2015-03-11 19:32:53 +02:00
lines . append ( """
2015-03-11 18:12:58 +02:00
* - `` {type} ``
- ` {name} < {url} >`_
- {mcu}
- {f_cpu:d} MHz
- {rom} Kb
2015-03-11 19:32:53 +02:00
- {ram} Kb """ . format (
type = type_ ,
name = data [ ' name ' ] ,
url = data [ ' url ' ] ,
mcu = data [ ' build ' ] [ ' mcu ' ] . upper ( ) ,
f_cpu = int ( ( data [ ' build ' ] [ ' f_cpu ' ] [ : - 1 ] ) ) / 1000000 ,
ram = int ( board_ram ) if board_ram % 1 == 0 else board_ram ,
rom = _round_memory_size (
data [ ' upload ' ] [ ' maximum_size ' ] / 1024 )
) )
2015-03-11 18:12:58 +02:00
2015-03-11 19:32:53 +02:00
return " \n " . join ( lines + [ " " ] )
2015-03-11 18:12:58 +02:00
2015-08-09 19:05:16 +03:00
def generate_packages ( packages , is_embedded ) :
2015-08-03 12:33:37 +03:00
if not packages :
return
2015-03-14 00:02:09 +02:00
allpackages = get_packages ( )
2015-03-11 18:12:58 +02:00
lines = [ ]
2015-08-03 12:33:37 +03:00
lines . append ( """
Packages
--------
""" )
2015-03-11 18:12:58 +02:00
lines . append ( """ .. list-table::
:header-rows: 1
* - Name
- Contents """ )
for type_ , data in packages . iteritems ( ) :
2015-03-14 00:02:09 +02:00
assert type_ in allpackages
2015-03-11 18:12:58 +02:00
contitems = [
" ` %s < %s >`_ " % ( name , url )
2015-03-14 00:02:09 +02:00
for name , url in allpackages [ type_ ]
2015-03-11 18:12:58 +02:00
]
lines . append ( """
* - `` {type_} ``
- {contents} """ . format (
type_ = type_ ,
contents = " , " . join ( contitems ) ) )
2015-08-09 19:05:16 +03:00
if is_embedded :
lines . append ( """
2015-03-11 18:12:58 +02:00
.. warning::
**Linux Users:** Don ' t forget to install " udev " rules file
2015-03-25 11:34:48 +02:00
`99-platformio-udev.rules <https://github.com/platformio/platformio/blob/develop/scripts/99-platformio-udev.rules>`_ (an instruction is located in the file).
2015-03-11 18:12:58 +02:00
2015-07-07 23:33:25 +03:00
**Windows Users:** Please check that you have correctly installed USB driver
from board manufacturer
2015-03-11 18:12:58 +02:00
""" )
2015-08-09 19:05:16 +03:00
2015-03-11 18:12:58 +02:00
return " \n " . join ( lines )
def generate_platform ( name ) :
print " Processing platform: %s " % name
lines = [ ]
2015-11-18 17:33:46 +02:00
lines . append ( """ .. Copyright 2014-2015 Ivan Kravets <me@ikravets.com>
Licensed under the Apache License, Version 2.0 (the " License " );
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an " AS IS " BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
""" )
2015-03-11 18:12:58 +02:00
lines . append ( " .. _platform_ %s : " % name )
lines . append ( " " )
_title = " Platform `` %s `` " % name
lines . append ( _title )
lines . append ( " = " * len ( _title ) )
p = PlatformFactory . newPlatform ( name )
2015-03-16 12:47:43 +02:00
lines . append ( p . get_description ( ) )
lines . append ( """
For more detailed information please visit `vendor site < %s >`_. """ %
p . get_vendor_url ( ) )
lines . append ( """
.. contents:: """ )
2015-03-20 21:44:26 +02:00
2015-08-03 12:33:37 +03:00
#
# Packages
#
2015-08-09 19:05:16 +03:00
_packages_content = generate_packages ( p . get_packages ( ) , p . is_embedded ( ) )
2015-08-03 12:33:37 +03:00
if _packages_content :
lines . append ( _packages_content )
2015-03-20 21:44:26 +02:00
2015-08-03 12:33:37 +03:00
#
# Frameworks
#
2015-03-20 21:44:26 +02:00
_frameworks = util . get_frameworks ( )
2015-08-03 12:33:37 +03:00
_frameworks_lines = [ ]
2015-03-20 21:44:26 +02:00
for framework in sorted ( _frameworks . keys ( ) ) :
if not is_compat_platform_and_framework ( name , framework ) :
continue
2015-08-03 12:33:37 +03:00
_frameworks_lines . append ( """
2015-03-20 21:44:26 +02:00
* - :ref:`framework_ {type_} `
- {description} """ . format (
type_ = framework ,
description = _frameworks [ framework ] [ ' description ' ] ) )
2015-08-03 12:33:37 +03:00
if _frameworks_lines :
lines . append ( """
Frameworks
----------
.. list-table::
:header-rows: 1
2015-03-11 18:12:58 +02:00
2015-08-03 12:33:37 +03:00
* - Name
- Description """ )
lines . extend ( _frameworks_lines )
2015-03-11 18:12:58 +02:00
2015-08-03 12:33:37 +03:00
#
# Boards
#
2015-03-11 18:12:58 +02:00
vendors = { }
for board , data in util . get_boards ( ) . items ( ) :
platform = data [ ' platform ' ]
vendor = data [ ' vendor ' ]
if name in platform :
if vendor in vendors :
vendors [ vendor ] . append ( { board : data } )
else :
vendors [ vendor ] = [ { board : data } ]
2015-08-03 12:33:37 +03:00
if vendors :
lines . append ( """
Boards
------
.. note::
* You can list pre-configured boards by :ref:`cmd_boards` command or
`PlatformIO Boards Explorer <http://platformio.org/#!/boards>`_
* For more detailed ``board`` information please scroll tables below by
horizontal.
""" )
2015-03-11 18:12:58 +02:00
for vendor , boards in sorted ( vendors . iteritems ( ) ) :
lines . append ( str ( vendor ) )
lines . append ( " ~ " * len ( vendor ) )
lines . append ( generate_boards ( boards ) )
2015-08-03 12:33:37 +03:00
2015-03-11 18:12:58 +02:00
return " \n " . join ( lines )
def update_platform_docs ( ) :
for name in PlatformFactory . get_platforms ( ) . keys ( ) :
rst_path = join (
2015-03-20 21:44:26 +02:00
dirname ( realpath ( __file__ ) ) , " .. " , " docs " , " platforms " ,
" %s .rst " % name )
2015-03-11 18:12:58 +02:00
with open ( rst_path , " w " ) as f :
f . write ( generate_platform ( name ) )
2015-03-16 17:30:23 +02:00
def generate_framework ( type_ , data ) :
print " Processing framework: %s " % type_
2015-03-11 18:12:58 +02:00
lines = [ ]
2015-03-16 17:30:23 +02:00
lines . append ( " .. _framework_ %s : " % type_ )
2015-03-11 18:12:58 +02:00
lines . append ( " " )
2015-03-16 17:30:23 +02:00
_title = " Framework `` %s `` " % type_
2015-03-11 18:12:58 +02:00
lines . append ( _title )
lines . append ( " = " * len ( _title ) )
lines . append ( data [ ' description ' ] )
lines . append ( """
2015-03-20 21:44:26 +02:00
For more detailed information please visit `vendor site < %s >`_.
""" % data [ ' url ' ] )
lines . append ( " .. contents:: " )
2015-03-16 17:30:23 +02:00
lines . append ( """
2015-03-20 21:44:26 +02:00
Platforms
---------
.. list-table::
:header-rows: 1
2015-03-16 12:47:43 +02:00
2015-03-20 21:44:26 +02:00
* - Name
- Description """ )
for platform in sorted ( PlatformFactory . get_platforms ( ) . keys ( ) ) :
if not is_compat_platform_and_framework ( platform , type_ ) :
continue
p = PlatformFactory . newPlatform ( platform )
lines . append ( """
* - :ref:`platform_ {type_} `
- {description} """ . format (
type_ = platform ,
description = p . get_description ( ) ) )
lines . append ( """
2015-03-11 18:12:58 +02:00
Boards
------
.. note::
2015-03-13 19:06:35 +02:00
* You can list pre-configured boards by :ref:`cmd_boards` command or
2015-03-16 23:08:59 +02:00
`PlatformIO Boards Explorer <http://platformio.org/#!/boards>`_
2015-03-11 18:12:58 +02:00
* For more detailed ``board`` information please scroll tables below by horizontal.
""" )
vendors = { }
for board , data in util . get_boards ( ) . items ( ) :
frameworks = data [ ' frameworks ' ]
vendor = data [ ' vendor ' ]
2015-03-16 17:30:23 +02:00
if type_ in frameworks :
2015-03-11 18:12:58 +02:00
if vendor in vendors :
vendors [ vendor ] . append ( { board : data } )
else :
vendors [ vendor ] = [ { board : data } ]
for vendor , boards in sorted ( vendors . iteritems ( ) ) :
lines . append ( str ( vendor ) )
lines . append ( " ~ " * len ( vendor ) )
lines . append ( generate_boards ( boards ) )
return " \n " . join ( lines )
def update_framework_docs ( ) :
for name , data in util . get_frameworks ( ) . items ( ) :
rst_path = join ( util . get_source_dir ( ) , " .. " , " docs " , " frameworks " ,
" %s .rst " % name )
with open ( rst_path , " w " ) as f :
f . write ( generate_framework ( name , data ) )
2015-03-27 14:24:59 +02:00
def update_create_platform_doc ( ) :
allpackages = get_packages ( )
lines = [ ]
lines . append ( """ .. _platform_creating_packages:
Packages
--------
*PlatformIO* has pre-built packages for the most popular operation systems:
*Mac OS*, *Linux (+ARM)* and *Windows*.
.. list-table::
:header-rows: 1
* - Name
- Contents """ )
for type_ , data in sorted ( allpackages . iteritems ( ) ) :
contitems = [
" ` %s < %s >`_ " % ( name , url )
for name , url in allpackages [ type_ ]
]
lines . append ( """
* - `` {type_} ``
- {contents} """ . format (
type_ = type_ ,
contents = " , " . join ( contitems ) ) )
with open ( join ( util . get_source_dir ( ) , " .. " , " docs " , " platforms " ,
" creating_platform.rst " ) , " r+ " ) as fp :
content = fp . read ( )
fp . seek ( 0 , 0 )
fp . write (
content [ : content . index ( " .. _platform_creating_packages: " ) ] +
" \n " . join ( lines ) + " \n \n " +
content [ content . index ( " .. _platform_creating_manifest_file: " ) : ]
)
2015-03-11 18:12:58 +02:00
def main ( ) :
2015-03-27 14:24:59 +02:00
update_create_platform_doc ( )
2015-03-11 18:12:58 +02:00
update_platform_docs ( )
update_framework_docs ( )
if __name__ == " __main__ " :
sys_exit ( main ( ) )