#!/usr/bin/env python3
#
# n23 - data acquisition and processing framework
#
# Copyright (C) 2013-2024 by Artur Wroblewski <wrobell@riseup.net>
#
# 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, see <http://www.gnu.org/licenses/>.
#

"""
Run N23 application.
"""

import argparse
import logging

import n23
from n23.app import run_app, read_app_config
from n23.util import read_file

logger = logging.getLogger(__name__)

parser = argparse.ArgumentParser()
parser.add_argument(
    '-v', '--verbose', action='count', default=False,
    help='Explain what is being done',
)
parser.add_argument(
    '-c', '--config', nargs='?', help='N23 application configuration file'
)
parser.add_argument('path', help='Resource path to N23 application file')

args = parser.parse_args()

if args.verbose == 0:
    level = logging.WARN
elif args.verbose == 1:
    level = logging.INFO
elif args.verbose >= 2:
    level = logging.DEBUG

logging.basicConfig(level=level)

config = None if args.config is None else read_app_config(args.config)
with read_file(args.path, 'hy') as data:
    n23.run(run_app(data, config=config))

# vim: sw=4:et:ai
