summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKang Kai <kai.kang@windriver.com>2012-06-06 17:52:28 +0800
committerRichard Purdie <richard.purdie@linuxfoundation.org>2012-06-08 12:13:43 +0100
commit0612cf3fcb3365e7721a2d5c331f8cd2647ae60b (patch)
tree63f46f80a1dc8205c380836ad3176850697787f4
parent7828e9eee25c74cef6671f69268a4589e9895938 (diff)
downloadpoky-0612cf3fcb3365e7721a2d5c331f8cd2647ae60b.tar.gz
hob2: create a standalone deploy image tool
[Yocto 2388] Create a deploy image tool using the existing dialog including DeployImageDialog and ImageSelectionDialog. This tool writes bootable images to USB devices, and it can be run directly without hob. Signed-off-by: Kang Kai <kai.kang@windriver.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rwxr-xr-xbitbake/bin/image-writer120
1 files changed, 120 insertions, 0 deletions
diff --git a/bitbake/bin/image-writer b/bitbake/bin/image-writer
new file mode 100755
index 0000000000..3f9f5c1ed5
--- /dev/null
+++ b/bitbake/bin/image-writer
@@ -0,0 +1,120 @@
1#!/usr/bin/env python
2
3# Copyright (c) 2012 Wind River Systems, Inc.
4#
5# This program is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License version 2 as
7# published by the Free Software Foundation.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12# See the GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program; if not, write to the Free Software
16# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
18import os
19import sys
20sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname( \
21 os.path.abspath(__file__))), 'lib'))
22try:
23 import bb
24except RuntimeError as exc:
25 sys.exit(str(exc))
26
27import gtk
28import optparse
29import pygtk
30
31from bb.ui.crumbs.hig import DeployImageDialog, ImageSelectionDialog, CrumbsMessageDialog
32from bb.ui.crumbs.hobwidget import HobAltButton, HobButton
33
34# I put all the fs bitbake supported here. Need more test.
35DEPLOYABLE_IMAGE_TYPES = ["jffs2", "cramfs", "ext2", "ext3", "btrfs", "squashfs", "ubi", "vmdk"]
36Title = "USB Image Maker"
37
38class DeployWindow(gtk.Window):
39 def __init__(self, image_path=''):
40 super(DeployWindow, self).__init__()
41
42 if len(image_path) > 0:
43 valid = True
44 if not os.path.exists(image_path):
45 valid = False
46 lbl = "<b>Invalid image file path: %s.</b>\nPress <b>Select Image</b> button to select an image." % image_path
47 else:
48 image_path = os.path.abspath(image_path)
49 extend_name = os.path.splitext(image_path)[1][1:]
50 if extend_name not in DEPLOYABLE_IMAGE_TYPES:
51 valid = False
52 lbl = "<b>Undeployable imge type: %s</b>\nPress <b>Select Image</b> button to select an image." % extend_name
53
54 if not valid:
55 image_path = ''
56 crumbs_dialog = CrumbsMessageDialog(self, lbl, gtk.STOCK_DIALOG_INFO)
57 button = crumbs_dialog.add_button("Close", gtk.RESPONSE_OK)
58 HobButton.style_button(button)
59 crumbs_dialog.run()
60 crumbs_dialog.destroy()
61
62 self.deploy_dialog = DeployImageDialog(Title, image_path, self,
63 gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT
64 | gtk.DIALOG_NO_SEPARATOR, None, standalone=True)
65 close_button = self.deploy_dialog.add_button("Close", gtk.RESPONSE_NO)
66 HobAltButton.style_button(close_button)
67 close_button.connect('clicked', gtk.main_quit)
68
69 make_button = self.deploy_dialog.add_button("Make USB image", gtk.RESPONSE_YES)
70 HobAltButton.style_button(make_button)
71
72 self.deploy_dialog.connect('select_image_clicked', self.select_image_clicked_cb)
73 self.deploy_dialog.connect('destroy', gtk.main_quit)
74 response = self.deploy_dialog.show()
75
76 def select_image_clicked_cb(self, dialog):
77 cwd = os.getcwd()
78 dialog = ImageSelectionDialog(cwd, DEPLOYABLE_IMAGE_TYPES, Title, self, gtk.FILE_CHOOSER_ACTION_SAVE )
79 button = dialog.add_button("Cancel", gtk.RESPONSE_NO)
80 HobAltButton.style_button(button)
81 button = dialog.add_button("Open", gtk.RESPONSE_YES)
82 HobAltButton.style_button(button)
83 response = dialog.run()
84
85 if response == gtk.RESPONSE_YES:
86 if not dialog.image_names:
87 lbl = "<b>No selections made</b>\nClicked the radio button to select a image."
88 crumbs_dialog = CrumbsMessageDialog(self, lbl, gtk.STOCK_DIALOG_INFO)
89 button = crumbs_dialog.add_button("Close", gtk.RESPONSE_OK)
90 HobButton.style_button(button)
91 crumbs_dialog.run()
92 crumbs_dialog.destroy()
93 dialog.destroy()
94 return
95
96 # get the full path of image
97 image_path = os.path.join(dialog.image_folder, dialog.image_names[0])
98 self.deploy_dialog.set_image_text_buffer(image_path)
99 self.deploy_dialog.set_image_path(image_path)
100
101 dialog.destroy()
102
103def main():
104 parser = optparse.OptionParser(
105 usage = """%prog [-h] [image_file]
106
107%prog writes bootable images to USB devices. You can
108provide the image file on the command line or select it using the GUI.""")
109
110 options, args = parser.parse_args(sys.argv)
111 image_file = args[1] if len(args) > 1 else ''
112 dw = DeployWindow(image_file)
113
114if __name__ == '__main__':
115 try:
116 main()
117 gtk.main()
118 except Exception:
119 import traceback
120 traceback.print_exc(3)