main.py 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import sys
  2. import argparse
  3. import shlex
  4. import logging
  5. from . import __version__
  6. import config
  7. import credentials
  8. import website
  9. logging.basicConfig(level=logging.WARNING)
  10. logger = logging.getLogger("vaporfile")
  11. def main():
  12. parser_template = argparse.ArgumentParser(add_help=False)
  13. parser_template.add_argument(
  14. "--version", action="version",
  15. version="%(prog)s {0} -- http://github.com/EnigmaCurry/vaporfile"\
  16. .format(__version__))
  17. parser_template.add_argument(
  18. "-c", "--config", metavar="PATH", dest="config",
  19. default=None, help="Use alternative config file (defaults"
  20. " to ~/.vaporfile)")
  21. parser_template.add_argument("-v", "--verbose", dest="verbose",
  22. default=False, action="store_true",
  23. help="Be verbose")
  24. parser_template.add_argument("-vv", "--veryverbose", dest="veryverbose",
  25. default=False, action="store_true",
  26. help="Be extra verbose")
  27. parser = argparse.ArgumentParser(parents=[parser_template])
  28. subparsers = parser.add_subparsers()
  29. ### Credentials
  30. p_cred = subparsers.add_parser(
  31. "credentials", help="Manage Amazon AWS credentials",
  32. parents=[parser_template])
  33. p_cred_subparsers = p_cred.add_subparsers()
  34. p_cred_store = p_cred_subparsers.add_parser(
  35. "store", help="Store credentials locally")
  36. p_cred_store.set_defaults(func=credentials.prompt_save_credentials)
  37. p_cred_remove = p_cred_subparsers.add_parser(
  38. "remove", help="Remove the credentials stored locally")
  39. p_cred_remove.set_defaults(func=credentials.remove_credentials)
  40. ### Create site
  41. p_create = subparsers.add_parser(
  42. "create", help="Create a new S3 website",
  43. parents=[parser_template])
  44. p_create.set_defaults(func=website.prompt_create_website)
  45. ### Upload
  46. p_upload = subparsers.add_parser(
  47. "upload", help="Upload a previously configured website",
  48. parents=[parser_template])
  49. p_upload.add_argument("WEBSITE", help="Name of configured website")
  50. p_upload.add_argument("--no-delete", action="store_true", help="Don't delete old files from S3")
  51. p_upload.set_defaults(func=website.upload_website)
  52. ### Remove
  53. p_remove = subparsers.add_parser(
  54. "remove", help="Remove a website configuration locally",
  55. parents=[parser_template])
  56. p_remove.add_argument("WEBSITE", help="Name of configured website")
  57. p_remove.set_defaults(func=website.remove_website)
  58. ### List
  59. p_list = subparsers.add_parser(
  60. "list", help="List all configured websites",
  61. parents=[parser_template])
  62. p_list.set_defaults(func=website.list_websites)
  63. if len(sys.argv) <= 1:
  64. parser.print_help()
  65. parser.exit(1)
  66. else:
  67. args = parser.parse_args()
  68. if args.config:
  69. config.__config_file__ = args.config
  70. if args.verbose:
  71. logger.setLevel(logging.INFO)
  72. logger.info("Setting verbose output mode")
  73. if args.veryverbose:
  74. logger.setLevel(logging.DEBUG)
  75. logger.debug("Setting very verbose output mode")
  76. args.func(args)