/search.css" rel="stylesheet" type="text/css"/> /search.js">
00001 "Provides access to the Ingest Catalog from python" 00002 00003 import os 00004 00005 warehouse = os.getenv('CATALOG_WAREHOUSE') 00006 if (not warehouse): 00007 warehouse = 'pdsf' 00008 server = os.getenv('CATALOG_SERVER') 00009 if (not server): 00010 server = 'dayabay.lbl.gov' 00011 url = os.getenv('CATALOG_URL') 00012 if (not url): 00013 url = 'http://' + server + '/warehouse-ws/' + warehouse + '/CatalogBean' 00014 00015 class MismatchException(Exception): 00016 def __str__(self): 00017 "Application/Stream mismatch" 00018 00019 class SetSelection: 00020 'Internal class that contains the representation of a selection of file sets' 00021 00022 def __init__(self, lhs, rhs): 00023 """ 00024 Creates an selection. If the second argument in None, then 00025 the first argument is taken to be a single selection. Otherwise 00026 both argments are taken to be instances of this class. 00027 """ 00028 self.resolution = None 00029 self.content = [] 00030 if (None == rhs): 00031 self.content.append(lhs) 00032 else: 00033 self.content = lhs.content + rhs.content 00034 self.subset = None 00035 00036 def __add__(self, others): 00037 if (self.subset != others.subset): 00038 raise MismatchException 00039 result = SetSelection(self, others) 00040 result.subset = self.subset 00041 return result 00042 00043 def __getitem__(self, key): 00044 self.resolve() 00045 return self.resolution[key] 00046 00047 def __len__(self): 00048 self.resolve() 00049 return len(self.resolution) 00050 00051 def resolve(self): 00052 if self.resolution: 00053 return 00054 00055 from dybcatalog_pkg.suds_stubs import getLocations 00056 self.resolution = getLocations(self.content, 00057 self.subset) 00058 00059 def __repr__(self): 00060 try: 00061 self.resolve() 00062 except TypeError as e: 00063 if 'Response is "text/html", not "text/xml"' == e.message: 00064 raise IOError('Failed to get correct reponse from Web Service') 00065 else: 00066 raise e 00067 return str(self.resolution) 00068 00069 00070 class RunSelection: 00071 'Internal class that contains the representation of a selection of Runs' 00072 00073 def __init__(self, lhs, rhs): 00074 """ 00075 Creates an selection. If the second argument in None, then 00076 the first argument is taken to be a single selection. Otherwise 00077 both argments are taken to be instances of this class. 00078 """ 00079 self.resolution = None 00080 self.content = [] 00081 if (None == rhs): 00082 self.content.append(lhs) 00083 else: 00084 self.content = lhs.content + rhs.content 00085 self.subset = None 00086 self.application = None 00087 self.stream = None 00088 00089 def __add__(self, others): 00090 if (self.subset != others.subset) or (self.application != others.application) or (self.stream != others.stream): 00091 raise MismatchException 00092 result = RunSelection(self, others) 00093 result.subset = self.subset 00094 result.application = self.application 00095 result.stream = self.stream 00096 return result 00097 00098 def __getitem__(self, item): 00099 self.resolve() 00100 if isinstance(item, slice): 00101 indices = item.indices(len(self)) 00102 return self.resolution[indices[0]:indices[1]:indices[2]] 00103 else: 00104 return self.resolution[item] 00105 00106 def __len__(self): 00107 self.resolve() 00108 return len(self.resolution) 00109 00110 def resolve(self): 00111 if self.resolution: 00112 return 00113 00114 from dybcatalog_pkg.suds_stubs import getLocationsByRunRanges 00115 self.resolution = getLocationsByRunRanges(self.content, 00116 self.application, 00117 self.stream, 00118 self.subset) 00119 00120 def __repr__(self): 00121 try: 00122 self.resolve() 00123 except TypeError as e: 00124 if 'Response is "text/html", not "text/xml"' == e.message: 00125 raise IOError('Failed to get correct reponse from Web Service') 00126 else: 00127 raise e 00128 return str(self.resolution) 00129 00130 00131 class EntrySelection: 00132 'Internal class that contains the representation of a selection of EntryIds' 00133 00134 def __init__(self, lhs, rhs): 00135 """ 00136 Creates an selection. If the second argument in None, then 00137 the first argument is taken to be a single selection. Otherwise 00138 both argments are taken to be instances of this class. 00139 """ 00140 self.resolution = None 00141 self.content = [] 00142 if (None == rhs): 00143 self.content.append(lhs) 00144 else: 00145 self.content = lhs.content + rhs.content 00146 self.subset = None 00147 00148 def __add__(self, others): 00149 if (self.subset != others.subset): 00150 raise MismatchException 00151 result = EntrySelection(self, others) 00152 result.subset = self.subset 00153 return result 00154 00155 def __getitem__(self, key): 00156 self.resolve() 00157 return self.resolution[key] 00158 00159 def __len__(self): 00160 self.resolve() 00161 return len(self.resolution) 00162 00163 def resolve(self): 00164 if self.resolution: 00165 return 00166 00167 from dybcatalog_pkg.suds_stubs import getLocations 00168 self.resolution = getLocations(self.content, 00169 self.subset) 00170 00171 def __repr__(self): 00172 try: 00173 self.resolve() 00174 except TypeError as e: 00175 if 'Response is "text/html", not "text/xml"' == e.message: 00176 raise IOError('Failed to get correct reponse from Web Service') 00177 else: 00178 raise e 00179 return str(self.resolution) 00180 00181 00182 class FileSets: 00183 00184 def __getitem__(self, key): 00185 selection = SetSelection(key, None) 00186 selection.subset = self.subset 00187 return selection 00188 00189 00190 class RunRange: 00191 00192 def __getitem__(self, item): 00193 if isinstance(item, slice): 00194 selection = RunSelection((item.start,item.stop,item.step), None) 00195 else: 00196 selection = RunSelection((item, item + 1, None), None) 00197 selection.subset = self.subset 00198 selection.application = self.application 00199 selection.stream = self.stream 00200 return selection 00201 00202 00203 class EntryIds: 00204 00205 def __getitem__(self, key): 00206 selection = EntrySelection(key, None) 00207 selection.subset = self.subset 00208 return selection 00209 00210 00211 class Stream: 00212 00213 def __call__(self, name): 00214 self.runs = RunRange() 00215 self.runs.subset = self.subset 00216 self.runs.application = self.application 00217 self.runs.stream = name 00218 return self 00219 00220 00221 class Application: 00222 00223 def __call__(self, name): 00224 self.runs = RunRange() 00225 self.runs.subset = self.subset 00226 self.runs.application = name 00227 self.runs.stream = None 00228 self.stream = Stream() 00229 self.stream.subset = self.subset 00230 self.stream.application = name 00231 return self 00232 00233 00234 class Subset: 00235 00236 def __call__(self, name): 00237 self.ids = EntryIds() 00238 self.ids.subset = name 00239 self.fileSets = FileSets() 00240 self.fileSets.subset = name 00241 self.runs = RunRange() 00242 self.runs.subset = name 00243 self.runs.application = None 00244 self.runs.stream = None 00245 self.stream = Stream() 00246 self.stream.subset = name 00247 self.stream.application = None 00248 self.appl = Application() 00249 self.appl.subset = name 00250 return self 00251 00252 00253 ids = EntryIds() 00254 ids.subset = None 00255 00256 fileSets = FileSets() 00257 fileSets.subset = None 00258 00259 runs = RunRange() 00260 runs.subset = None 00261 runs.application = None 00262 runs.stream = None 00263 stream = Stream() 00264 stream.subset = None 00265 stream.application = None 00266 appl = Application() 00267 appl.subset = None 00268 good = Subset() 00269 00270 00271 def getSettings(): 00272 result = ' URL of Catalog web service is "' + url + '"' 00273 return result