annotate TEisotools-1.1.a/commons/core/checker/CheckerUtils.py @ 15:255c852351c5 draft

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