#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Mythbuntu Control Centre Launcher Script
#
# Copyright (C) 2007, Mario Limonciello, for Mythbuntu
#
#
# Mythbuntu 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 application; if not, write to the Free Software Foundation, Inc., 51
# Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
##################################################################################

__copyright__ = "Copyright © 2007 Mario Limonciello"
__author__    = "Mario Limonciello <superm1@ubuntu.com>"

import sys
import os
import subprocess

def main():
    toexec = []
    if os.getuid() == 0:
        # no privilege escalation required
        pass
    elif os.path.exists('/usr/bin/gksudo'):
        toexec = ['gksudo', '-k', '-D', '/usr/share/applications/mythbuntu-control-centre.desktop']
    elif os.path.exists('/usr/bin/kdesu'):
        toexec = ['kdesu', '--nonewdcop', '--']
    else:
        toexec = ['sudo']
    toexec.append('/usr/share/mythbuntu-control-centre/bin/mythbuntu-control-centre')
    os.execvp(toexec[0], toexec)
    sys.exit(127)

if __name__ == '__main__':
    main()
