File: pepper

package info (click to toggle)
salt-pepper 0.5.5-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, forky, sid, trixie
  • size: 124 kB
  • sloc: python: 963; makefile: 13
file content (41 lines) | stat: -rwxr-xr-x 1,214 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env python
'''
A CLI interface to a remote salt-api instance
'''
from __future__ import print_function

import sys
import logging

from pepper.cli import PepperCli
from pepper import PepperException

try:
    from logging import NullHandler
except ImportError: # Python < 2.7
    class NullHandler(logging.Handler):
        def emit(self, record): pass

logging.basicConfig(format='%(levelname)s %(asctime)s %(module)s: %(message)s')
logger = logging.getLogger('pepper')
logger.addHandler(NullHandler())

if __name__ == '__main__':
    try:
        cli = PepperCli()
        for exit_code, result in cli.run():
            print(result)
            if exit_code is not None:
                raise SystemExit(exit_code)
    except PepperException as exc:
        print('Pepper error: {0}'.format(exc), file=sys.stderr)
        raise SystemExit(1)
    except KeyboardInterrupt:
        # TODO: mimic CLI and output JID on ctrl-c
        raise SystemExit(0)
    except Exception as e:
        print(e)
        print('Uncaught Pepper error (increase verbosity for the full traceback).',
                file=sys.stderr)
        logger.debug('Uncaught traceback:', exc_info=True)
        raise SystemExit(1)