Exemple #1
0
 def read(self, spec, fields=None):
     "Read API, it reads data from MongoDB storage for provided spec."
     try:
         gen = self.find(spec, fields)
         docs = [r for r in gen]
         return docs
     except Exception as exp:
         raise ReadError(str(exp))
Exemple #2
0
 def file_read(self, fname):
     "Read documents from given file name"
     try:
         schema = self.schema
         out = []
         with DataFileReader(open_file(fname), DatumReader()) as reader:
             for rec in reader:
                 out.append(rec)
         return out
     except Exception as exc:
         err = traceback.format_exc(limit=1).splitlines()[-1]
         msg = 'Failure in %s storage, error=%s' % (self.stype, err)
         raise ReadError(msg)
Exemple #3
0
 def read(self, spec, fields=None):
     "Read API for LTS"
     try:
         if not spec:
             spec = {}
         if isinstance(spec, list):
             spec = {'wmaid': {'$in': spec}}
             return self.read_from_storage(spec)  # list of wmaids
         elif PAT_UID.match(str(spec)):
             return self.read_from_storage([spec])  # one wmaid
         else:
             return self.submit(spec, fields)
     except Exception as exp:
         raise ReadError(str(exp))
Exemple #4
0
 def read(self, spec, fields=None):
     "Read data from local storage for given spec"
     try:
         if isinstance(spec, list):
             out = []
             for item in spec:
                 res = self._read(item, fields)
                 if res and len(res) == 1:
                     out.append(res[0])
             return out
         data = self._read(spec, fields)
         return data
     except Exception as exc:
         err = traceback.format_exc(limit=1).splitlines()[-1]
         msg = 'Failure in %s storage, error=%s' % (self.stype, err)
         raise ReadError(msg)