]> kaliko git repositories - mpd-sima.git/blob - launch
Add conf management and cli parsing
[mpd-sima.git] / launch
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3
4 import logging
5 ##
6
7 from sima import core
8 from sima.plugins.crop import Crop
9 from sima.lib.logger import set_logger
10 from sima.utils.config import ConfMan
11 from sima.utils.startopt import StartOpt
12 from sima.utils.utils import exception_log
13 ##
14
15
16 def main():
17     """Entry point, deal w/ CLI and starts application
18     """
19     info = dict({'version': core.__version__,})
20     # StartOpt gathers options from command line call (in StartOpt().options)
21     sopt = StartOpt(info)
22     # set logger
23     set_logger(level='debug')
24     logger = logging.getLogger('sima')
25     cli_loglevel = getattr(logging,
26                            sopt.options.get('verbosity', 'warning').upper())
27     logger.setLevel(cli_loglevel)
28     # loads configuration
29     conf_manager = ConfMan(logger, sopt.options)
30     config = conf_manager.config
31     logger.setLevel(getattr(logging,
32                     config.get('log', 'verbosity').upper()))  # pylint: disable=E1103
33
34     logger.debug('Command line say: {0}'.format(sopt.options))
35     logger.info('Starting...')
36     sima = core.Sima()
37     sima.register_plugin(Crop)
38     try:
39         sima.run()
40     except KeyboardInterrupt:
41         logger.info('Caught KeyboardInterrupt, stopping')
42         sima.shutdown()
43
44
45 # Script starts here
46 if __name__ == '__main__':
47     # pylint: disable=broad-except
48     try:
49         main()
50     except Exception:
51         exception_log()
52
53
54 # VIM MODLINE
55 # vim: ai ts=4 sw=4 sts=4 expandtab