All of lore.kernel.org
 help / color / mirror / Atom feed
* Use python in variable assigment of a recipe
@ 2012-02-28  9:26 Steffen Sledz
  2012-02-28  9:55 ` Paul Eggleton
  0 siblings, 1 reply; 5+ messages in thread
From: Steffen Sledz @ 2012-02-28  9:26 UTC (permalink / raw)
  To: openembedded-devel

According to the user manual it is possible to use python code in variable assignments by using ${@...}.

I like to use a function (subprocess.check_output) here which requires an import statement. Where do i have to place this import?

And another question. Is it possible to determine the path to the recipe itself from with it?

Thx,
Steffen

-- 
DResearch Fahrzeugelektronik GmbH
Otto-Schmirgal-Str. 3, 10319 Berlin, Germany
Tel: +49 30 515932-237 mailto:sledz@dresearch-fe.de
Fax: +49 30 515932-299
Geschäftsführer: Dr. Michael Weber, Werner Mögle;
Amtsgericht Berlin Charlottenburg; HRB 130120 B;
Ust.-IDNr. DE273952058



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Use python in variable assigment of a recipe
  2012-02-28  9:26 Use python in variable assigment of a recipe Steffen Sledz
@ 2012-02-28  9:55 ` Paul Eggleton
  2012-02-28 12:11   ` Steffen Sledz
  0 siblings, 1 reply; 5+ messages in thread
From: Paul Eggleton @ 2012-02-28  9:55 UTC (permalink / raw)
  To: Steffen Sledz; +Cc: openembedded-devel

On Tuesday 28 February 2012 10:26:16 Steffen Sledz wrote:
> According to the user manual it is possible to use python code in variable
> assignments by using ${@...}.
> 
> I like to use a function (subprocess.check_output) here which requires an
> import statement. Where do i have to place this import?

If you've got more than one line of Python then you should probably define a 
normal Python function (just use "def" as you would in a normal python script 
- there are plenty of examples of this) and then call this using ${@...}.
 
> And another question. Is it possible to determine the path to the recipe
> itself from with it?

I think you just need to get the value of the FILE variable e.g

 d.getVar('FILE', True)

Cheers,
Paul

-- 

Paul Eggleton
Intel Open Source Technology Centre



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Use python in variable assigment of a recipe
  2012-02-28  9:55 ` Paul Eggleton
@ 2012-02-28 12:11   ` Steffen Sledz
  2012-02-28 13:28     ` Paul Eggleton
  2012-02-28 13:33     ` Phil Blundell
  0 siblings, 2 replies; 5+ messages in thread
From: Steffen Sledz @ 2012-02-28 12:11 UTC (permalink / raw)
  To: Paul Eggleton; +Cc: openembedded-devel

On 28.02.2012 10:55, Paul Eggleton wrote:
> On Tuesday 28 February 2012 10:26:16 Steffen Sledz wrote:
>> According to the user manual it is possible to use python code in variable
>> assignments by using ${@...}.
>>
>> I like to use a function (subprocess.check_output) here which requires an
>> import statement. Where do i have to place this import?
> 
> If you've got more than one line of Python then you should probably define a 
> normal Python function (just use "def" as you would in a normal python script 
> - there are plenty of examples of this) and then call this using ${@...}.

Works. Thx.

>> And another question. Is it possible to determine the path to the recipe
>> itself from with it?
> 
> I think you just need to get the value of the FILE variable e.g
> 
>  d.getVar('FILE', True)

Because i'm working with oe-classic i tried this (found in some other examples):

  MYVAR = "${@my_func()}"

  def my_func():
      bbpath = os.path.dirname(bb.data.getVar('FILE',d,1))
      ...

But this leads to an error:

  NameError: global name 'd' is not defined

:(

-- 
DResearch Fahrzeugelektronik GmbH
Otto-Schmirgal-Str. 3, 10319 Berlin, Germany
Tel: +49 30 515932-237 mailto:sledz@dresearch-fe.de
Fax: +49 30 515932-299
Geschäftsführer: Dr. Michael Weber, Werner Mögle;
Amtsgericht Berlin Charlottenburg; HRB 130120 B;
Ust.-IDNr. DE273952058



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Use python in variable assigment of a recipe
  2012-02-28 12:11   ` Steffen Sledz
@ 2012-02-28 13:28     ` Paul Eggleton
  2012-02-28 13:33     ` Phil Blundell
  1 sibling, 0 replies; 5+ messages in thread
From: Paul Eggleton @ 2012-02-28 13:28 UTC (permalink / raw)
  To: Steffen Sledz; +Cc: openembedded-devel

On Tuesday 28 February 2012 13:11:08 Steffen Sledz wrote:
> Because i'm working with oe-classic i tried this (found in some other
> examples):
> 
>   MYVAR = "${@my_func()}"
> 
>   def my_func():
>       bbpath = os.path.dirname(bb.data.getVar('FILE',d,1))
>       ...
> 
> But this leads to an error:
> 
>   NameError: global name 'd' is not defined

If you pass in d it should work, i.e.:

   MYVAR = "${@my_func(d)}"
 
   def my_func(d):
       bbpath = os.path.dirname(bb.data.getVar('FILE',d,1))

BTW, d.getVar() should work fine in OE-Classic (or to be fully correct, it 
should work fine with older versions of bitbake).

Cheers,
Paul

-- 

Paul Eggleton
Intel Open Source Technology Centre



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Use python in variable assigment of a recipe
  2012-02-28 12:11   ` Steffen Sledz
  2012-02-28 13:28     ` Paul Eggleton
@ 2012-02-28 13:33     ` Phil Blundell
  1 sibling, 0 replies; 5+ messages in thread
From: Phil Blundell @ 2012-02-28 13:33 UTC (permalink / raw)
  To: openembedded-devel

On Tue, 2012-02-28 at 13:11 +0100, Steffen Sledz wrote:
> Because i'm working with oe-classic i tried this (found in some other examples):
> 
>   MYVAR = "${@my_func()}"
> 
>   def my_func():
>       bbpath = os.path.dirname(bb.data.getVar('FILE',d,1))
>       ...
> 
> But this leads to an error:
> 
>   NameError: global name 'd' is not defined
> 
> :(

MYVAR = "${@my_func(d)}"

def my_func(d):
   ...

p.






^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-02-28 13:42 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-02-28  9:26 Use python in variable assigment of a recipe Steffen Sledz
2012-02-28  9:55 ` Paul Eggleton
2012-02-28 12:11   ` Steffen Sledz
2012-02-28 13:28     ` Paul Eggleton
2012-02-28 13:33     ` Phil Blundell

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.