PageRenderTime 17ms CodeModel.GetById 8ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/tool_list.py

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