#!/usr/bin/env python

# Copyright (C) 2005 Osmo Salomaa
#
# This file is part of Gaupol.
#
# Gaupol 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.
#
# Gaupol 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 Gaupol; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA


"""Script to test PyEnchant installation."""


import os
import sys

test_path = os.path.dirname(os.path.abspath(__file__))
lib_path = os.path.join(test_path, '..', 'lib')
sys.path.insert(0, lib_path)
from gaupol.base.util import langlib


print 'Importing enchant module:',
try:
    import enchant
    print 'success'
except ImportError:
    try:
        import pkg_resources
        try:
            pkg_resources.require('pyenchant')
        except pkg_resources.DistributionNotFound:
            print 'Not found'
            raise SystemExit(1)
        import enchant
        print 'success'
    except ImportError:
        print 'Not found.'
        raise SystemExit(1)
except enchant.Error, message:
    print message
    raise SystemExit(1)

print 'PyEnchant version:',
try:
    print enchant.__version__
except enchant.Error, message:
    print message

print 'Found dictionaries:'
for lang in langlib.locales:
    try:
        dictionary = enchant.Dict(lang)
        print '  %s (%s)' % (lang, dictionary.provider.name)
    except enchant.Error:
        pass
