#! @PYTHON@ @PYOPTIONS@
# -*- python -*-
# -*- coding: UTF-8 -*-
#
#  disk-manager-root : Execute disk-manager as root. If you are not
#                      already root, search for an authentification program.
#  Copyright (C) 2007 Mertens Florent <flomertens@gmail.com>
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  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, write to the Free Software
#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#

import os
import sys
import gettext
from subprocess import *

sys.path.insert(0, '/usr/share/disk-manager')

from DiskManager.Fstab.FstabDialogs import dialog
from DiskManager.config import *
from DiskManager.Utility import *
from gettext import gettext as _

if __name__ == '__main__' :
    
    gettext.bindtextdomain(PACKAGE,localedir)
    gettext.textdomain(PACKAGE)
  
    if not os.getuid() == 0 :
        desktop = get_desktop()
        if desktop == "GNOME" and test_cmd("gksu") :
            auth = "gksu"
        elif desktop == "KDE" and test_cmd("kdesu") :
            auth = "kdesu"
        elif test_cmd("gksu") :
            auth = "gksu"
        elif test_cmd("kdesu") :
            auth = "kdesu"   
        else :
            dialog("error", _("No authentication program founds"), \
                _("Disk Manager need to be run as root, but I can't find\n"
                "a graphical authentication program.\n" 
                "You should install <i>gksu</i> or <i>kdesu</i>.\n" 
                "Alternatively, you can run disk-manager from "
                "the terminal with <i>su</i> or <i>sudo</i>."))
            sys.exit()
        print "INFO : Launching %s with %s..." % (PACKAGE, auth)
        os.putenv("%s_user-XAUTHORITY" % PACKAGE, os.environ["XAUTHORITY"])
        argv = [auth, "--", PACKAGE]
        argv.extend(sys.argv[1:])
        os.execvp(auth, argv)
    else :
        argv = [PACKAGE]
        argv.extend(sys.argv[1:])
        os.execvp(PACKAGE, argv)
        
        
