def test_line_reader(self):
        lines = """line1
line2
line3\rline4\r
line5"""
        expected = ['line1', 'line2', 'line3', 'line4', 'line5']
        self.assertEqual(list(utils.line_reader(StringIO(lines))), expected)
    def test_line_reader(self):
        lines = """line1
line2
line3\rline4\r
line5"""
        expected = ['line1', 'line2', 'line3', 'line4', 'line5']
        self.assertEqual(list(utils.line_reader(StringIO(lines))), expected)
Esempio n. 3
0
    def process_output(self):
        self.started_at = time.time()
        self.status = 'converting'
        # We use line_reader, rather than just iterating over the file object,
        # because iterating over the file object gives us all the lines when
        # the process ends, and we're looking for real-time updates.
        for line in line_reader(self.popen.stdout):
            self.lines.append(line) # for debugging, if needed
            try:
                status = self.converter.process_status_line(self.video, line)
            except StandardError:
                logging.warn("error in process_status_line()", exc_info=True)
                continue
            if status is None:
                continue
            updated = set()
            if 'finished' in status:
                self.error = status.get('error', None)
                break
            if 'duration' in status:
                updated.update(('duration', 'progress'))
                self.duration = float(status['duration'])
                if self.progress is None:
                    self.progress = 0.0
            if 'pass1' in status:
                updated.add('progress')
                self.progress = min(float(status['pass1']/2.0),
                                    self.duration)
            if 'pass2' in status:
                updated.add('progress')
                self.progress = min(float(status['pass2']/2.0 + 5),
                                    self.duration)
            if 'progress' in status:
                updated.add('progress')
                self.progress = min(float(status['progress']),
                                    self.duration)
            if 'eta' in status:
                updated.add('eta')
                self.eta = float(status['eta'])

            if updated:
                self.progress_percent = self.calc_progress_percent()
                if 'eta' not in updated:
                    if self.duration and 0 < self.progress_percent < 1.0:
                        progress = self.progress_percent * 100
                        elapsed = time.time() - self.started_at
                        time_per_percent = elapsed / progress
                        self.eta = float(
                            time_per_percent * (100 - progress))
                    else:
                        self.eta = 0.0

                self.notify_listeners()