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

# sun_daemon is a part of sun.

# Copyright 2015-2022 Dimitris Zlatanidis <d.zlatanidis@gmail.com>
# All rights reserved.

# sun is a tray notification applet for informing about
# package updates in Slackware.

# https://gitlab.com/dslackw/sun

# sun 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, see <http://www.gnu.org/licenses/>.


"""
 ____  _   _ _   _
/ ___|| | | | \ | |
\___ \| | | |  \| |
 ___) | |_| | |\  |
|____/ \___/|_| \_|
"""


import os
import sys
import shutil


def autostart():
    args = sys.argv
    args.pop(0)

    xdg_autostart_path = '/etc/xdg/autostart/'
    enable_file = f'{xdg_autostart_path}sun_daemon.desktop'
    disable_file = f'{enable_file}.sample'

    if len(args) == 1 and args[0] == 'enable':
        if os.path.isfile(disable_file):
            shutil.move(disable_file, enable_file)
            print('The daemon autostart is enabled.')
        else:
            print('The daemon autostart is already enabled.')
    elif len(args) == 1 and args[0] == 'disable':
        if os.path.isfile(enable_file):
            shutil.move(enable_file, disable_file)
            print('The daemon autostart is disabled.')
        else:
            print('The daemon autostart is already disabled.')
    elif len(args) == 1 and args[0] == 'status':
        if os.path.isfile(enable_file):
            print('The SUN daemon autostart is enabled.')
        else:
            print('The SUN daemon autostart is disabled.')
    else:
        print("SUN (Slackware Update Notifier) daemon autostart.\n"
              "\nUsage: sun_daemon [OPTIONS]\n"
              "\nOptional arguments:\n"
              "  enable    Enable autostart daemon.\n"
              "  disable   Disable autostart daemon.\n"
              "  status    Daemon autostart status.\n")


if __name__ == '__main__':
    autostart()
