#!/usr/bin/python

# Copyright (C) 2008 Canonical Ltd.

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3,
# as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import sys
import optparse
import os
from usbcreator.gtk_frontend import GtkFrontend

usage = '%prog [options]'
parser = optparse.OptionParser(usage=usage, version='0.1.8')
parser.set_defaults(
    safe=False)
parser.add_option('-s', '--safe', dest='safe', action='store_true',
                  help='choose safer options when constructing the USB '
                  'disk (may slow down the boot process).')
(options, args) = parser.parse_args()
if options.safe:
    os.environ['USBCREATOR_SAFE'] = '1'

if os.getuid() != 0:
    args = ['gksu', 'gksu', '--desktop',
    '/usr/share/applications/usb-creator.desktop', '--']
    args.extend(sys.argv)
    os.execvp(args[0], args)

# TODO: trap sigterm, hook into copy shutdown routine.
f = GtkFrontend()
