Exemplo n.º 1
0
    def _writeFile(self, filePath, newFilePath=None):
        if newFilePath is None:
            newFilePath = filePath

        data = self._subtitleData.data(filePath)
        converter = SubConverter()
        content = converter.convert(data.outputFormat, data.subtitles)

        if File.exists(newFilePath):
            file_ = File(newFilePath)
            file_.overwrite(content, data.outputEncoding)
        else:
            File.write(newFilePath, content, data.outputEncoding)
        self._subtitleData.setCleanState(filePath)
        self.__updateMenuItemsState()
Exemplo n.º 2
0
    def writeSubtitles(self, convertedSubtitles, filePath, encoding):
        try:
            file_ = File(filePath)
        except:
            # File doesn't exist, we can safely write to it
            File.write(filePath, convertedSubtitles, encoding)
            log.info(_("File %s saved.") % filePath)
        else:
            # A little hack to ensure that translator won't make a mistake
            choices = { 'yes': _('y'), 'no': _('n'), 'quit': _('q'), 'backup': _('b') }
            choice = ''

            if self._args.force:
                choice = choices["yes"]
            while(choice not in choices.values()):
                vals = {
                    "file": filePath, "yes": choices["yes"], "no": choices['no'],
                    "bck": choices['backup'], "quit": choices["quit"]
                }

                choice = input(
                    _("File '%(file)s' exists. Overwrite? [%(yes)s/%(no)s/%(bck)s/%(quit)s]") % 
                    vals)

            if choice == choices['backup']:
                backupFilePath = file_.backup()
                log.info(_("Backup: %s") % backupFilePath)
                log.info(_("Overwriting %s") % filePath)
                file_.overwrite(convertedSubtitles, encoding)
            elif choice == choices['no']:
                log.info(_("Skipping %s") % filePath)
                return
            elif choice == choices['yes']:
                log.info(_("Overwriting %s") % filePath)
                file_.overwrite(convertedSubtitles, encoding)
            elif choice == choices['quit']:
                log.info(_("Quitting converting work."))
                sys.exit(0)