#!/usr/bin/python

# Copyright 2011-2013 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/encuentro

"""Script to run Encuentro."""

import logging
import sys
import os

# 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
    sys._INSTALLED_BASE_DIR = INSTALLED_BASE_DIR
else:
    project_basedir = os.path.abspath(os.path.dirname(os.path.dirname(
                                            os.path.realpath(sys.argv[0]))))

if project_basedir not in sys.path:
    sys.path.insert(0, project_basedir)
    sys.path.insert(1, os.path.join(project_basedir, 'qtreactor'))

from encuentro import main, platform, logger

# set up logging
verbose = len(sys.argv) > 1 and sys.argv[1] == '-v'
logger.set_up(verbose)
log = logging.getLogger('encuentro.init')

# first of all, show the versions
print "Running Python %s on %r" % (sys.version_info, sys.platform)
log.info("Running Python %s on %r", sys.version_info, sys.platform)
version_file = platform.get_path('version.txt')
if os.path.exists(version_file):
    version = open(version_file).read().strip()
    print "Encuentro: v. %s" % (version,)
else:
    version = None
    print "Encuentro: sin revno info"
log.info("Encuentro version: %r", version)

main.start(version)
