示例#1
0
    def __init__(self, report_file, semaphore):
        try:
            # Insert the report into the database
            self.fh = open(report_file)
            self._report = yaml.safe_load_all(self.fh)
            self.header = self._report.next()
            cc = self.header['probe_cc']
            assert re.match("[a-zA-Z]{2}", cc)

            public_file = join(settings.public_directory, cc,
                               basename(report_file)+".gz")
            self.header['report_file'] = public_file
            report = self.header
            report['measurements'] = []
            self.rid = settings.db.reports.insert(report)

            test_name = self.header['test_name']

            # Insert each measurement into the database
            for entry in self:
                entry = run_process(test_name, report_file, entry)
                settings.db.reports.update(
                    {'_id': self.rid},
                    {'$push': {'measurements': entry}
                })

            try:
                makedirs(dirname(public_file))
            except OSError as exc:
                if exc.errno != 17:
                    raise exc

            fsrc = open(report_file, 'rb')
            fdst = gzip.open(public_file, 'wb')
            shutil.copyfileobj(fsrc, fdst)
            fsrc.close()
            fdst.close()

            remove(report_file)
        except Exception, e:
            print e
示例#2
0
 def process(self, entry):
     return run_process(self.header['test_name'], self.report_path, entry)