clsmain 1.1 KB

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