Module EDUtilsImage
[hide private]
[frames] | no frames]

Source Code for Module EDUtilsImage

 1  # 
 2  #    Project: The EDNA Kernel 
 3  #             http://www.edna-site.org 
 4  # 
 5  #    File: "$Id$" 
 6  # 
 7  #    Copyright (C) 2008-2009 European Synchrotron Radiation Facility 
 8  #                            Grenoble, France 
 9  # 
10  #    Principal authors: Marie-Francoise Incardona (incardon@esrf.fr) 
11  #                       Olof Svensson (svensson@esrf.fr)  
12  #                       Jerome Kieffer 
13  # 
14  #    This program is free software: you can redistribute it and/or modify 
15  #    it under the terms of the GNU Lesser General Public License as published 
16  #    by the Free Software Foundation, either version 3 of the License, or 
17  #    (at your option) any later version. 
18  # 
19  #    This program is distributed in the hope that it will be useful, 
20  #    but WITHOUT ANY WARRANTY; without even the implied warranty of 
21  #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
22  #    GNU Lesser General Public License for more details. 
23  # 
24  #    You should have received a copy of the GNU General Public License 
25  #    and the GNU Lesser General Public License  along with this program.   
26  #    If not, see <http://www.gnu.org/licenses/>. 
27  # 
28   
29  """ 
30  This is a static utility class for handling of files. 
31  """ 
32   
33  __authors__ = [ "Marie-Francoise Incardona", "Olof Svensson", "Jerome Kieffer" ] 
34  __contact__ = "svensson@esrf.fr" 
35  __license__ = "LGPLv3+" 
36  __copyright__ = "European Synchrotron Radiation Facility, Grenoble, France" 
37   
38   
39  import os, re 
40 41 42 -class EDUtilsImage:
43 44 45 @staticmethod
46 - def __compileAndMatchRegexpTemplate(_strPathToImage):
47 listResult = [] 48 pyStrBaseImageName = os.path.basename(_strPathToImage) 49 pyRegexp = re.compile(r'(.*)([^0^1^2^3^4^5^6^7^8^9])([0-9]*)\.(.*)') 50 pyMatch = pyRegexp.match(pyStrBaseImageName) 51 if (pyMatch != None): 52 listResult = [ pyMatch.group(0), pyMatch.group(1) , pyMatch.group(2) , pyMatch.group(3) , pyMatch.group(4) ] 53 return listResult
54 55 56 @staticmethod
57 - def getImageNumber(_strPathToImage):
58 iImageNumber = None 59 listResult = EDUtilsImage.__compileAndMatchRegexpTemplate(_strPathToImage) 60 if (listResult != None): 61 iImageNumber = int(listResult[3]) 62 return iImageNumber
63 64 65 @staticmethod
66 - def getTemplate(_strPathToImage, _strSymbol="#"):
67 strTemplate = None 68 listResult = EDUtilsImage.__compileAndMatchRegexpTemplate(_strPathToImage) 69 if (listResult != None): 70 strPrefix = listResult[1] 71 strSeparator = listResult[2] 72 strImageNumber = listResult[3] 73 strSuffix = listResult[4] 74 strHashes = "" 75 for i in range(len(strImageNumber)): 76 strHashes += _strSymbol 77 strTemplate = strPrefix + strSeparator + strHashes + "." + strSuffix 78 return strTemplate
79 80 81 @staticmethod
82 - def getPrefix(_strPathToImage):
83 strPrefix = None 84 listResult = EDUtilsImage.__compileAndMatchRegexpTemplate(_strPathToImage) 85 if (listResult != None): 86 strPrefix = listResult[1] 87 return strPrefix
88 89 90 @staticmethod
91 - def getSuffix(_strPathToImage):
92 strSuffix = None 93 listResult = EDUtilsImage.__compileAndMatchRegexpTemplate(_strPathToImage) 94 if (listResult != None): 95 strSuffix = listResult[4] 96 return strSuffix
97