Advertisement
Guest User

Untitled

a guest
Sep 17th, 2014
366
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. from bigdata import generictask
  2. from bigdata.utility import pretty_print
  3. import comm.emailout
  4. import datetime
  5. import os
  6.  
  7.  
  8. class UserTask (generictask.GenericTask):
  9.  
  10. def action(self, srId, result, taskName, attach=False):
  11. """
  12. This task can parse and send the result output of an other task to email-in@cisco.com
  13.  
  14. Parameters:
  15. - `<srId>` (STR) SR ID
  16. - `<result>` (DICT) The dict representation of a task output
  17. - `<taskName>` (STR) The task name
  18. - `<attach>` (BOOL) Send as an attached file
  19.  
  20. Returns:
  21. -
  22. """
  23.  
  24. # temp patch
  25. tmp = result.copy()
  26. result['data'] = tmp
  27. # /temp patch
  28.  
  29. #output_string = pretty_print({'data': result}, nocolor=True, printlog=False, noprint=True)
  30. output_string = pretty_print(result, nocolor=True, printlog=False, noprint=True)
  31.  
  32. mail = comm.emailout.EmailOut("bdb_no_reply@cisco.com", "email-in@cisco.com", "BDB - "+srId+" - Task "+taskName+" output")
  33.  
  34. if not attach:
  35. mail.set_body(pretty_print(result))
  36. else:
  37. filename = str(datetime.datetime.now().strftime("%Y%m%d-%H%M%S"))
  38. filename += "-BDB-"
  39. filename += taskName
  40. with open(filename, 'w+') as f:
  41. f.write(output_string)
  42. mail.attach(filename)
  43. mail.set_body('New file attached '+filename)
  44. os.remove(filename)
  45. mail.send()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement