You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

116 lines
3.7 KiB

4 years ago
  1. #!/home/alpcentaur/ProjektA/PrototypeWebApp/venv/bin/python3.5
  2. # Copyright (c) 2009 Chris Moyer http://coredumped.org/
  3. #
  4. # Permission is hereby granted, free of charge, to any person obtaining a
  5. # copy of this software and associated documentation files (the
  6. # "Software"), to deal in the Software without restriction, including
  7. # without limitation the rights to use, copy, modify, merge, publish, dis-
  8. # tribute, sublicense, and/or sell copies of the Software, and to permit
  9. # persons to whom the Software is furnished to do so, subject to the fol-
  10. # lowing conditions:
  11. #
  12. # The above copyright notice and this permission notice shall be included
  13. # in all copies or substantial portions of the Software.
  14. #
  15. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  16. # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
  17. # ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
  18. # SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  19. # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  21. #
  22. # Task/Job Administration utility
  23. #
  24. VERSION="0.1"
  25. __version__ = VERSION
  26. usage = """%prog [options] [command]
  27. Commands:
  28. list|ls List all Tasks in SDB
  29. delete <id> Delete Task with id <id>
  30. get <name> Get Task <name>
  31. create|mk <name> <hour> <command> Create a new Task <name> with command <command> running every <hour>
  32. """
  33. def list():
  34. """List all Tasks in SDB"""
  35. from boto.manage.task import Task
  36. print "%-8s %-40s %s" % ("Hour", "Name", "Command")
  37. print "-"*100
  38. for t in Task.all():
  39. print "%-8s %-40s %s" % (t.hour, t.name, t.command)
  40. def get(name):
  41. """Get a task
  42. :param name: The name of the task to fetch
  43. :type name: str
  44. """
  45. from boto.manage.task import Task
  46. q = Task.find()
  47. q.filter("name like", "%s%%" % name)
  48. for t in q:
  49. print "="*80
  50. print "| ", t.id
  51. print "|%s" % ("-"*79)
  52. print "| Name: ", t.name
  53. print "| Hour: ", t.hour
  54. print "| Command: ", t.command
  55. if t.last_executed:
  56. print "| Last Run: ", t.last_executed.ctime()
  57. print "| Last Status: ", t.last_status
  58. print "| Last Run Log: ", t.last_output
  59. print "="*80
  60. def delete(id):
  61. from boto.manage.task import Task
  62. t = Task.get_by_id(id)
  63. print "Deleting task: %s" % t.name
  64. if raw_input("Are you sure? ").lower() in ["y", "yes"]:
  65. t.delete()
  66. print "Deleted"
  67. else:
  68. print "Canceled"
  69. def create(name, hour, command):
  70. """Create a new task
  71. :param name: Name of the task to create
  72. :type name: str
  73. :param hour: What hour to run it at, "*" for every hour
  74. :type hour: str
  75. :param command: The command to execute
  76. :type command: str
  77. """
  78. from boto.manage.task import Task
  79. t = Task()
  80. t.name = name
  81. t.hour = hour
  82. t.command = command
  83. t.put()
  84. print "Created task: %s" % t.id
  85. if __name__ == "__main__":
  86. try:
  87. import readline
  88. except ImportError:
  89. pass
  90. import boto
  91. import sys
  92. from optparse import OptionParser
  93. from boto.mashups.iobject import IObject
  94. parser = OptionParser(version=__version__, usage=usage)
  95. (options, args) = parser.parse_args()
  96. if len(args) < 1:
  97. parser.print_help()
  98. sys.exit(1)
  99. command = args[0].lower()
  100. if command in ("ls", "list"):
  101. list()
  102. elif command == "get":
  103. get(args[1])
  104. elif command == "create":
  105. create(args[1], args[2], args[3])
  106. elif command == "delete":
  107. delete(args[1])