#!/usr/bin/python

# Copyright (C) 2005-2013, 2016, 2017 Canonical Ltd
#
# 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 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 program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

"""Breezy -- a free distributed version-control tool"""

import os
import sys
import warnings

# update this on each release
_script_version = (3, 2, 1)

profiling = False
if '--profile-imports' in sys.argv:
    import profile_imports
    profile_imports.install()
    profiling = True


if os.name == "posix":
    import locale
    try:
        locale.setlocale(locale.LC_ALL, '')
    except locale.Error as e:
        sys.stderr.write(
            'brz: warning: %s\n'
            '  bzr could not set the application locale.\n'
            '  Although this should be no problem for bzr itself, it might\n'
            '  cause problems with some plugins. To investigate the issue,\n'
            '  look at the output of the locale(1p) tool.\n' % e)
    # Use better default than ascii with posix filesystems that deal in bytes
    # natively even when the C locale or no locale at all is given. Note that
    # we need an immortal string for the hack, hence the lack of a hyphen.
    sys._brz_default_fs_enc = "utf8"


try:
    import breezy
except ImportError as e:
    sys.stderr.write(
        "brz: ERROR: "
        "Couldn't import breezy and dependencies.\n"
        "Please check the directory containing breezy is on your PYTHONPATH.\n"
        "\n")
    raise

if breezy.version_info[:3] != _script_version:
    sys.stderr.write(
        "brz: WARNING: breezy version doesn't match the brz program.\n"
        "This may indicate an installation problem.\n"
        "breezy is version %s from %s\n"
        "brz is version %s from %s\n" % (
            breezy._format_version_tuple(breezy.version_info),
            breezy.__path__[0],
            breezy._format_version_tuple(_script_version),
            __file__))

if __name__ == '__main__':
    from breezy.__main__ import main
    main()
else:
    raise ImportError("The brz script cannot be imported.")
