| 1 |
|
| 2 |
''' |
| 3 |
A CLI interface to a remote salt-api instance |
| 4 |
''' |
| 5 |
from __future__ import print_function |
| 6 |
|
| 7 |
import sys |
| 8 |
import logging |
| 9 |
|
| 10 |
from pepper.cli import PepperCli |
| 11 |
from pepper import PepperException |
| 12 |
|
| 13 |
try: |
| 14 |
from logging import NullHandler |
| 15 |
except ImportError: |
| 16 |
class NullHandler(logging.Handler): |
| 17 |
def emit(self, record): pass |
| 18 |
|
| 19 |
logging.basicConfig(format='%(levelname)s %(asctime)s %(module)s: %(message)s') |
| 20 |
logger = logging.getLogger('pepper') |
| 21 |
logger.addHandler(NullHandler()) |
| 22 |
|
| 23 |
if __name__ == '__main__': |
| 24 |
try: |
| 25 |
cli = PepperCli() |
| 26 |
for exit_code, result in cli.run(): |
| 27 |
print(result) |
| 28 |
if exit_code is not None: |
| 29 |
raise SystemExit(exit_code) |
| 30 |
except PepperException as exc: |
| 31 |
print('Pepper error: {0}'.format(exc), file=sys.stderr) |
| 32 |
raise SystemExit(1) |
| 33 |
except KeyboardInterrupt: |
| 34 |
|
| 35 |
raise SystemExit(0) |
| 36 |
except Exception as e: |
| 37 |
print(e) |
| 38 |
print('Uncaught Pepper error (increase verbosity for the full traceback).', |
| 39 |
file=sys.stderr) |
| 40 |
logger.debug('Uncaught traceback:', exc_info=True) |
| 41 |
raise SystemExit(1) |