~usb-creator-hackers/usb-creator/trunk

« back to all changes in this revision

Viewing changes to bin/usb-creator-gtk

  • Committer: Benjamin Drung
  • Date: 2022-11-02 13:01:26 UTC
  • Revision ID: benjamin.drung@canonical.com-20221102130126-4z0xyivy5f37dp13
Move to https://code.launchpad.net/~usb-creator-hackers/usb-creator/+git/main

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/python3
2
 
 
3
 
# Copyright (C) 2009 Canonical Ltd.
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 3,
7
 
# as 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.  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
 
 
17
 
import os
18
 
import sys
19
 
import optparse
20
 
import logging
21
 
 
22
 
from dbus import DBusException
23
 
 
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'
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
31
 
 
32
 
sane_path()
33
 
setup_logging()
34
 
setup_gettext()
35
 
 
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,
41
 
                    trace=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',
46
 
                  action='store_true',
47
 
                  help=_('allow writing to system-internal devices'))
48
 
(options, args) = parser.parse_args()
49
 
 
50
 
try:
51
 
    backend = UDisksBackend(
52
 
        allow_system_internal=options.allow_system_internal)
53
 
    frontend = GtkFrontend(
54
 
        backend, options.img,
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
58
 
    # automatically?
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'
63
 
                    'properly function.')
64
 
    else:
65
 
        message = _('An error occurred while talking to the udisks '
66
 
                    'service.')
67
 
    GtkFrontend.startup_failure(message)
68
 
    sys.exit(1)
69
 
except (KeyboardInterrupt, Exception) as e:
70
 
    # TODO evand 2009-05-03: What should we do here to make sure devices are
71
 
    # unmounted, etc?
72
 
    logging.exception('Unhandled exception:')
73
 
    message = _('An unhandled exception occurred:\n%s' % text_type(e))
74
 
    GtkFrontend.startup_failure(message)