1 import sys
2 import os
3
4
5
6
7 biana_path = None
8 site_packages_path = None
9
10
11 for current_path_index in xrange(1,len(sys.path)):
12 if not os.path.exists(sys.path[current_path_index]):
13 continue
14 if not os.path.isdir(sys.path[current_path_index]):
15 continue
16 for current_dir in os.listdir(sys.path[current_path_index]):
17 if not os.path.isdir(sys.path[current_path_index]+os.sep+current_dir):
18 continue
19 if current_dir.lower() == "biana":
20 biana_path = sys.path[current_path_index]
21 break
22
23 if biana_path is None:
24 biana_path = site_packages_path
25
26 biana_path = biana_path+os.sep+"biana"+os.sep+"BianaParser"
27
28 sys.path.append(biana_path)
29
30 list_all_files = os.listdir(biana_path)
31
32 not_allowed_import_files = ["bianaParser.py","database2biana.py","__init__.py", "psi_MiXMLParser.py"]
33
34 list_python_files = []
35 for current_file in list_all_files:
36 if current_file.endswith(".py") and current_file not in not_allowed_import_files and not current_file.startswith("."):
37 list_python_files.append(current_file)
38
39 parserObjects = {}
40
41
42 imports = map(__import__, [ x[0:-3] for x in list_python_files] )
43
44
45 for current_parser in imports[0].BianaParser.__subclasses__():
46 parserObjects[current_parser.name.lower()] = current_parser
47
48
50 """
51 Runs the script to insert the parser to the database
52 """
53 parser = ""
54 try:
55 parser = sys.argv[1]
56 except:
57 sys.stderr.write("First argument must be the name of the parser to execute.\n")
58
59 if parserObjects.has_key(parser.lower()):
60 parserObjects[parser.lower()]().start()
61 else:
62 sys.stderr.write("Database parser not recognized\n")
63 parsers_list = [x[0] for x in get_available_parsers_info()]
64 parsers_list.sort()
65 sys.stderr.write("Accepted parsers are: \n\t%s\n" %"\n\t".join(parsers_list))
66 sys.exit(2)
67
68
70 """
71 Returns a list of tuples with the information of the parsers. (parser_name, parser_description, external_entity_definition)
72 """
73
74 return [ (current_parser.name, current_parser.description, current_parser.external_entity_definition) for current_parser in parserObjects.values() ]
75