Beispiel #1
0
    def stopped(self, taskk):
        from morituri.common import checksum

        if not taskk.exception:
            # Check if the tags are different or not
            if taskk == self.tasks[0]:
                taglist = taskk.taglist.copy()
                if common.tagListEquals(taglist, self._taglist):
                    self.debug('tags are already fine: %r',
                               common.tagListToDict(taglist))
                else:
                    # need to retag
                    self.debug('tags need to be rewritten')
                    self.debug('Current tags: %r, new tags: %r',
                               common.tagListToDict(taglist),
                               common.tagListToDict(self._taglist))
                    assert common.tagListToDict(taglist) \
                        != common.tagListToDict(self._taglist)
                    self.tasks.append(checksum.CRC32Task(self._path))
                    self._fd, self._tmppath = tempfile.mkstemp(
                        dir=os.path.dirname(self._path), suffix=u'.morituri')
                    self.tasks.append(
                        TagWriteTask(self._path, self._tmppath, self._taglist))
                    self.tasks.append(checksum.CRC32Task(self._tmppath))
                    self.tasks.append(TagReadTask(self._tmppath))
            elif len(self.tasks) > 1 and taskk == self.tasks[4]:
                if common.tagListEquals(self.tasks[4].taglist, self._taglist):
                    self.debug('tags written successfully')
                    c1 = self.tasks[1].checksum
                    c2 = self.tasks[3].checksum
                    self.debug('comparing checksums %08x and %08x' % (c1, c2))
                    if c1 == c2:
                        # data is fine, so we can now move
                        # but first, copy original mode to our temporary file
                        shutil.copymode(self._path, self._tmppath)
                        self.debug('moving temporary file to %r' % self._path)
                        os.rename(self._tmppath, self._path)
                        self.changed = True
                    else:
                        # FIXME: don't raise TypeError
                        e = TypeError("Checksums failed")
                        self.setAndRaiseException(e)
                else:
                    self.debug('failed to update tags, only have %r',
                               common.tagListToDict(self.tasks[4].taglist))
                    self.debug(
                        'difference: %r',
                        common.tagListDifference(self.tasks[4].taglist,
                                                 self._taglist))
                    os.unlink(self._tmppath)
                    e = TypeError("Tags not written")
                    self.setAndRaiseException(e)

        task.MultiSeparateTask.stopped(self, taskk)
Beispiel #2
0
    def verifyTrack(self, runner, trackResult):
        # here to avoid import gst eating our options
        from morituri.common import checksum

        t = checksum.CRC32Task(trackResult.filename)

        runner.run(t)

        ret = trackResult.testcrc == t.checksum
        log.debug('program',
            'verifyTrack: track result crc %r, file crc %r, result %r',
            trackResult.testcrc, t.checksum, ret)
        return ret
Beispiel #3
0
def main(path, start, end):
    progress = taskgtk.GtkProgressRunner()
    progress.connect('stop', lambda _: gtk.main_quit())

    window = gtk.Window()
    window.add(progress)
    window.show_all()

    checksumtask = checksum.CRC32Task(path, start, end)
    progress.run(checksumtask)

    gtk.main()

    print "CRC: %08X" % checksumtask.checksum
Beispiel #4
0
    def do(self, args):
        try:
            fromPath = unicode(args[0])
        except IndexError:
            self.stdout.write('Please specify an input file.\n')
            return 3

        runner = task.SyncRunner()

        # here to avoid import gst eating our options
        from morituri.common import checksum
        checksumtask = checksum.CRC32Task(fromPath)

        runner.run(checksumtask)

        self.stdout.write('Checksum: %08x\n' % checksumtask.checksum)
Beispiel #5
0
    def do(self, args):
        if not args:
            self.stdout.write('Please specify one or more input files.\n')
            return 3

        runner = task.SyncRunner()
        # here to avoid import gst eating our options
        from morituri.common import checksum

        for arg in args:
            fromPath = unicode(arg)

            checksumtask = checksum.CRC32Task(fromPath)

            runner.run(checksumtask)

            self.stdout.write('Checksum: %08x\n' % checksumtask.checksum)
Beispiel #6
0
    def verifyTrack(self, runner, trackResult):
        # here to avoid import gst eating our options
        from morituri.common import checksum

        t = checksum.CRC32Task(trackResult.filename)

        try:
            runner.run(t)
        except task.TaskException, e:
            if isinstance(e.exception, common.MissingFrames):
                self.warning('missing frames for %r' % trackResult.filename)
                return False
            elif isinstance(e.exception, gstreamer.GstException):
                self.warning('GstException %r' % (e.exception, ))
                return False
            else:
                raise