PageRenderTime 24ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/tool_list.py

https://bitbucket.org/cistrome/cistrome-harvard/
Python | 69 lines | 65 code | 2 blank | 2 comment | 16 complexity | 4173db9f923035cd83dad3dd11f13e9d MD5 | raw file
  1. import os,sys
  2. #--------read tool_conf.xml.sample to get all the tool xml file names-----------
  3. onoff = 1
  4. tool_list = []
  5. for line in open("tool_conf.xml.sample", "r"):
  6. if line.find("<!--") != -1:
  7. onoff = 0
  8. if line.find("file") != -1 and onoff==1:
  9. strs = line.split('\"')
  10. tool_list.append(strs[1])
  11. if line.find("<section") != -1 and onoff==1:
  12. keys = line.strip().split('\"')
  13. n = 0
  14. strtmp = "section::"
  15. while n < len(keys) :
  16. if keys[n].find("id") != -1 : strtmp = strtmp + keys[n+1]
  17. if keys[n].find("name") != -1 : strtmp = strtmp + keys[n+1] + "-"
  18. n = n + 1
  19. tool_list.append(strtmp.replace(' ', '_'))
  20. if line.find("-->") != -1:
  21. onoff =1
  22. #-------read tool info from every tool xml file--------------------------
  23. name = []
  24. id = []
  25. desc = []
  26. tool_infos = []
  27. for tool in tool_list :
  28. if tool.find("section")!=-1 :
  29. tool_info = dict()
  30. tool_info["id"] = tool
  31. tool_infos.append(tool_info)
  32. if os.path.exists("tools/"+tool) :
  33. for line in open("tools/"+tool) :
  34. if line.find("<tool ") != -1 and line.find("id") != -1 :
  35. keys = line.strip().split('\"')
  36. tool_info = dict()
  37. tool_info["desc"] = ''
  38. for n in range(len(keys)-1):
  39. if " id=" in keys[n]:
  40. tool_info["id"] = keys[n+1].replace(' ', '_')
  41. if " name=" in keys[n]:
  42. tool_info["name"] = keys[n+1]
  43. if " description=" in keys[n]:
  44. tool_info["desc"] = keys[n+1]
  45. tool_infos.append(tool_info)
  46. break
  47. flag=0
  48. if len(sys.argv) == 1 :
  49. for tool_info in tool_infos:
  50. if tool_info["id"].find("section") != -1 :
  51. print "==========================================================================================================================================="
  52. print "%-45s\t%-40s\t%s" % ("id", "name", tool_info["id"])
  53. print "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -"
  54. else :
  55. print "%-45s\t%-40s" % (tool_info["id"], tool_info["name"])
  56. else:
  57. for tool_info in tool_infos:
  58. if tool_info["id"].find("section") != -1 :
  59. flag=0
  60. elif flag==1:
  61. print " functional.test_toolbox:TestForTool_%s" % tool_info["id"],
  62. if tool_info["id"].replace('section::', '')==sys.argv[1]:
  63. flag=1
  64. #for key in tool_infos.keys():
  65. # print tool_infos[key]["id"], "\t", tool_infos[key]["name"], "\t", tool_infos[key]["desc"]