#!/usr/bin/python

#
# Copyright 2012 Facundo Batista
#
# 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 warranties of
# MERCHANTABILITY, SATISFACTORY QUALITY, 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/>.
#
# For further info, check  https://launchpad.net/launcherposta

"""Script to run Launcher Posta."""

import os
import sys

# this will be replaced at install time
INSTALLED_BASE_DIR = "@ INSTALLED_BASE_DIR @"

# get the replaced-at-install-time name if exists, or the project one
if os.path.exists(INSTALLED_BASE_DIR):
    project_basedir = INSTALLED_BASE_DIR
else:
    project_basedir = os.path.abspath(os.path.dirname(os.path.dirname(
                                            os.path.realpath(sys.argv[0]))))

# first of all, show the versions to stdout (just in case logging 
# not even works, to have *something*)
print "Running Python %s on %r" % (sys.version_info, sys.platform)
version_file = os.path.join(project_basedir, 'version.txt')
if os.path.exists(version_file):
    version = open(version_file).read().strip()
else:
    version = '?'
print "LauncherPosta: v. %s" % (version,)

if project_basedir not in sys.path:
    sys.path.insert(0, project_basedir)

# set up logger and dump again basic version info
from launcherposta import logger
l = logger.set_up()
l.info("Running Python %s on %r", sys.version_info, sys.platform)
l.info("LauncherPosta: v. %s", version)

# check all the imports
from launcherposta import importer
importer.check('gi.repository.Gtk', 'python-gi', '3.2.2')
importer.check('gi.repository.Gio', 'python-gi', '3.2.2')
importer.check('gi.repository.AppIndicator3', 'python-gi', '3.2.2')
importer.check('xdg', 'python-xdg', '0.15')

from launcherposta import main
main.go(version)
