406.1.1
by Dmitrijs Ledkovs
Support flashing devices using fastboot (e.g. Nexus7). |
1 |
#!/usr/bin/python3
|
3
by Evan Dandrea
* Fix FTBFS. Thanks David Futcher (LP: #267103). |
2 |
|
97.2.12
by Evan Dandrea
Added a test harness for the Windows backend. |
3 |
# Copyright (C) 2009 Canonical Ltd.
|
3
by Evan Dandrea
* Fix FTBFS. Thanks David Futcher (LP: #267103). |
4 |
|
1
by Evan Dandrea
Imported project. |
5 |
# This program is free software: you can redistribute it and/or modify
|
3
by Evan Dandrea
* Fix FTBFS. Thanks David Futcher (LP: #267103). |
6 |
# it under the terms of the GNU General Public License version 3,
|
7 |
# as published by the Free Software Foundation.
|
|
1
by Evan Dandrea
Imported project. |
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. See the
|
|
12 |
# 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, see <http://www.gnu.org/licenses/>.
|
|
16 |
||
377
by Colin Watson
More pyflakes cleanup. |
17 |
import os |
18 |
import sys |
|
23
by Evan Dandrea
* Add --safe option to enable syslinux's 'safe, slow, and stupid' mode |
19 |
import optparse |
377
by Colin Watson
More pyflakes cleanup. |
20 |
import logging |
21 |
||
97.2.11
by Evan Dandrea
* Split bin/usb-creator back into bin/usb-creator-gtk and bin/usb-creator-kde. |
22 |
from dbus import DBusException |
97.2.8
by Evan Dandrea
Initial commit of the following incomplete work: |
23 |
|
97.2.56
by Evan Dandrea
* Use icons and UI data from the tree if usb-creator-gtk is being run from |
24 |
program = sys.argv[0] |
25 |
if program.startswith('./') or program.startswith('bin/'): |
|
26 |
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..')) |
|
27 |
os.environ['USBCREATOR_LOCAL'] = '1' |
|
97.2.11
by Evan Dandrea
* Split bin/usb-creator back into bin/usb-creator-gtk and bin/usb-creator-kde. |
28 |
from usbcreator.frontends.gtk import GtkFrontend |
265
by Martin Pitt
* Port to udisks: Rename all DeviceKit-Disks related D-Bus interfaces, |
29 |
from usbcreator.backends.udisks import UDisksBackend |
406.1.1
by Dmitrijs Ledkovs
Support flashing devices using fastboot (e.g. Nexus7). |
30 |
from usbcreator.backends.fastboot import FastbootBackend |
381
by Colin Watson
Use str() rather than unicode() in Python 3. |
31 |
from usbcreator.misc import sane_path, setup_gettext, setup_logging, text_type |
97.2.11
by Evan Dandrea
* Split bin/usb-creator back into bin/usb-creator-gtk and bin/usb-creator-kde. |
32 |
|
355
by Colin Watson
Ensure that at least /bin, /sbin, /usr/bin, and /usr/sbin are on PATH |
33 |
sane_path() |
97.2.11
by Evan Dandrea
* Split bin/usb-creator back into bin/usb-creator-gtk and bin/usb-creator-kde. |
34 |
setup_logging() |
379
by Colin Watson
Only pass unicode=True to gettext.install in Python 2. |
35 |
setup_gettext() |
97.2.41
by Evan Dandrea
* Clean up bin/usb-creator-gtk to match changes in main.py (Windows main |
36 |
|
37 |
# TODO evand 2009-07-09: Rename to bin/usb-creator-gtk.in and substitue the
|
|
38 |
# version in at build time.
|
|
315
by Roderick B. Greening
Bump version info to 0.2.23 |
39 |
parser = optparse.OptionParser(usage=_('%prog [options]'), version='0.2.23') |
97.2.41
by Evan Dandrea
* Clean up bin/usb-creator-gtk to match changes in main.py (Windows main |
40 |
parser.set_defaults(safe=False, |
41 |
iso=None, |
|
42 |
persistent=True, |
|
319.1.1
by Colin Watson
Add an --allow-system-internal option (Unix only) to allow installation |
43 |
allow_system_internal=False, |
97.2.41
by Evan Dandrea
* Clean up bin/usb-creator-gtk to match changes in main.py (Windows main |
44 |
trace=False) |
45 |
# FIXME evand 2009-07-28: Reconnect this option to the install routine.
|
|
97.2.11
by Evan Dandrea
* Split bin/usb-creator back into bin/usb-creator-gtk and bin/usb-creator-kde. |
46 |
parser.add_option('-s', '--safe', dest='safe', action='store_true', |
241
by Evan Dandrea
* Change the program title (not the program name) to "Startup Disk |
47 |
help=_('choose safer options when constructing the startup ' |
97.2.41
by Evan Dandrea
* Clean up bin/usb-creator-gtk to match changes in main.py (Windows main |
48 |
'disk (may slow down the boot process).')) |
97.2.11
by Evan Dandrea
* Split bin/usb-creator back into bin/usb-creator-gtk and bin/usb-creator-kde. |
49 |
parser.add_option('-i', '--iso', dest='img', |
97.2.41
by Evan Dandrea
* Clean up bin/usb-creator-gtk to match changes in main.py (Windows main |
50 |
help=_('provide a source image (CD or disk) to ' |
51 |
'pre-populate the UI.')) |
|
52 |
parser.add_option('-n', '--not_persistent', dest='persistent', |
|
53 |
action='store_false', |
|
251
by Mario Limonciello
When setting the no persistence flag (-n), don't offer changing |
54 |
help=_('disable persistent setting in the UI')) |
319.1.1
by Colin Watson
Add an --allow-system-internal option (Unix only) to allow installation |
55 |
parser.add_option('--allow-system-internal', dest='allow_system_internal', |
56 |
action='store_true', |
|
57 |
help=_('allow writing to system-internal devices')) |
|
330
by Evan Dandrea
Hide partition table block devices by default. To revert to the |
58 |
parser.add_option('--show-all', dest='show_all', action='store_true', |
59 |
help=_('Show all devices')) |
|
406.1.1
by Dmitrijs Ledkovs
Support flashing devices using fastboot (e.g. Nexus7). |
60 |
parser.add_option('--fastboot', dest='fastboot', action='store_true', |
61 |
help=_('Use fastboot backend to flash Android devices.')) |
|
97.2.11
by Evan Dandrea
* Split bin/usb-creator back into bin/usb-creator-gtk and bin/usb-creator-kde. |
62 |
(options, args) = parser.parse_args() |
63 |
||
64 |
try: |
|
406.1.1
by Dmitrijs Ledkovs
Support flashing devices using fastboot (e.g. Nexus7). |
65 |
if options.fastboot: |
66 |
options.persistent = False |
|
67 |
backend = FastbootBackend() |
|
68 |
else: |
|
69 |
backend = UDisksBackend( |
|
70 |
allow_system_internal=options.allow_system_internal, |
|
71 |
show_all=options.show_all) |
|
72 |
frontend = GtkFrontend( |
|
73 |
backend, options.img, options.persistent, |
|
406.1.2
by Dmitrijs Ledkovs
refactor backend check |
74 |
allow_system_internal=options.allow_system_internal) |
366
by Colin Watson
Use "except Exception as e" syntax rather than the old-style "except |
75 |
except DBusException as e: |
97.2.11
by Evan Dandrea
* Split bin/usb-creator back into bin/usb-creator-gtk and bin/usb-creator-kde. |
76 |
# FIXME evand 2009-07-09: Wouldn't service activation pick this up
|
77 |
# automatically?
|
|
97.2.41
by Evan Dandrea
* Clean up bin/usb-creator-gtk to match changes in main.py (Windows main |
78 |
# FIXME evand 2009-07-28: Does this really belong this far out?
|
79 |
logging.exception('DBus exception:') |
|
97.2.11
by Evan Dandrea
* Split bin/usb-creator back into bin/usb-creator-gtk and bin/usb-creator-kde. |
80 |
if e._dbus_error_name == 'org.freedesktop.DBus.Error.ServiceUnknown': |
265
by Martin Pitt
* Port to udisks: Rename all DeviceKit-Disks related D-Bus interfaces, |
81 |
message = _('This program needs udisks running in order to' |
97.2.41
by Evan Dandrea
* Clean up bin/usb-creator-gtk to match changes in main.py (Windows main |
82 |
'properly function.') |
97.2.11
by Evan Dandrea
* Split bin/usb-creator back into bin/usb-creator-gtk and bin/usb-creator-kde. |
83 |
else: |
265
by Martin Pitt
* Port to udisks: Rename all DeviceKit-Disks related D-Bus interfaces, |
84 |
message = _('An error occurred while talking to the udisks ' |
97.2.41
by Evan Dandrea
* Clean up bin/usb-creator-gtk to match changes in main.py (Windows main |
85 |
'service.') |
86 |
GtkFrontend.startup_failure(message) |
|
87 |
sys.exit(1) |
|
366
by Colin Watson
Use "except Exception as e" syntax rather than the old-style "except |
88 |
except (KeyboardInterrupt, Exception) as e: |
97.2.11
by Evan Dandrea
* Split bin/usb-creator back into bin/usb-creator-gtk and bin/usb-creator-kde. |
89 |
# TODO evand 2009-05-03: What should we do here to make sure devices are
|
90 |
# unmounted, etc?
|
|
97.2.41
by Evan Dandrea
* Clean up bin/usb-creator-gtk to match changes in main.py (Windows main |
91 |
logging.exception('Unhandled exception:') |
381
by Colin Watson
Use str() rather than unicode() in Python 3. |
92 |
message = _('An unhandled exception occurred:\n%s' % text_type(e)) |
97.2.41
by Evan Dandrea
* Clean up bin/usb-creator-gtk to match changes in main.py (Windows main |
93 |
GtkFrontend.startup_failure(message) |