Patchwork [bitbake-devel,2/2] hob2: create a standalone deploy image tool

login
register
mail settings
Submitter Kang Kai
Date June 5, 2012, 3:37 a.m.
Message ID <df48506400665d5bb161559583327cbd94ce3eb7.1338866958.git.kai.kang@windriver.com>
Download mbox | patch
Permalink /patch/29227/
State New
Headers show

Comments

Kang Kai - June 5, 2012, 3:37 a.m.
[Yocto 2388]

Create a standalone deploy image tool using the existing dialog
including DeployImageDialog and ImageSelectionDialog.

Duplicate the gtk and pygtk versions check in the hob.py because this
will be run separately.

Update ui/crumbs/utils.py that it needs to 'import bb' when run this
tool.

Signed-off-by: Kang Kai <kai.kang@windriver.com>
---
 bitbake/bin/bitbake-deployimage   |  135 +++++++++++++++++++++++++++++++++++++
 bitbake/lib/bb/ui/crumbs/utils.py |    1 +
 2 files changed, 136 insertions(+), 0 deletions(-)
 create mode 100755 bitbake/bin/bitbake-deployimage
Shane Wang - June 5, 2012, 6:42 a.m.
> -----Original Message-----
> From: Kang Kai [mailto:kai.kang@windriver.com]
> Sent: Tuesday, June 05, 2012 11:37 AM
> To: dvhart@linux.intel.com
> Cc: Wang, Shane; zhenfeng.zhao@windriver.com;
> bitbake-devel@lists.openembedded.org
> Subject: [PATCH 2/2] hob2: create a standalone deploy image tool
> 
> [Yocto 2388]
> 
> Create a standalone deploy image tool using the existing dialog
> including DeployImageDialog and ImageSelectionDialog.
> 
> Duplicate the gtk and pygtk versions check in the hob.py because this
> will be run separately.
> 
> Update ui/crumbs/utils.py that it needs to 'import bb' when run this
> tool.
> 
> Signed-off-by: Kang Kai <kai.kang@windriver.com>
> ---
>  bitbake/bin/bitbake-deployimage   |  135
> +++++++++++++++++++++++++++++++++++++
>  bitbake/lib/bb/ui/crumbs/utils.py |    1 +
>  2 files changed, 136 insertions(+), 0 deletions(-)
>  create mode 100755 bitbake/bin/bitbake-deployimage
> 
> diff --git a/bitbake/bin/bitbake-deployimage
> b/bitbake/bin/bitbake-deployimage
> new file mode 100755
> index 0000000..8fdd21b
> --- /dev/null
> +++ b/bitbake/bin/bitbake-deployimage
> @@ -0,0 +1,135 @@
> +#!/usr/bin/python
> +
> +
> +requirements = "FATAL: Gtk+ 2.20.0 or higher, PyGtk version 2.22.0 or higher
> and PyGobject are required to use Hob"
Kai, I don't like you have this kind of limitation for GTK and PyGTK.
Hob.py does have because we want special efforts on the visual components. For this simple app,
I don't want you to exclude a lot of users who only have lower versions.



> diff --git a/bitbake/lib/bb/ui/crumbs/utils.py
> b/bitbake/lib/bb/ui/crumbs/utils.py
> index cd01a04..939864f 100644
> --- a/bitbake/lib/bb/ui/crumbs/utils.py
> +++ b/bitbake/lib/bb/ui/crumbs/utils.py
> @@ -22,6 +22,7 @@
>  # bitbake which will allow more flexibility.
> 
>  import os
> +import bb
Why is this needed? I don't see any change you made in utils.py.
Is that to say without this line, the functions in utils.py don't work?

> 
>  def which_terminal():
>      term = bb.utils.which(os.environ["PATH"], "xterm")
> --
> 1.7.5.4
Kang Kai - June 5, 2012, 7:04 a.m.
On 2012?06?05? 14:42, Wang, Shane wrote:
>> -----Original Message-----
>> From: Kang Kai [mailto:kai.kang@windriver.com]
>> Sent: Tuesday, June 05, 2012 11:37 AM
>> To: dvhart@linux.intel.com
>> Cc: Wang, Shane; zhenfeng.zhao@windriver.com;
>> bitbake-devel@lists.openembedded.org
>> Subject: [PATCH 2/2] hob2: create a standalone deploy image tool
>>
>> [Yocto 2388]
>>
>> Create a standalone deploy image tool using the existing dialog
>> including DeployImageDialog and ImageSelectionDialog.
>>
>> Duplicate the gtk and pygtk versions check in the hob.py because this
>> will be run separately.
>>
>> Update ui/crumbs/utils.py that it needs to 'import bb' when run this
>> tool.
>>
>> Signed-off-by: Kang Kai<kai.kang@windriver.com>
>> ---
>>   bitbake/bin/bitbake-deployimage   |  135
>> +++++++++++++++++++++++++++++++++++++
>>   bitbake/lib/bb/ui/crumbs/utils.py |    1 +
>>   2 files changed, 136 insertions(+), 0 deletions(-)
>>   create mode 100755 bitbake/bin/bitbake-deployimage
>>
>> diff --git a/bitbake/bin/bitbake-deployimage
>> b/bitbake/bin/bitbake-deployimage
>> new file mode 100755
>> index 0000000..8fdd21b
>> --- /dev/null
>> +++ b/bitbake/bin/bitbake-deployimage
>> @@ -0,0 +1,135 @@
>> +#!/usr/bin/python
>> +
>> +
>> +requirements = "FATAL: Gtk+ 2.20.0 or higher, PyGtk version 2.22.0 or higher
>> and PyGobject are required to use Hob"

Hi Shane,

> Kai, I don't like you have this kind of limitation for GTK and PyGTK.
> Hob.py does have because we want special efforts on the visual components. For this simple app,
> I don't want you to exclude a lot of users who only have lower versions.

Fine, I'll remove the version check.

>
>
>
>> diff --git a/bitbake/lib/bb/ui/crumbs/utils.py
>> b/bitbake/lib/bb/ui/crumbs/utils.py
>> index cd01a04..939864f 100644
>> --- a/bitbake/lib/bb/ui/crumbs/utils.py
>> +++ b/bitbake/lib/bb/ui/crumbs/utils.py
>> @@ -22,6 +22,7 @@
>>   # bitbake which will allow more flexibility.
>>
>>   import os
>> +import bb
> Why is this needed? I don't see any change you made in utils.py.
> Is that to say without this line, the functions in utils.py don't work?

Without the import, it just complains that

NameError: global name 'bb' is not defined

Regards,
Kai

>
>>   def which_terminal():
>>       term = bb.utils.which(os.environ["PATH"], "xterm")
>> --
>> 1.7.5.4
>
Shane Wang - June 5, 2012, 7:40 a.m.
Kang Kai wrote on 2012-06-05:

> On 2012?06?05? 14:42, Wang, Shane wrote:

>>> -----Original Message-----

>>> From: Kang Kai [mailto:kai.kang@windriver.com]

>>> Sent: Tuesday, June 05, 2012 11:37 AM

>>> To: dvhart@linux.intel.com

>>> Cc: Wang, Shane; zhenfeng.zhao@windriver.com;

>>> bitbake-devel@lists.openembedded.org

>>> Subject: [PATCH 2/2] hob2: create a standalone deploy image tool

>>> 

>>> diff --git a/bitbake/lib/bb/ui/crumbs/utils.py

>>> b/bitbake/lib/bb/ui/crumbs/utils.py

>>> index cd01a04..939864f 100644

>>> --- a/bitbake/lib/bb/ui/crumbs/utils.py

>>> +++ b/bitbake/lib/bb/ui/crumbs/utils.py

>>> @@ -22,6 +22,7 @@

>>>   # bitbake which will allow more flexibility.

>>>   

>>>   import os

>>> +import bb

>> Why is this needed? I don't see any change you made in utils.py.

>> Is that to say without this line, the functions in utils.py don't work?

> 

> Without the import, it just complains that

> 

> NameError: global name 'bb' is not defined

> 

> Regards,

> Kai


OK, It seems Saul didn't test it when he created utils.py;-)

--
Shane
Kang Kai - June 5, 2012, 8:15 a.m.
On 2012?06?05? 15:40, Wang, Shane wrote:
> Kang Kai wrote on 2012-06-05:
>
>> On 2012?06?05? 14:42, Wang, Shane wrote:
>>>> -----Original Message-----
>>>> From: Kang Kai [mailto:kai.kang@windriver.com]
>>>> Sent: Tuesday, June 05, 2012 11:37 AM
>>>> To: dvhart@linux.intel.com
>>>> Cc: Wang, Shane; zhenfeng.zhao@windriver.com;
>>>> bitbake-devel@lists.openembedded.org
>>>> Subject: [PATCH 2/2] hob2: create a standalone deploy image tool
>>>>
>>>> diff --git a/bitbake/lib/bb/ui/crumbs/utils.py
>>>> b/bitbake/lib/bb/ui/crumbs/utils.py
>>>> index cd01a04..939864f 100644
>>>> --- a/bitbake/lib/bb/ui/crumbs/utils.py
>>>> +++ b/bitbake/lib/bb/ui/crumbs/utils.py
>>>> @@ -22,6 +22,7 @@
>>>>    # bitbake which will allow more flexibility.
>>>>
>>>>    import os
>>>> +import bb
>>> Why is this needed? I don't see any change you made in utils.py.
>>> Is that to say without this line, the functions in utils.py don't work?
>> Without the import, it just complains that
>>
>> NameError: global name 'bb' is not defined
>>
>> Regards,
>> Kai
> OK, It seems Saul didn't test it when he created utils.py;-)

I am not quit sure because it is fine when call the deploy image in the 
hob. little weird.

Regards,
Kai

>
> --
> Shane
Darren Hart - June 5, 2012, 5:24 p.m.
On 06/05/2012 01:15 AM, Kang Kai wrote:
> On 2012?06?05? 15:40, Wang, Shane wrote:
>> Kang Kai wrote on 2012-06-05:
>>
>>> On 2012?06?05? 14:42, Wang, Shane wrote:
>>>>> -----Original Message-----
>>>>> From: Kang Kai [mailto:kai.kang@windriver.com]
>>>>> Sent: Tuesday, June 05, 2012 11:37 AM
>>>>> To: dvhart@linux.intel.com
>>>>> Cc: Wang, Shane; zhenfeng.zhao@windriver.com;
>>>>> bitbake-devel@lists.openembedded.org
>>>>> Subject: [PATCH 2/2] hob2: create a standalone deploy image tool
>>>>>
>>>>> diff --git a/bitbake/lib/bb/ui/crumbs/utils.py
>>>>> b/bitbake/lib/bb/ui/crumbs/utils.py
>>>>> index cd01a04..939864f 100644
>>>>> --- a/bitbake/lib/bb/ui/crumbs/utils.py
>>>>> +++ b/bitbake/lib/bb/ui/crumbs/utils.py
>>>>> @@ -22,6 +22,7 @@
>>>>>    # bitbake which will allow more flexibility.
>>>>>
>>>>>    import os
>>>>> +import bb
>>>> Why is this needed? I don't see any change you made in utils.py.
>>>> Is that to say without this line, the functions in utils.py don't work?
>>> Without the import, it just complains that
>>>
>>> NameError: global name 'bb' is not defined
>>>
>>> Regards,
>>> Kai
>> OK, It seems Saul didn't test it when he created utils.py;-)
> 
> I am not quit sure because it is fine when call the deploy image in the 
> hob. little weird.
> 

Probably because another file in the import list includes bb.

However, this change is not specific to the image tool and should be
broken out as a separate patch. utils.py makes calls to bb.utils.which()
on the third source line, so bb should certainly be imported in utils.py.

--
Darren


> Regards,
> Kai
> 
>>
>> --
>> Shane
>
Darren Hart - June 5, 2012, 5:55 p.m.
On 06/04/2012 08:37 PM, Kang Kai wrote:
> [Yocto 2388]
> 
> Create a standalone deploy image tool using the existing dialog
> including DeployImageDialog and ImageSelectionDialog.
> 
> Duplicate the gtk and pygtk versions check in the hob.py because this
> will be run separately.
> 
> Update ui/crumbs/utils.py that it needs to 'import bb' when run this
> tool.

Should be a separate patch as it's independent of the image writer.

> 
> Signed-off-by: Kang Kai <kai.kang@windriver.com>
> ---
>  bitbake/bin/bitbake-deployimage   |  135 +++++++++++++++++++++++++++++++++++++
>  bitbake/lib/bb/ui/crumbs/utils.py |    1 +
>  2 files changed, 136 insertions(+), 0 deletions(-)
>  create mode 100755 bitbake/bin/bitbake-deployimage
> 
> diff --git a/bitbake/bin/bitbake-deployimage b/bitbake/bin/bitbake-deployimage
> new file mode 100755
> index 0000000..8fdd21b
> --- /dev/null
> +++ b/bitbake/bin/bitbake-deployimage

A shorter name might be appropriate. Since this really doesn't involve
bitbake, maye we can drop that from the name? I would also suggest
avoiding the term "deploy" as it has a very specific meaning for
bitbake. Consider:

write-image
gddimage
hob-image
hob-dd

I don't love any of these, just thinking out loud.


> @@ -0,0 +1,135 @@
> +#!/usr/bin/python

This should be:

#!/usr/bin/env python



> +
> +# Copyright (c) 2012 Wind River Systems, Inc.
> +#
> +# This program is free software; you can redistribute it and/or modify
> +# it under the terms of the GNU General Public License version 2 as
> +# published by the Free Software Foundation.
> +#
> +# This program is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
> +# See the GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program; if not, write to the Free Software
> +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
> +
> +import os
> +import sys
> +import optparse
> +
> +requirements = "FATAL: Gtk+ 2.20.0 or higher, PyGtk version 2.22.0 or higher and PyGobject are required to use Hob"

But this isn't Hob, right? What is required to run just this script? I
think the requirements check is a good idea, but let's not unnecessarily
fail to run with overly strict requirement.s

> +try:
> +    import gtk
> +    import pygtk
> +
> +    pygtk.require('2.0') # to be certain we don't have gtk+ 1.x !?!
> +    gtkver = gtk.gtk_version
> +    pygtkver = gtk.pygtk_version
> +    if gtkver  < (2, 20, 0) or pygtkver < (2, 22, 0):
> +        sys.exit("%s,\nYou have Gtk+ %s and PyGtk %s." % (requirements,
> +                    ".".join(map(str, gtkver)),
> +                    ".".join(map(str, pygtkver))))
> +
> +except ImportError as exc:
> +    sys.exit("%s (%s)." % (requirements, str(exc)))
> +
> +sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname( \
> +                                    os.path.abspath(__file__))), 'lib'))
> +try:
> +    import bb
> +except RuntimeError as exc:
> +    sys.exit(str(exc))
> +
> +from bb.ui.crumbs.hig import DeployImageDialog, ImageSelectionDialog, CrumbsMessageDialog
> +from bb.ui.crumbs.hobwidget import HobAltButton, HobButton
> +
> +# I put all the fs bitbake supported here. Need more test.
> +DEPLOYABLE_IMAGE_TYPES = ["jffs2", "cramfs", "ext2", "ext3", "btrfs", "squashfs", "ubi", "vmdk"]
> +Title = "Usb Image Maker"

s/Usb/USB/

Probably shouldn't be USB only in the future.

> +
> +class DeployWindow(gtk.Window):
> +    def __init__(self, image_path=''):
> +        super(DeployWindow, self).__init__()
> +
> +        if len(image_path) > 0:
> +            valid = True
> +            if not os.path.exists(image_path):
> +                valid = False
> +                lbl = "<b>Invalid image file path</b>\nYou could use <b>Select Image</b> button to select image"

Missing punctuation and articles:

"<b>Invalid image file path.</b>\nYou can use the <b>Select Image</b>
button to select an image."

Or

"<b>Invalid image file path: %s.</b>\nPress <b>Select Image</b> to
select an image." % (image_path)


> +            else:
> +                image_path = os.path.abspath(image_path)
> +                extend_name = os.path.splitext(image_path)[1][1:]
> +                if extend_name not in DEPLOYABLE_IMAGE_TYPES:
> +                    valid = False
> +                    lbl = "<b>Undeployable imge</b>\nYou could use <b>Select Image</b> button to select image"

Typo, missing articles and punctuation. Consider:

"<b>Undeployable image type: %s</b>\nPress <b>Select Image</b> to select
an image." % (extend_name)

> +
> +            if not valid:
> +                image_path = ''
> +                crumbs_dialog = CrumbsMessageDialog(self, lbl, gtk.STOCK_DIALOG_INFO)
> +                button = crumbs_dialog.add_button("Close", gtk.RESPONSE_OK)
> +                HobButton.style_button(button)
> +                crumbs_dialog.run()
> +                crumbs_dialog.destroy()
> +
> +        self.deploy_dialog = DeployImageDialog(Title, image_path, self,
> +                                        gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT
> +                                        | gtk.DIALOG_NO_SEPARATOR, None, singleton=True)

Are you creating a proper singleton, or is this just used to indicate
"stand alone" ? Just curious as singleton's are quite difficult to do
properly in Python.

> +        close_button = self.deploy_dialog.add_button("Close", gtk.RESPONSE_NO)
> +        HobAltButton.style_button(close_button)
> +        close_button.connect('clicked', gtk.main_quit)
> +
> +        make_button = self.deploy_dialog.add_button("Make USB image", gtk.RESPONSE_YES)
> +        HobAltButton.style_button(make_button)
> +
> +        self.deploy_dialog.connect('select_image_clicked', self.select_image_clicked_cb)
> +        self.deploy_dialog.connect('destroy', gtk.main_quit)
> +        response = self.deploy_dialog.show()
> +
> +    def select_image_clicked_cb(self, dialog):
> +        cwd = os.getcwd()
> +        dialog = ImageSelectionDialog(cwd, DEPLOYABLE_IMAGE_TYPES, Title, self, gtk.FILE_CHOOSER_ACTION_SAVE )
> +        button = dialog.add_button("Cancel", gtk.RESPONSE_NO)
> +        HobAltButton.style_button(button)
> +        button = dialog.add_button("Open", gtk.RESPONSE_YES)
> +        HobAltButton.style_button(button)
> +        response = dialog.run()
> +
> +        if response == gtk.RESPONSE_YES:
> +            if not dialog.image_names:
> +                lbl = "<b>No selections made</b>\nYou have not made any selections"

This string is a bit redundant. The other strings in the app give
instructions to resolve the failure, should this as well?

> +                crumbs_dialog = CrumbsMessageDialog(self, lbl, gtk.STOCK_DIALOG_INFO)
> +                button = crumbs_dialog.add_button("Close", gtk.RESPONSE_OK)
> +                HobButton.style_button(button)
> +                crumbs_dialog.run()
> +                crumbs_dialog.destroy()
> +                dialog.destroy()
> +                return
> +
> +            # get the full path of image
> +            image_path = os.path.join(dialog.image_folder, dialog.image_names[0])
> +            self.deploy_dialog.set_image_text_buffer(image_path)
> +            self.deploy_dialog.set_image_path(image_path)
> +
> +        dialog.destroy()
> +
> +def main():
> +    parser = optparse.OptionParser(
> +                usage = """%prog [-h] [image_file]
> +
> +This deploy image tool try to deploy the bitbake images to USB devices.
> +You could provides the image file from command line or select it use the
> +GUI tool.""")

bitbake-deployimage writes bootable images to USB devices. You can
provide the image file on the command line or select it using the GUI.

> +
> +    options, args = parser.parse_args(sys.argv)
> +    image_file = args[1] if len(args) > 1 else ''
> +    dw = DeployWindow(image_file)
> +
> +if __name__ == '__main__':
> +    try:
> +        main()
> +        gtk.main()
> +    except Exception:
> +        import traceback
> +        traceback.print_exc(3)
> diff --git a/bitbake/lib/bb/ui/crumbs/utils.py b/bitbake/lib/bb/ui/crumbs/utils.py
> index cd01a04..939864f 100644
> --- a/bitbake/lib/bb/ui/crumbs/utils.py
> +++ b/bitbake/lib/bb/ui/crumbs/utils.py
> @@ -22,6 +22,7 @@
>  # bitbake which will allow more flexibility.
>  
>  import os
> +import bb

separate patch.

>  
>  def which_terminal():
>      term = bb.utils.which(os.environ["PATH"], "xterm")
Kang Kai - June 6, 2012, 3:29 a.m.
On 2012?06?06? 01:24, Darren Hart wrote:
>
> On 06/05/2012 01:15 AM, Kang Kai wrote:
>> On 2012?06?05? 15:40, Wang, Shane wrote:
>>> Kang Kai wrote on 2012-06-05:
>>>
>>>> On 2012?06?05? 14:42, Wang, Shane wrote:
>>>>>> -----Original Message-----
>>>>>> From: Kang Kai [mailto:kai.kang@windriver.com]
>>>>>> Sent: Tuesday, June 05, 2012 11:37 AM
>>>>>> To: dvhart@linux.intel.com
>>>>>> Cc: Wang, Shane; zhenfeng.zhao@windriver.com;
>>>>>> bitbake-devel@lists.openembedded.org
>>>>>> Subject: [PATCH 2/2] hob2: create a standalone deploy image tool
>>>>>>
>>>>>> diff --git a/bitbake/lib/bb/ui/crumbs/utils.py
>>>>>> b/bitbake/lib/bb/ui/crumbs/utils.py
>>>>>> index cd01a04..939864f 100644
>>>>>> --- a/bitbake/lib/bb/ui/crumbs/utils.py
>>>>>> +++ b/bitbake/lib/bb/ui/crumbs/utils.py
>>>>>> @@ -22,6 +22,7 @@
>>>>>>     # bitbake which will allow more flexibility.
>>>>>>
>>>>>>     import os
>>>>>> +import bb
>>>>> Why is this needed? I don't see any change you made in utils.py.
>>>>> Is that to say without this line, the functions in utils.py don't work?
>>>> Without the import, it just complains that
>>>>
>>>> NameError: global name 'bb' is not defined
>>>>
>>>> Regards,
>>>> Kai
>>> OK, It seems Saul didn't test it when he created utils.py;-)
>> I am not quit sure because it is fine when call the deploy image in the
>> hob. little weird.
>>
> Probably because another file in the import list includes bb.
>
> However, this change is not specific to the image tool and should be
> broken out as a separate patch. utils.py makes calls to bb.utils.which()
> on the third source line, so bb should certainly be imported in utils.py.

But I import bb in the bitbake-deployimage too. It still complains lack 
of module bb.

Regards,
Kai



>
> --
> Darren
>
>
>> Regards,
>> Kai
>>
>>> --
>>> Shane
Shane Wang - June 6, 2012, 5:01 a.m.
Kang Kai wrote on 2012-06-06:

> On 2012?06?06? 01:24, Darren Hart wrote:

>> 

>> On 06/05/2012 01:15 AM, Kang Kai wrote:

>>> On 2012?06?05? 15:40, Wang, Shane wrote:

>>>> Kang Kai wrote on 2012-06-05:

>>>> 

>>>>> On 2012?06?05? 14:42, Wang, Shane wrote:

>>>>>>> -----Original Message-----

>>>>>>> From: Kang Kai [mailto:kai.kang@windriver.com]

>>>>>>> Sent: Tuesday, June 05, 2012 11:37 AM

>>>>>>> To: dvhart@linux.intel.com

>>>>>>> Cc: Wang, Shane; zhenfeng.zhao@windriver.com;

>>>>>>> bitbake-devel@lists.openembedded.org

>>>>>>> Subject: [PATCH 2/2] hob2: create a standalone deploy image tool

>>>>>>> 

>>>>>>> diff --git a/bitbake/lib/bb/ui/crumbs/utils.py

>>>>>>> b/bitbake/lib/bb/ui/crumbs/utils.py

>>>>>>> index cd01a04..939864f 100644

>>>>>>> --- a/bitbake/lib/bb/ui/crumbs/utils.py

>>>>>>> +++ b/bitbake/lib/bb/ui/crumbs/utils.py

>>>>>>> @@ -22,6 +22,7 @@

>>>>>>>     # bitbake which will allow more flexibility.

>>>>>>>     

>>>>>>>     import os

>>>>>>> +import bb

>>>>>> Why is this needed? I don't see any change you made in utils.py.

>>>>>> Is that to say without this line, the functions in utils.py don't work?

>>>>> Without the import, it just complains that

>>>>> 

>>>>> NameError: global name 'bb' is not defined

>>>>> 

>>>>> Regards,

>>>>> Kai

>>>> OK, It seems Saul didn't test it when he created utils.py;-)

>>> I am not quit sure because it is fine when call the deploy image in the

>>> hob. little weird.

>>> 

>> Probably because another file in the import list includes bb.

>> 

>> However, this change is not specific to the image tool and should be

>> broken out as a separate patch. utils.py makes calls to bb.utils.which()

>> on the third source line, so bb should certainly be imported in utils.py.

> 

> But I import bb in the bitbake-deployimage too. It still complains lack

> of module bb.

> 

> Regards,

> Kai

> 


Never mind. I think the rule is you should import in the file where you use.
There is no assumption that others help to import.

Ditto in C language for including header files.

--
Shane

Patch

diff --git a/bitbake/bin/bitbake-deployimage b/bitbake/bin/bitbake-deployimage
new file mode 100755
index 0000000..8fdd21b
--- /dev/null
+++ b/bitbake/bin/bitbake-deployimage
@@ -0,0 +1,135 @@ 
+#!/usr/bin/python
+
+# Copyright (c) 2012 Wind River Systems, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+import os
+import sys
+import optparse
+
+requirements = "FATAL: Gtk+ 2.20.0 or higher, PyGtk version 2.22.0 or higher and PyGobject are required to use Hob"
+try:
+    import gtk
+    import pygtk
+
+    pygtk.require('2.0') # to be certain we don't have gtk+ 1.x !?!
+    gtkver = gtk.gtk_version
+    pygtkver = gtk.pygtk_version
+    if gtkver  < (2, 20, 0) or pygtkver < (2, 22, 0):
+        sys.exit("%s,\nYou have Gtk+ %s and PyGtk %s." % (requirements,
+                    ".".join(map(str, gtkver)),
+                    ".".join(map(str, pygtkver))))
+
+except ImportError as exc:
+    sys.exit("%s (%s)." % (requirements, str(exc)))
+
+sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname( \
+                                    os.path.abspath(__file__))), 'lib'))
+try:
+    import bb
+except RuntimeError as exc:
+    sys.exit(str(exc))
+
+from bb.ui.crumbs.hig import DeployImageDialog, ImageSelectionDialog, CrumbsMessageDialog
+from bb.ui.crumbs.hobwidget import HobAltButton, HobButton
+
+# I put all the fs bitbake supported here. Need more test.
+DEPLOYABLE_IMAGE_TYPES = ["jffs2", "cramfs", "ext2", "ext3", "btrfs", "squashfs", "ubi", "vmdk"]
+Title = "Usb Image Maker"
+
+class DeployWindow(gtk.Window):
+    def __init__(self, image_path=''):
+        super(DeployWindow, self).__init__()
+
+        if len(image_path) > 0:
+            valid = True
+            if not os.path.exists(image_path):
+                valid = False
+                lbl = "<b>Invalid image file path</b>\nYou could use <b>Select Image</b> button to select image"
+            else:
+                image_path = os.path.abspath(image_path)
+                extend_name = os.path.splitext(image_path)[1][1:]
+                if extend_name not in DEPLOYABLE_IMAGE_TYPES:
+                    valid = False
+                    lbl = "<b>Undeployable imge</b>\nYou could use <b>Select Image</b> button to select image"
+
+            if not valid:
+                image_path = ''
+                crumbs_dialog = CrumbsMessageDialog(self, lbl, gtk.STOCK_DIALOG_INFO)
+                button = crumbs_dialog.add_button("Close", gtk.RESPONSE_OK)
+                HobButton.style_button(button)
+                crumbs_dialog.run()
+                crumbs_dialog.destroy()
+
+        self.deploy_dialog = DeployImageDialog(Title, image_path, self,
+                                        gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT
+                                        | gtk.DIALOG_NO_SEPARATOR, None, singleton=True)
+        close_button = self.deploy_dialog.add_button("Close", gtk.RESPONSE_NO)
+        HobAltButton.style_button(close_button)
+        close_button.connect('clicked', gtk.main_quit)
+
+        make_button = self.deploy_dialog.add_button("Make USB image", gtk.RESPONSE_YES)
+        HobAltButton.style_button(make_button)
+
+        self.deploy_dialog.connect('select_image_clicked', self.select_image_clicked_cb)
+        self.deploy_dialog.connect('destroy', gtk.main_quit)
+        response = self.deploy_dialog.show()
+
+    def select_image_clicked_cb(self, dialog):
+        cwd = os.getcwd()
+        dialog = ImageSelectionDialog(cwd, DEPLOYABLE_IMAGE_TYPES, Title, self, gtk.FILE_CHOOSER_ACTION_SAVE )
+        button = dialog.add_button("Cancel", gtk.RESPONSE_NO)
+        HobAltButton.style_button(button)
+        button = dialog.add_button("Open", gtk.RESPONSE_YES)
+        HobAltButton.style_button(button)
+        response = dialog.run()
+
+        if response == gtk.RESPONSE_YES:
+            if not dialog.image_names:
+                lbl = "<b>No selections made</b>\nYou have not made any selections"
+                crumbs_dialog = CrumbsMessageDialog(self, lbl, gtk.STOCK_DIALOG_INFO)
+                button = crumbs_dialog.add_button("Close", gtk.RESPONSE_OK)
+                HobButton.style_button(button)
+                crumbs_dialog.run()
+                crumbs_dialog.destroy()
+                dialog.destroy()
+                return
+
+            # get the full path of image
+            image_path = os.path.join(dialog.image_folder, dialog.image_names[0])
+            self.deploy_dialog.set_image_text_buffer(image_path)
+            self.deploy_dialog.set_image_path(image_path)
+
+        dialog.destroy()
+
+def main():
+    parser = optparse.OptionParser(
+                usage = """%prog [-h] [image_file]
+
+This deploy image tool try to deploy the bitbake images to USB devices.
+You could provides the image file from command line or select it use the
+GUI tool.""")
+
+    options, args = parser.parse_args(sys.argv)
+    image_file = args[1] if len(args) > 1 else ''
+    dw = DeployWindow(image_file)
+
+if __name__ == '__main__':
+    try:
+        main()
+        gtk.main()
+    except Exception:
+        import traceback
+        traceback.print_exc(3)
diff --git a/bitbake/lib/bb/ui/crumbs/utils.py b/bitbake/lib/bb/ui/crumbs/utils.py
index cd01a04..939864f 100644
--- a/bitbake/lib/bb/ui/crumbs/utils.py
+++ b/bitbake/lib/bb/ui/crumbs/utils.py
@@ -22,6 +22,7 @@ 
 # bitbake which will allow more flexibility.
 
 import os
+import bb
 
 def which_terminal():
     term = bb.utils.which(os.environ["PATH"], "xterm")