#!/usr/bin/env python3

"""
Copyright (c) 2020 Ian Santopietro
Copyright (c) 2020 System76, Inc.
All rights reserved.

This file is part of Pop-Transition.

    Pop-Transition 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.

    Pop-Transition 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 Pop-Transition.  If not, see <https://www.gnu.org/licenses/>.

pop-transition is a simple app that notifies users if they have debian versions
of packages which were transitioned to Flatpak in Pop_OS 20.04. 
"""

help = """pop-transition - Migrate deprecated Debian packages to Flatpak.

Usage:
    pop-transition [daemon | check | help ]

    If run without options, pop-transition will open the transition helper 
    window.

Options:
    help, -h
            Display this help message and exit.

    check, -c
            Check for deprecated debian packages and print any that are 
            currently installed. 

    daemon, -d
            Run as a daemon without displaying a window. If there are apps to 
            transition, a notification will be displayed. The daemon will then 
            exit after 10 seconds.
"""
import logging
import sys

formatter = logging.Formatter('%(asctime)s %(name)-12s %(levelname)-8s %(message)s')
log = logging.getLogger('pop-transition')
handler = logging.StreamHandler()
handler.setFormatter(formatter)
if 'debug' in sys.argv:
    handler.setLevel(logging.DEBUG)
else:
    handler.setLevel(logging.WARNING)
log.addHandler(handler)
log.setLevel(logging.DEBUG)
log.debug('Set up logging')

import pop_transition

if len(sys.argv) < 1:
    pop_transition.run_window()

elif 'daemon' in sys.argv[-1] or sys.argv[-1] == '-d':
    pop_transition.run()

elif 'check' in sys.argv[-1] or sys.argv[-1] == '-c':
    output, output_text = pop_transition.run_check()
    print(output_text)

elif 'help' in sys.argv[-1] or sys.argv[-1] == '-h':
    print(help)

else:
    pop_transition.run_window()
