scripts.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. """TODO Docstring, used in the command line help text."""
  2. import argparse
  3. import logging
  4. logger = logging.getLogger(__name__)
  5. def get_parser():
  6. """Return argument parser."""
  7. parser = argparse.ArgumentParser(description=__doc__)
  8. parser.add_argument(
  9. "-v",
  10. "--verbose",
  11. action="store_true",
  12. dest="verbose",
  13. default=False,
  14. help="Verbose output",
  15. )
  16. # add arguments here
  17. # parser.add_argument(
  18. # 'path',
  19. # metavar='FILE',
  20. # )
  21. return parser
  22. def main(): # pragma: no cover
  23. """Call main command with args from parser.
  24. This method is called when you run 'bin/run-clean-python',
  25. this is configured in 'setup.py'. Adjust when needed. You can have multiple
  26. main scripts.
  27. """
  28. options = get_parser().parse_args()
  29. if options.verbose:
  30. log_level = logging.DEBUG
  31. else:
  32. log_level = logging.INFO
  33. logging.basicConfig(level=log_level, format="%(levelname)s: %(message)s")
  34. try:
  35. print("Call some function from another file here")
  36. # ^^^ TODO: pass in options.xyz where needed.
  37. except: # noqa: E722
  38. logger.exception("An exception has occurred.")
  39. return 1