[FE training-materials-updates] yocto: slides: add a part about Python tasks
Antoine Ténart
antoine.tenart at free-electrons.com
Wed Sep 7 10:43:03 CEST 2016
Repository : git://git.free-electrons.com/training-materials.git
On branch : master
Link : http://git.free-electrons.com/training-materials/commit/?id=2010a784aa12c0ab2089a8eb032862a9cff0d033
>---------------------------------------------------------------
commit 2010a784aa12c0ab2089a8eb032862a9cff0d033
Author: Antoine Tenart <antoine.tenart at free-electrons.com>
Date: Wed Sep 7 10:20:39 2016 +0200
yocto: slides: add a part about Python tasks
Signed-off-by: Antoine Tenart <antoine.tenart at free-electrons.com>
>---------------------------------------------------------------
2010a784aa12c0ab2089a8eb032862a9cff0d033
slides/yocto-recipe-extra/yocto-recipe-extra.tex | 56 ++++++++++++++++++++++++
1 file changed, 56 insertions(+)
diff --git a/slides/yocto-recipe-extra/yocto-recipe-extra.tex b/slides/yocto-recipe-extra/yocto-recipe-extra.tex
index 3947f74..0d84d56 100644
--- a/slides/yocto-recipe-extra/yocto-recipe-extra.tex
+++ b/slides/yocto-recipe-extra/yocto-recipe-extra.tex
@@ -113,6 +113,62 @@ PACKAGECONFIG ??= " \
\end{itemize}
\end{frame}
+\subsection{Python tasks}
+
+\begin{frame}
+ \frametitle{Tasks in Python}
+ \begin{itemize}
+ \item Tasks can be written in Python when using the keyword
+ \code{python}.
+ \item The \code{d} variable is accessible, and represents the
+ BitBake datastore (where variables are stored).
+ \item Two modules are automatically imported:
+ \begin{itemize}
+ \item \code{bb}: to access BitBake's internal functions.
+ \item \code{os}: Python's operating system interfaces.
+ \end{itemize}
+ \item You can import other modules using the keyword
+ \code{import}.
+ \item Anonymous Python functions are executed during parsing.
+ \end{itemize}
+\end{frame}
+
+\begin{frame}
+ \frametitle{Accessing the datastore with Python}
+ \begin{itemize}
+ \item The \code{d} variable is accessible within Python tasks.
+ \end{itemize}
+ \begin{description}
+ \item[\code{d.getVar("X", expand=False)}] Returns the value of
+ \code{X}.
+ \item[\code{d.setVar("X", "value")}] Set \code{X}.
+ \item[\code{d.appendVar("X", "value")}] Append \code{value} to
+ \code{X}.
+ \item[\code{d.prependVar("X", "value")}] Prepend \code{value} to
+ \code{X}.
+ \item[\code{d.expand(expression)}] Expend variables in
+ \code{expression}.
+ \end{description}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{Python task example}
+ \begin{minted}{python}
+# Anonymous function
+python () {
+ if d.getVar("FOO", True) == "example":
+ d.setVar("BAR", "Hello, World.")
+}
+
+# Task
+python do_settime() {
+ import time
+
+ d.setVar("TIME", time.strftime('%Y%m%d', time.gmtime()))
+}
+ \end{minted}
+\end{frame}
+
\subsection{Root filesystem creation}
\begin{frame}[fragile]
More information about the training-materials-updates
mailing list