#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# Copyright (C) 2015 Martin Wimpress <code@ubuntu-mate.org>
#
# 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 St, Fifth Floor, Boston, MA 02110-1301, USA.

import os
import shutil
import sys

def install_layout(filename, filename_suffix):
    if os.path.exists(os.path.join('/','tmp',filename + filename_suffix)):
        shutil.copy2(os.path.join('/','tmp',filename + filename_suffix),
                     os.path.join('/','usr','share','mate-panel','layouts',filename + filename_suffix))
        os.remove(os.path.join('/','tmp',filename + filename_suffix))
    else:
        print('ERROR! Unable to find ' + os.path.join('/','tmp',filename + filename_suffix))
        sys.exit(1)

if __name__ == '__main__':
    if len(sys.argv) == 2:
        filename = sys.argv[1]
        install_layout(filename,'-tweak.layout')
        install_layout(filename,'-tweak.panel')
    else:
        print("ERORR! No name supplied.")
        sys.exit(1)
