main 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # -*- coding: utf-8 -*-
  2. # name: main
  3. # key: main
  4. # --
  5. #!/usr/bin/env python
  6. import argparse
  7. import logging
  8. import sys
  9. parser = argparse.ArgumentParser(usage="%(prog)s [options] args...")
  10. parser.add_argument("-v", action="append_const", const=1, dest="verbosity", default=[],
  11. help="Be more verbose. Can be specified multiple times to increase verbosity further")
  12. def main(args):
  13. $0
  14. return 0
  15. ################################## Boilerplate ################################
  16. def _configure_logging(args):
  17. verbosity_level = len(args.verbosity)
  18. if verbosity_level == 0:
  19. level = "WARNING"
  20. elif verbosity_level == 1:
  21. level = "INFO"
  22. else:
  23. level = "DEBUG"
  24. logging.basicConfig(
  25. stream=sys.stderr,
  26. level=level,
  27. format="%(asctime)s -- %(message)s"
  28. )
  29. #### For use with entry_points/console_scripts
  30. def main_entry_point():
  31. args = parser.parse_args()
  32. _configure_logging(args)
  33. sys.exit(main(args))
  34. if __name__ == "__main__":
  35. main_entry_point()