annotate commons/core/checker/CheckerUtils.py @ 6:769e306b7933

Change the repository level.
author yufei-luo
date Fri, 18 Jan 2013 04:54:14 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
1 # Copyright INRA (Institut National de la Recherche Agronomique)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
2 # http://www.inra.fr
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
3 # http://urgi.versailles.inra.fr
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
4 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
5 # This software is governed by the CeCILL license under French law and
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
6 # abiding by the rules of distribution of free software. You can use,
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
7 # modify and/ or redistribute the software under the terms of the CeCILL
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
8 # license as circulated by CEA, CNRS and INRIA at the following URL
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
9 # "http://www.cecill.info".
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
10 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
11 # As a counterpart to the access to the source code and rights to copy,
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
12 # modify and redistribute granted by the license, users are provided only
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
13 # with a limited warranty and the software's author, the holder of the
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
14 # economic rights, and the successive licensors have only limited
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
15 # liability.
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
16 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
17 # In this respect, the user's attention is drawn to the risks associated
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
18 # with loading, using, modifying and/or developing or reproducing the
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
19 # software by the user in light of its specific status of free software,
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
20 # that may mean that it is complicated to manipulate, and that also
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
21 # therefore means that it is reserved for developers and experienced
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
22 # professionals having in-depth computer knowledge. Users are therefore
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
23 # encouraged to load and test the software's suitability as regards their
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
24 # requirements in conditions enabling the security of their systems and/or
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
25 # data to be ensured and, more generally, to use and operate it in the
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
26 # same conditions as regards security.
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
27 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
28 # The fact that you are presently reading this means that you have had
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
29 # knowledge of the CeCILL license and that you accept its terms.
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
30
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
31
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
32 import os
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
33 import sys
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
34 import re
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
35 import glob
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
36 import ConfigParser
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
37 from ConfigParser import NoOptionError
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
38 from ConfigParser import NoSectionError
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
39 from commons.core.checker.CheckerException import CheckerException
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
40
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
41
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
42 ## A set of static methods used to perform checks.
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
43 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
44 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
45 class CheckerUtils( object ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
46
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
47 ## Check if blastName param is in ["blastn", "blastp", "blastx", "tblastn", "tblastx"]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
48 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
49 # @param blastName name to check
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
50 # @return True if name is in list False otherwise
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
51 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
52 def isBlastNameNotInBlastValues( blastName ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
53 blastValuesSet = set( ["blastn", "blastp", "blastx", "tblastn", "tblastx"] )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
54 blastNameSet = set( [ blastName ] )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
55 return not blastNameSet.issubset( blastValuesSet )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
56
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
57 isBlastNameNotInBlastValues = staticmethod( isBlastNameNotInBlastValues )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
58
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
59
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
60 ## Check if param is NOT "TRUE" and NOT false "FALSE"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
61 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
62 # @param param str to check
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
63 # @return True if param is not eq to "TRUE" AND not eq to "FALSE", false otherwise
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
64 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
65 def isNotTRUEisNotFALSE( param ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
66 return param != "TRUE" and param != "FALSE"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
67
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
68 isNotTRUEisNotFALSE = staticmethod( isNotTRUEisNotFALSE )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
69
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
70
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
71 ## Check if resource (file or dir) do NOT exists
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
72 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
73 # @param resource file or dir to check
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
74 # @return True if resource exists False otherwise
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
75 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
76 def isRessourceNotExits( resource ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
77 return not os.path.exists( resource )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
78
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
79 isRessourceNotExits = staticmethod( isRessourceNotExits )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
80
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
81
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
82 ## Check a specific E-value format: de-dd
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
83 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
84 # @param param E-value to check
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
85 # @return True if format is de-dd False otherwise
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
86 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
87 def isNotAeValueWithOneDigit2DecimalsAtLeast( param ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
88 # \d\d stands for 2 digits and more ???
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
89 return not re.match( "\de\-\d\d", param )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
90
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
91 isNotAeValueWithOneDigit2DecimalsAtLeast = staticmethod( isNotAeValueWithOneDigit2DecimalsAtLeast )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
92
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
93
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
94 ## Check a number format
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
95 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
96 # @param param value to check
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
97 # @return True if param is a number (d+) False otherwise
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
98 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
99 def isNotANumber( param ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
100 return not re.match( "\d+", param )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
101
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
102 isNotANumber = staticmethod( isNotANumber )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
103
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
104
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
105 ## Check if an executable is in the user's PATH
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
106 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
107 # @param exeName name of the executable
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
108 # @return True if executable in user's PATH, False otherwise
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
109 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
110 def isExecutableInUserPath( exeName ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
111 dirPathList = os.environ["PATH"].split(":")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
112 for dirPath in dirPathList:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
113 if os.path.isdir( dirPath ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
114 try:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
115 binPathList = glob.glob( dirPath + "/*" )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
116 except OSError, e:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
117 continue
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
118 for binPath in binPathList:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
119 bin = os.path.basename( binPath )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
120 if bin == exeName:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
121 return True
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
122 return False
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
123
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
124 isExecutableInUserPath = staticmethod( isExecutableInUserPath )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
125
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
126
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
127 ## Return the full path of a given executable
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
128 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
129 def getFullPathFromExecutable( exeName ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
130 lDirFromUserPath = os.environ["PATH"].split(":")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
131 for dir in lDirFromUserPath:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
132 if os.path.isdir( dir ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
133 try:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
134 lExecutables = glob.glob( "%s/*" % ( dir ) )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
135 except OSError, e:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
136 continue
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
137 for exe in lExecutables:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
138 path, exe = os.path.split( exe )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
139 if exe == exeName:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
140 return path
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
141 return ""
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
142
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
143 getFullPathFromExecutable = staticmethod( getFullPathFromExecutable )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
144
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
145
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
146 #TODO: to remove ?
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
147 ## Check if a queue Name is valid. Warning: Only with the queue manager SGE
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
148 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
149 # @param fullQueueName name of the queue to test (with or without parameters)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
150 # @return True if queue name is valid, False otherwise
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
151 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
152 def isQueueNameValid( fullQueueName ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
153 queueName = fullQueueName.split()[0]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
154 if queueName == "none":
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
155 return True
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
156 queueFile = "queueName.txt"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
157 if not CheckerUtils.isExecutableInUserPath( "qconf" ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
158 msg = "executable 'qconf' can't be found"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
159 sys.stderr.write( "%s\n" % ( msg ) )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
160 return False
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
161 cmd = "qconf -sql > " + queueFile
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
162 os.system( cmd )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
163 queueFileHandler = open( queueFile, "r" )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
164 lQueueNames = queueFileHandler.readlines()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
165 queueFileHandler.close()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
166 os.remove( queueFile )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
167 queueNameValid = False
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
168 for qName in lQueueNames:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
169 qName = qName.strip()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
170 if qName == queueName:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
171 queueNameValid = True
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
172 break
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
173 return queueNameValid
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
174
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
175 isQueueNameValid = staticmethod( isQueueNameValid )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
176
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
177
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
178 ## Check if a string length is lower or equal than 15
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
179 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
180 # @param strName any string
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
181 # @return True if string length is <= 15, False otherwise
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
182 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
183 def isMax15Char( strName ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
184 return (len(strName) <= 15 )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
185
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
186 isMax15Char = staticmethod( isMax15Char )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
187
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
188
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
189 ## Check if a string is made with only alphanumeric or underscore character
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
190 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
191 # @param strName any string
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
192 # @return True if string is with alphanumeric or underscore, False otherwise
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
193 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
194 def isCharAlphanumOrUnderscore( strName ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
195 # authorized ALPHABET [a-z,A-Z,0-9,_]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
196 p = re.compile('\W')
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
197 errList=p.findall(strName)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
198 if len( errList ) > 0 :
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
199 return False
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
200 else:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
201 return True
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
202
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
203 isCharAlphanumOrUnderscore = staticmethod( isCharAlphanumOrUnderscore )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
204
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
205
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
206 ## Check if sectionName is in the configuration file
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
207 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
208 # @param config filehandle of configuration file
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
209 # @param sectionName string of section name to check
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
210 # @exception NoSectionError: if section not found raise a NoSectionError
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
211 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
212 def checkSectionInConfigFile( config, sectionName ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
213 if not (config.has_section(sectionName)):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
214 raise NoSectionError(sectionName)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
215
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
216 checkSectionInConfigFile = staticmethod( checkSectionInConfigFile )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
217
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
218
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
219 ## Check if an option is in a specified section in the configuration file
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
220 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
221 # @param config filehandle of configuration file
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
222 # @param sectionName string of section name
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
223 # @param optionName string of option name to check
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
224 # @exception NoOptionError: if option not found raise a NoOptionError
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
225 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
226 def checkOptionInSectionInConfigFile( config, sectionName, optionName ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
227 config.get( sectionName, optionName )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
228
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
229 checkOptionInSectionInConfigFile = staticmethod( checkOptionInSectionInConfigFile )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
230
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
231
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
232 ## Check version number coherency between configFile and CHANGELOG
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
233 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
234 # @param config ConfigParser Instance of configuration file
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
235 # @param changeLogFileHandle CHANGELOG file handle
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
236 # @exception NoOptionError: if option not found raise a NoOptionError
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
237 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
238 def checkConfigVersion( changeLogFileHandle, config ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
239 line = changeLogFileHandle.readline()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
240 while not line.startswith("REPET release "):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
241 line = changeLogFileHandle.readline()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
242 numVersionChangeLog = line.split()[2]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
243
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
244 numVersionConfig = config.get("repet_env", "repet_version")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
245
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
246 if not numVersionChangeLog == numVersionConfig:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
247 message = "*** Error: wrong config file version. Expected version num is " + numVersionChangeLog + " but actual in config file is " + numVersionConfig
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
248 raise CheckerException(message)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
249
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
250 checkConfigVersion = staticmethod( checkConfigVersion )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
251
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
252
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
253 ## Get version number from CHANGELOG
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
254 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
255 # @param changeLogFile CHANGELOG file name
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
256 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
257 def getVersionFromChangelogFile(changeLogFileName):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
258 with open(changeLogFileName) as changeLogFileHandle:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
259 line = changeLogFileHandle.readline()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
260 while not line.startswith("REPET release "):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
261 line = changeLogFileHandle.readline()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
262 numVersionChangeLog = line.split()[2]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
263 return numVersionChangeLog
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
264
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
265
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
266 getVersionFromChangelogFile = staticmethod( getVersionFromChangelogFile )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
267
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
268
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
269 ## Check if headers of an input file contain only alpha numeric characters and "_ : . -"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
270 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
271 # @param fileHandler file handle
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
272 # @exception CheckerException if bad header raise a CheckerException
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
273 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
274 def checkHeaders( fileHandler ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
275 lHeaders = CheckerUtils._getHeaderFromFastaFile(fileHandler)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
276 p = re.compile('[^a-zA-Z0-9_:\.\-]', re.IGNORECASE)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
277 lWrongHeaders = []
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
278 for header in lHeaders:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
279 errList=p.findall(header)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
280 if len( errList ) > 0 :
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
281 lWrongHeaders.append(header)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
282 if lWrongHeaders != []:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
283 exception = CheckerException()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
284 exception.setMessages(lWrongHeaders)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
285 raise exception
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
286
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
287 checkHeaders = staticmethod( checkHeaders )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
288
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
289
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
290 def _getHeaderFromFastaFile( inFile ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
291 lHeaders = []
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
292 while True:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
293 line = inFile.readline()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
294 if line == "":
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
295 break
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
296 if line[0] == ">":
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
297 lHeaders.append( line[1:-1] )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
298 return lHeaders
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
299
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
300 _getHeaderFromFastaFile = staticmethod( _getHeaderFromFastaFile )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
301
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
302
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
303 ## Return True if an option is in a specified section in the configuration file, False otherwise
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
304 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
305 # @param config handler of configuration file
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
306 # @param sectionName string of section name
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
307 # @param optionName string of option name to check
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
308 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
309 def isOptionInSectionInConfig( configHandler, section, option ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
310 try:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
311 CheckerUtils.checkOptionInSectionInConfigFile( configHandler, section, option )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
312 except NoOptionError:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
313 return False
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
314 return True
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
315
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
316 isOptionInSectionInConfig = staticmethod( isOptionInSectionInConfig )