#!/usr/bin/env python3
#
# Copyright 2012-2016 Tails developers <tails@boum.org>
# Copyright 2011 Max <govnototalitarizm@gmail.com>
# Copyright (C) 2009 Martin Owens
#
# 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, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#

import glob
import os
import os.path
import subprocess

import DistUtilsExtra.command.build_extra
import DistUtilsExtra.command.build_i18n

from distutils.core import setup

__appname__ = 'tails-greeter'
__version__ = '1.0.8'


class build_i18n(DistUtilsExtra.command.build_i18n.build_i18n):
    def run(self):
        # generate the headers required to use gettext with gtkbuilder"
        subprocess.call(["intltool-extract",
                         "--type=gettext/glade",
                         "data/greeter.ui"])
        super().run()


# remove MANIFEST. distutils doesn't properly update it
# when the contents of directories change.
if os.path.exists('MANIFEST'):
    os.remove('MANIFEST')

# Generate a standard share dir
SDIR = 'share/%s/' % __appname__

setup(
        name            =__appname__,                       # NOQA: E221, E251
        version         =__version__,                       # NOQA: E221, E251
        description     ='GDM greeter for Tails',           # NOQA: E221, E251
        long_description="Tails Greeter allows users to choose their "
            "preferred region, language, and configuration settings before "
            "entering Tails session.",                      # NOQA: E221, E251
        author          ='Tails developers',                # NOQA: E221, E251
        author_email    ='tails@boum.org',                  # NOQA: E221, E251
        url             ='https://tails.boum.org/',         # NOQA: E221, E251
        platforms       ='linux',                           # NOQA: E221, E251
        license         ='GPLv3',                           # NOQA: E221, E251
        packages        =['tailsgreeter'],                  # NOQA: E221, E251
        scripts         =['bin/tails-greeter'],             # NOQA: E221, E251
        data_files      =[                                  # NOQA: E221, E251
            (SDIR, ['data/greeter.ui', 'data/greeter.css',
                    'data/tails-logging.conf', 'data/no-password-lecture.txt',
                    'data/default_langcodes', 'lib/set-cursor.py',
                    'lib/tails-greeter.py']),
            ('lib/systemd/user/',
             ['config/tails-greeter-session-helper.service']),
            ('share/applications/', ['data/tails-greeter.desktop']),
            ('share/gnome-session/sessions/', ['config/gdm-tails.session']),
            ('share/gnome-shell/modes/', ['config/gdm-tails.json']),
            ('share/gdm/greeter/applications',
             ['config/gdm-shell-tails.desktop']),
            ('share/icons/hicolor/scalable/actions',
             glob.glob('icons/hicolor/scalable/actions/*.svg')),
        ],
        cmdclass        ={                                  # NOQA: E221, E551
                   'build': DistUtilsExtra.command.build_extra.build_extra,
                   'build_i18n': build_i18n,
                 },
    )
