/tools/validation/fix_errors_code.py

https://bitbucket.org/h_morita_dbcls/galaxy-central · Python · 49 lines · 44 code · 3 blank · 2 comment · 1 complexity · 34f8daf9fa6f36712e3e3453a490dcef MD5 · raw file

  1. # runs after the job (and after the default post-filter)
  2. import pkg_resources
  3. pkg_resources.require( "bx-python" )
  4. from galaxy import datatypes, jobs, util
  5. # needed to reference ParseError types, is this bad?
  6. from bx.tabular.io import *
  7. from bx.intervals.io import *
  8. import sys, tempfile, os
  9. def validate(incoming):
  10. """Validator"""
  11. #raise Exception, 'not quite right'
  12. pass
  13. def exec_before_job( app, inp_data, out_data, param_dict, tool=None):
  14. """Build a temp file with errors in it"""
  15. errors = []
  16. for name, data in inp_data.items():
  17. validation_errors = data.validation_errors
  18. for error in validation_errors:
  19. # build dummy class
  20. try:
  21. temp = eval(error.err_type)()
  22. except:
  23. temp = object()
  24. # stuff attributes
  25. temp.__dict__ = util.string_to_object( error.attributes )
  26. errors.append(temp)
  27. # There *should* only be 1 input, so we assume there is and continue
  28. # base64 pickel
  29. errors_str = util.object_to_string( errors )
  30. # write
  31. database_tmp = "./database/tmp" # globaly visible path
  32. error_file = tempfile.NamedTemporaryFile(mode="w", dir=database_tmp, suffix=".b64")
  33. error_file_name = error_file.name
  34. error_file.close()
  35. error_file = open(error_file_name, "w")
  36. error_file.write(errors_str)
  37. error_file.close()
  38. param_dict["errorsfile"] = error_file_name
  39. def exec_after_process( app, inp_data, out_data, param_dict, tool=None, stdout=None, stderr=None):
  40. # in a perfect world, changes to param_dict would persist
  41. # for now, unlink from tool
  42. # os.unlink(param_dict["errorsfile"])
  43. pass