blob: 7d7116780b188d4a113afcd0cf2c234262d18e50 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001#!/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.hobwidget import HobAltButton, HobButton
32from bb.ui.crumbs.hig.crumbsmessagedialog import CrumbsMessageDialog
33from bb.ui.crumbs.hig.deployimagedialog import DeployImageDialog
34from bb.ui.crumbs.hig.imageselectiondialog import ImageSelectionDialog
35
36# I put all the fs bitbake supported here. Need more test.
37DEPLOYABLE_IMAGE_TYPES = ["jffs2", "cramfs", "ext2", "ext3", "ext4", "btrfs", "squashfs", "ubi", "vmdk"]
38Title = "USB Image Writer"
39
40class DeployWindow(gtk.Window):
41 def __init__(self, image_path=''):
42 super(DeployWindow, self).__init__()
43
44 if len(image_path) > 0:
45 valid = True
46 if not os.path.exists(image_path):
47 valid = False
48 lbl = "<b>Invalid image file path: %s.</b>\nPress <b>Select Image</b> to select an image." % image_path
49 else:
50 image_path = os.path.abspath(image_path)
51 extend_name = os.path.splitext(image_path)[1][1:]
52 if extend_name not in DEPLOYABLE_IMAGE_TYPES:
53 valid = False
54 lbl = "<b>Undeployable imge type: %s</b>\nPress <b>Select Image</b> to select an image." % extend_name
55
56 if not valid:
57 image_path = ''
58 crumbs_dialog = CrumbsMessageDialog(self, lbl, gtk.STOCK_DIALOG_INFO)
59 button = crumbs_dialog.add_button("Close", gtk.RESPONSE_OK)
60 HobButton.style_button(button)
61 crumbs_dialog.run()
62 crumbs_dialog.destroy()
63
64 self.deploy_dialog = DeployImageDialog(Title, image_path, self,
65 gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT
66 | gtk.DIALOG_NO_SEPARATOR, None, standalone=True)
67 close_button = self.deploy_dialog.add_button("Close", gtk.RESPONSE_NO)
68 HobAltButton.style_button(close_button)
69 close_button.connect('clicked', gtk.main_quit)
70
71 write_button = self.deploy_dialog.add_button("Write USB image", gtk.RESPONSE_YES)
72 HobAltButton.style_button(write_button)
73
74 self.deploy_dialog.connect('select_image_clicked', self.select_image_clicked_cb)
75 self.deploy_dialog.connect('destroy', gtk.main_quit)
76 response = self.deploy_dialog.show()
77
78 def select_image_clicked_cb(self, dialog):
79 cwd = os.getcwd()
80 dialog = ImageSelectionDialog(cwd, DEPLOYABLE_IMAGE_TYPES, Title, self, gtk.FILE_CHOOSER_ACTION_SAVE )
81 button = dialog.add_button("Cancel", gtk.RESPONSE_NO)
82 HobAltButton.style_button(button)
83 button = dialog.add_button("Open", gtk.RESPONSE_YES)
84 HobAltButton.style_button(button)
85 response = dialog.run()
86
87 if response == gtk.RESPONSE_YES:
88 if not dialog.image_names:
89 lbl = "<b>No selections made</b>\nClicked the radio button to select a image."
90 crumbs_dialog = CrumbsMessageDialog(self, lbl, gtk.STOCK_DIALOG_INFO)
91 button = crumbs_dialog.add_button("Close", gtk.RESPONSE_OK)
92 HobButton.style_button(button)
93 crumbs_dialog.run()
94 crumbs_dialog.destroy()
95 dialog.destroy()
96 return
97
98 # get the full path of image
99 image_path = os.path.join(dialog.image_folder, dialog.image_names[0])
100 self.deploy_dialog.set_image_text_buffer(image_path)
101 self.deploy_dialog.set_image_path(image_path)
102
103 dialog.destroy()
104
105def main():
106 parser = optparse.OptionParser(
107 usage = """%prog [-h] [image_file]
108
109%prog writes bootable images to USB devices. You can
110provide the image file on the command line or select it using the GUI.""")
111
112 options, args = parser.parse_args(sys.argv)
113 image_file = args[1] if len(args) > 1 else ''
114 dw = DeployWindow(image_file)
115
116if __name__ == '__main__':
117 try:
118 main()
119 gtk.main()
120 except Exception:
121 import traceback
122 traceback.print_exc(3)