Package omero :: Package util :: Module originalfileutils
[hide private]
[frames] | no frames]

Source Code for Module omero.util.originalfileutils

  1  #!/usr/bin/python 
  2  # 
  3  #------------------------------------------------------------------------------ 
  4  #  Copyright (C) 2006-2008 University of Dundee. All rights reserved. 
  5  # 
  6  # 
  7  #       This program is free software; you can redistribute it and/or modify 
  8  #  it under the terms of the GNU General Public License as published by 
  9  #  the Free Software Foundation; either version 2 of the License, or 
 10  #  (at your option) any later version. 
 11  #  This program is distributed in the hope that it will be useful, 
 12  #  but WITHOUT ANY WARRANTY; without even the implied warranty of 
 13  #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 14  #  GNU General Public License for more details. 
 15  #   
 16  #  You should have received a copy of the GNU General Public License along 
 17  #  with this program; if not, write to the Free Software Foundation, Inc., 
 18  #  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 
 19  # 
 20  #---------------------------------------------------------------------- 
 21   
 22  ### 
 23  # 
 24  # Original file utilities 
 25  # This file supplies some utilities to deal with OriginalFile Objects. 
 26  # 
 27  # 
 28  # @author  Jean-Marie Burel      
 29  #       <a href="mailto:j.burel@dundee.ac.uk">j.burel@dundee.ac.uk</a> 
 30  # @author       Donald MacDonald &nbsp;&nbsp;&nbsp;&nbsp; 
 31  #       <a href="mailto:donald@lifesci.dundee.ac.uk">donald@lifesci.dundee.ac.uk</a> 
 32  # @version 3.0 
 33  # <small> 
 34  # (<b>Internal version:</b> $Revision: $Date: $) 
 35  # </small> 
 36  # @since 3.0-Beta4 
 37  #/ 
 38  import mimetypes; 
 39   
 40  importerMap = {'.dcm':'Dicom', 
 41  '.dicom':'Dicom', 
 42  '.pic':'BioRad', 
 43  '.ipl':'IPLab', 
 44  '.iplm':'IPLab', 
 45  '.dv':'Deltavision', 
 46  '.r3d':'Deltavision', 
 47  '.mrc':'MRC', 
 48  '.dm3':'Gatan', 
 49  '.ims':'Imaris', 
 50  '.raw':'OpenlabRaw', 
 51  '.ome':'OMEXML', 
 52  '.lif':'LIF', 
 53  '.sdt':'SDT', 
 54  '.sld':'Slidebook', 
 55  '.al3d':'Alicona', 
 56  '.mng':'MNG', 
 57  '.nrrd':'NNRD', 
 58  '.xv':'Khoros', 
 59  '.xys':'Visitech', 
 60  '.lim':'LIM', 
 61  '.xdce':'InCell', 
 62  '.ics':'ICS', 
 63  '.2':'PerkinElmer', 
 64  '.3':'PerkinElmer', 
 65  '.4':'PerkinElmer', 
 66  '.5':'PerkinElmer', 
 67  '.6':'PerkinElmer', 
 68  '.7':'PerkinElmer', 
 69  '.8':'PerkinElmer', 
 70  '.9':'PerkinElmer', 
 71  '.zvi':'ZeissZVI', 
 72  '.ipw':'IPW', 
 73  '.nef':'LegecyND2', 
 74  '.nd2':'ND2', 
 75  '.cxd':'PCI', 
 76  '.stk':'Metamorph', 
 77  '.lsm':'ZeissLSM', 
 78  '.seq':'SEQ', 
 79  '.gel':'Gel', 
 80  '.flex':'Flex', 
 81  '.svs':'SVS', 
 82  '.lei':'Leica', 
 83  '.oib':'Fluoview', 
 84  '.oif':'Fluoview', 
 85  '.ome.tif':'OMETiff', 
 86  '.liff':'Openlab'}; 
 87   
 88  formatMap = {'.avi':'AVI', 
 89  '.qt':'QT', 
 90  '.pic':'Pict', 
 91  '.eps':'EPS', 
 92  '.psd':'PSD', 
 93  '.jp2':'video/jpeg2000', 
 94  '.tif':'image/tiff', 
 95  '.tiff':'image/tiff'}; 
 96   
 97  UNKNOWN = 'type/unknown'; 
 98  KNOWNMIMETYPE = 'type/known'; 
 99  IMPORTER = 'application/importer'; 
100   
101 -def getExtension(filename):
102 if(filename==None): 103 return filename; 104 str = filename.split('.'); 105 if(len(str)<2): 106 return None; 107 return str[len(str)-1];
108
109 -def getFormat(filename):
110 if(getExtension(filename)==None): 111 return (UNKNOWN, UNKNOWN); 112 if(getExtension(filename) in importerMap): 113 return (IMPORTER, importerMap[filename]); 114 if(getExtension(filename) in formatMap): 115 return (KNOWNMIMETYPE, formatMap[filename]); 116 if(mimetypes.guess_type(filename) != (None, None)): 117 return (KNOWNMIMETYPE, mimetypes.guess_type(filename)[0]); 118 else: 119 return (UNKNOWN, UNKNOWN);
120