Changeset 2fd516b in sasview for DataLoader
- Timestamp:
- Jul 9, 2008 5:05:25 PM (16 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- 94daf8a
- Parents:
- 9cd84ee
- Location:
- DataLoader
- Files:
-
- 1 deleted
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
DataLoader/loader.py
r3dd7cce r2fd516b 73 73 74 74 75 def __setitem__(self, ext=None, reader=None):75 def __setitem__(self,dir=None, ext=None, reader=None): 76 76 """ 77 77 __setitem__ sets in a dictionary(self.readers) a given reader … … 79 79 @param ext: extension given of type string 80 80 @param reader:instance Reader class 81 @param dir: directory name where plugins readers will be saved 81 82 @raise : ValueError will be raise if a "plugins" directory is not found 82 83 and the user didn't add a reader as parameter or if the user didn't … … 86 87 ext , a ValueError "missing extension" is raised. 87 88 @note: when called without parameters __setitem__ will try to load 88 readers inside a "plugins" directory 89 """ 90 import os 89 readers inside a "readers" directory 90 if call with a directory name will try find readers 91 from that directory "dir" 92 """ 93 if dir==None: 94 dir='readers' 95 91 96 if reader==None and ext==None:#1st load 92 97 plugReader=None 93 if os.path.isdir( 'plugins'):94 plugReader=_findReaders( 'plugins')# import all module in plugins95 if os.path.isdir('../ plugins'):96 plugReader=_findReaders('../ plugins')98 if os.path.isdir(dir): 99 plugReader=_findReaders(dir)# import all module in plugins 100 if os.path.isdir('../'+dir): 101 plugReader=_findReaders('../'+dir) 97 102 else: 98 if os.path.isdir('.. \DataLoader\plugins'):99 os.chdir(os.path.abspath('.. \DataLoader\plugins'))# change the current100 plugReader=_findReaders( 'plugins')103 if os.path.isdir('../DataLoader/'+dir): 104 os.chdir(os.path.abspath('../DataLoader/'+dir))# change the current 105 plugReader=_findReaders(dir) 101 106 102 107 if plugReader !=None: 103 108 for preader in plugReader:# for each modules takes list of extensions 104 print preader,preader.ext 105 for item in preader.ext: 109 try: 110 list=preader.ext 111 except: 112 raise AttributeError," %s instance has no attribute 'ext'"\ 113 %(preader.__class__) 114 for item in list: 106 115 ext=item 107 116 if ext not in self.readers:#assign extension with its reader … … 115 124 elif reader!=None: 116 125 #only reader is receive try to find a field ext 117 if reader.ext: 118 for item in reader.ext: 119 ext=item 120 if ext not in self.readers:#assign extension with its reader 121 self.readers[ext] = [] 122 self.readers[ext].insert(0,reader) 123 else: 124 raise ValueError,"missing extension" 126 try: 127 list=preader.ext 128 except: 129 raise AttributeError," Reader instance has no attribute 'ext'" 130 for item in list: 131 132 ext=item 133 if ext not in self.readers:#assign extension with its reader 134 self.readers[ext] = [] 135 self.readers[ext].insert(0,reader) 136 125 137 else: 126 138 raise ValueError,"missing reader" -
DataLoader/readers/IgorReader.py
rc125e0c r2fd516b 5 5 class Reader: 6 6 """ Simple data reader for Igor data files """ 7 7 ext=['.ASC'] 8 8 def __init__(self, filename=None): 9 9 """ Init -
DataLoader/test/testplugings.py
rd22da51 r2fd516b 12 12 import os 13 13 class testLoader(unittest.TestCase): 14 14 L=Loader() 15 15 def testplugin(self): 16 """ test loading with readers""" 17 18 self.assertEqual(self.L.__contains__('.tiff'),True) 19 self.assertEqual(self.L.__contains__('.png'),True) 20 self.assertEqual(self.L.__contains__('.txt'),True) 21 def testplugin1(self): 16 22 """ test loading with plugging""" 17 l=Loader() 18 self.assertEqual(l.__contains__('.tiff'),True) 19 self.assertEqual(l.__contains__('.png'),True) 20 self.assertEqual(l.__contains__('.txt'),True) 21 23 self.L.__setitem__(dir='plugins') 24 #Testing loading a txt file of 2 columns, the only reader should be read1 25 xload,yload,dyload=self.L.load('test_2_columns.txt') 26 x=[2.83954,0.204082,0.408163,0.612245,0.816327,1.02041,1.22449,1.42857,1.63265] 27 y=[0.6,3.44938, 5.82026,5.27591,5.2781,5.22531,7.47487,7.85852,10.2278] 28 dx=[] 29 dy=[] 30 self.assertEqual(len(xload),len(x)) 31 self.assertEqual(len(yload),len(y)) 32 self.assertEqual(len(dyload),0) 33 for i in range(len(x)): 34 self.assertEqual(xload[i],x[i]) 35 self.assertEqual(yload[i],y[i])
Note: See TracChangeset
for help on using the changeset viewer.