Please note that User Registration has been temporarily disabled due to a recent increase in automated registrations. If anyone needs an account, please request one here: RequestAccount. Thanks for your patience!

Difference between revisions of "BitBake (dev)"

From Openembedded.org
Jump to: navigation, search
(Helloworld using lib bb)
(Fix various URLs to up to date location)
 
(15 intermediate revisions by 5 users not shown)
Line 1: Line 1:
= Bitbake =
+
''developer homepage''
Where are all bitbake hot information !!
+
  
* First , RTFM ;-) : http://bitbake.berlios.de/manual/
+
* First , RTFM ;-) (doc directory in the bitbake source)
Best documentation for source is via python documentation system.
+
* Don't forget mailinglist :
 +
** http://lists.linuxtogo.org/cgi-bin/mailman/listinfo/bitbake-devel
  
 +
Source tree is in git at http://git.openembedded.org/bitbake/
  
 +
= Tutorial =
  
= Helloworld using lib bb =
+
This tutorial focus bitbake developement, not bbclass or openembedded developement that is documented elsewhere.
 +
 
 +
== "Helloworld" using bb library ==
 +
 
 +
=== Simplest ===
  
 
<pre>
 
<pre>
Line 17: Line 23:
  
 
version = bb.__version__
 
version = bb.__version__
bb.msg.note(1, 0, "Hello from helloworld using lib bb v%s." % ( version ))
+
bb.note("Hello from helloworld using lib bb v%s." % ( version ))
 
</pre>
 
</pre>
 +
 +
=== with data module ===
 +
 +
<pre>
 +
#!/usr/bin/env python
 +
# ex:ts=4:sw=4:sts=4:et
 +
# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
 +
 +
import os , bb
 +
from bb import data
 +
 +
hello = ("Hello from helloworld using lib bb v%s." % ( bb.__version__ ))
 +
 +
d = data.init()
 +
data.setVar('HELLO_MSG', hello, d)
 +
 +
mystring = data.getVar('HELLO_MSG', d, 1)
 +
bb.note(mystring)
 +
</pre>
 +
 +
data module is well documented because it uses doctest.
 +
Enjoy to play with the different methods.
 +
 +
=== with persist_data module ===
 +
 +
Now you want persistant data to exchange data between threads/tasks.
 +
This can be done using bb.persist_data module that uses sqlite via pyslite2.
 +
 +
<pre>
 +
#!/usr/bin/env python
 +
# ex:ts=4:sw=4:sts=4:et
 +
# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
 +
 +
import bb, os, sys
 +
from bb import data, persist_data, fetch
 +
 +
__version__ = "0.0.1"
 +
   
 +
def main():
 +
    """
 +
    The main Method
 +
    """
 +
   
 +
    # persist_data module need debug_level to be set
 +
    bb.msg.set_debug_level(0) 
 +
   
 +
    # init a data with PERSISTENT_DIR to set where the data will be saved
 +
    d = data.init()
 +
    data.setVar('PERSISTENT_DIR', os.getcwd(), d)
 +
   
 +
    # create persist_data base in bb_persist_data.sqlite3
 +
    pd = persist_data.PersistData(d)
 +
   
 +
    # create a sql table
 +
    pd.addDomain("MYBASE")
 +
   
 +
    # add a data in this table
 +
    pd.setValue( "MYBASE", "TOTO", "hello world!")
 +
   
 +
    # print it
 +
    val = pd.getValue ( "MYBASE", "TOTO")
 +
    print val
 +
   
 +
if __name__ == '__main__':
 +
    main()
 +
</pre>
 +
 +
You can edit and watch your base using [http://sqlitebrowser.sourceforge.net sqlitebrowser] for example. Should be useful for debug and test purpose. You can look also at fetch module source that use bb.persist_data.
 +
 +
[[Category:Dev]]

Latest revision as of 21:30, 8 February 2012

developer homepage

Source tree is in git at http://git.openembedded.org/bitbake/

Contents

[edit] Tutorial

This tutorial focus bitbake developement, not bbclass or openembedded developement that is documented elsewhere.

[edit] "Helloworld" using bb library

[edit] Simplest

#!/usr/bin/env python
# ex:ts=4:sw=4:sts=4:et
# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-

import bb

version = bb.__version__
bb.note("Hello from helloworld using lib bb v%s." % ( version ))

[edit] with data module

#!/usr/bin/env python
# ex:ts=4:sw=4:sts=4:et
# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-

import os , bb
from bb import data

hello = ("Hello from helloworld using lib bb v%s." % ( bb.__version__ ))

d = data.init()
data.setVar('HELLO_MSG', hello, d)

mystring = data.getVar('HELLO_MSG', d, 1)
bb.note(mystring)

data module is well documented because it uses doctest. Enjoy to play with the different methods.

[edit] with persist_data module

Now you want persistant data to exchange data between threads/tasks. This can be done using bb.persist_data module that uses sqlite via pyslite2.

#!/usr/bin/env python
# ex:ts=4:sw=4:sts=4:et
# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-

import bb, os, sys
from bb import data, persist_data, fetch

__version__ = "0.0.1"
    
def main():
    """
    The main Method
    """
    
    # persist_data module need debug_level to be set
    bb.msg.set_debug_level(0)  
    
    # init a data with PERSISTENT_DIR to set where the data will be saved
    d = data.init()
    data.setVar('PERSISTENT_DIR', os.getcwd(), d)
    
    # create persist_data base in bb_persist_data.sqlite3
    pd = persist_data.PersistData(d)
    
    # create a sql table
    pd.addDomain("MYBASE")
    
    # add a data in this table
    pd.setValue( "MYBASE", "TOTO", "hello world!")
    
    # print it
    val = pd.getValue ( "MYBASE", "TOTO")
    print val
    
if __name__ == '__main__':
    main()

You can edit and watch your base using sqlitebrowser for example. Should be useful for debug and test purpose. You can look also at fetch module source that use bb.persist_data.

Personal tools
Namespaces

Variants
Actions
Navigation
Categories
OE services
Toolbox