3
# Copyright (C) 2009 Canonical Ltd.
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 3,
7
# as published by the Free Software Foundation.
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.
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/>.
22
from dbus import DBusException
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'
28
from usbcreator.frontends.gtk import GtkFrontend
29
from usbcreator.backends.udisks import UDisksBackend
30
from usbcreator.misc import sane_path, setup_gettext, setup_logging, text_type
36
# TODO evand 2009-07-09: Rename to bin/usb-creator-gtk.in and substitue the
37
# version in at build time.
38
parser = optparse.OptionParser(usage=_('%prog [options]'), version='0.3.3')
39
parser.set_defaults(iso=None,
40
allow_system_internal=False,
42
# FIXME evand 2009-07-28: Reconnect this option to the install routine.
43
parser.add_option('-i', '--iso', dest='img',
44
help=_('provide a source image to pre-populate the UI.'))
45
parser.add_option('--allow-system-internal', dest='allow_system_internal',
47
help=_('allow writing to system-internal devices'))
48
(options, args) = parser.parse_args()
51
backend = UDisksBackend(
52
allow_system_internal=options.allow_system_internal)
53
frontend = GtkFrontend(
55
allow_system_internal=options.allow_system_internal)
56
except DBusException as e:
57
# FIXME evand 2009-07-09: Wouldn't service activation pick this up
59
# FIXME evand 2009-07-28: Does this really belong this far out?
60
logging.exception('DBus exception:')
61
if e._dbus_error_name == 'org.freedesktop.DBus.Error.ServiceUnknown':
62
message = _('This program needs udisks running in order to'
65
message = _('An error occurred while talking to the udisks '
67
GtkFrontend.startup_failure(message)
69
except (KeyboardInterrupt, Exception) as e:
70
# TODO evand 2009-05-03: What should we do here to make sure devices are
72
logging.exception('Unhandled exception:')
73
message = _('An unhandled exception occurred:\n%s' % text_type(e))
74
GtkFrontend.startup_failure(message)