[ee5479d8] | 1 | from register import ExtensionRegistry |
---|
| 2 | import TXT3_Reader, TXT2_Reader,DataReader |
---|
| 3 | import danse_reader |
---|
| 4 | import tiff_reader |
---|
| 5 | #import tiff_reader |
---|
| 6 | class Loader: |
---|
| 7 | def __init__(self): |
---|
| 8 | """ init method""" |
---|
| 9 | self.reg=ExtensionRegistry() |
---|
| 10 | def setFormat(self,ext,reader): |
---|
| 11 | """ |
---|
| 12 | Load the available reader with file extensions |
---|
| 13 | @param ext:file extension |
---|
| 14 | @param reader: instance of a reader |
---|
| 15 | """ |
---|
| 16 | #self.reg[ext]=reader |
---|
| 17 | self.reg.__setitem__(ext, reader) |
---|
| 18 | def getReader(self,ext): |
---|
| 19 | return self.reg.__getitem__( ext) |
---|
| 20 | |
---|
| 21 | |
---|
| 22 | def loadData(self,path,format=None): |
---|
| 23 | """ Read a file and save values""" |
---|
| 24 | self.reg.lookup(path) |
---|
| 25 | try: |
---|
| 26 | return self.reg.load(path,format) |
---|
| 27 | except ValueError,msg: |
---|
| 28 | print msg |
---|
| 29 | |
---|
| 30 | |
---|
| 31 | def getextension(self,name=False,ext=True): |
---|
| 32 | """ return list of readers""" |
---|
| 33 | return self.reg.formats(name,ext) |
---|
| 34 | def test(): |
---|
| 35 | L=Loader() |
---|
| 36 | |
---|
| 37 | read1=TXT2_Reader.Reader() |
---|
| 38 | read2=TXT3_Reader.Reader() |
---|
| 39 | read3=DataReader.DataReader() |
---|
| 40 | read4=danse_reader.DataReader() |
---|
| 41 | read5=tiff_reader.DataReader() |
---|
| 42 | |
---|
| 43 | L.setFormat('.txt',read1) |
---|
| 44 | L.setFormat('.txt',read2) |
---|
| 45 | |
---|
| 46 | L.setFormat('.dat',read2) |
---|
| 47 | L.setFormat('.dat',read1) |
---|
| 48 | |
---|
| 49 | L.setFormat('.ASC',read3) |
---|
| 50 | L.setFormat('.sans',read4) |
---|
| 51 | L.setFormat('.sans',read5) |
---|
| 52 | L.setFormat('.tif',read5) |
---|
| 53 | L.setFormat('.jpg',read5) |
---|
| 54 | L.setFormat('.png',read5) |
---|
| 55 | L.setFormat('.jpeg',read5) |
---|
| 56 | L.setFormat('.gif',read5) |
---|
| 57 | L.setFormat('.bmp',read5) |
---|
| 58 | |
---|
| 59 | |
---|
| 60 | |
---|
| 61 | print L.loadData('testdata_line.txt') |
---|
| 62 | print L.loadData('test.dat') |
---|
| 63 | print L.loadData('test.date') |
---|
| 64 | print L.loadData('MAR07232_rest.ASC') |
---|
| 65 | print L.loadData('AR07232_rest.ASC') |
---|
| 66 | print L.loadData('MP_New.sans') |
---|
| 67 | print L.loadData('P_New.sans') |
---|
| 68 | print L.loadData('angles_flat.png') |
---|
| 69 | |
---|
| 70 | |
---|
| 71 | |
---|
| 72 | |
---|
| 73 | |
---|
| 74 | if __name__ == "__main__": test() |
---|