#!/usr/local/bin/python2.6
# -*- coding:utf-8 -*-

# -----------------------------------------------------------------------------
# Getting Things Gnome! - A personal organizer for the GNOME desktop
# Copyright (c) 2008,2009 Lionel Dricot & Bertrand Rousseau
#
# 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 3 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, see <http://www.gnu.org/licenses/>.
# -----------------------------------------------------------------------------

"""
Getting Things Gnome! - A personal organizer for the GNOME desktop
==================================================================

:copyright: 2008,2009 Lionel Dricot & Bertrand Rousseau
:license: GNU General Public License, version 3 or later
"""

import sys

from optparse import OptionParser

def X_is_running():
    from subprocess import Popen, PIPE
    p = Popen(["xset", "-q"], stdout=PIPE, stderr=PIPE)
    p.communicate()
    return p.returncode == 0

try:
    parser = OptionParser()
    parser.add_option("-d", "--debug",
                  action="store_true", dest="debug", help="enable debug output")
    (options, args) = parser.parse_args()

    if not X_is_running():
        print "Could not open X display"
        sys.exit(1)

    else:
        import GTG.gtg
        sys.exit(GTG.gtg.main(options, args))

except KeyboardInterrupt:
    sys.exit(1)
