예제 #1
0
    def save_selected(self, doc_file):
        doc = SK2_Presenter(self.app.appdata)
        origin = self.doc_presenter.model.doc_origin
        doc.methods.set_doc_origin(origin)
        doc_units = self.doc_presenter.model.doc_units
        doc.methods.set_doc_units(doc_units)
        page = doc.methods.get_page()
        page_format = deepcopy(self.active_page.page_format)
        doc.methods.set_page_format(page, page_format)
        objs = []
        for item in self.selection.objs:
            objs.append(item.copy())
        layer = doc.methods.get_layer(page)
        layer.childs = objs

        pd = ProgressDialog(_('Saving file...'), self.app.mw)
        try:
            saver = get_saver(doc_file)
            if saver is None:
                msg = _('Unknown file format is requested for saving <%s>')
                raise IOError(msg % doc_file)
            pd.run(saver, [doc, doc_file])
        except Exception:
            raise
        finally:
            pd.destroy()
            doc.close()
예제 #2
0
파일: presenter.py 프로젝트: Scrik/sk1-wx
	def save_selected(self, doc_file):
		doc = SK2_Presenter(self.app.appdata)
		origin = self.doc_presenter.model.doc_origin
		doc.methods.set_doc_origin(origin)
		doc_units = self.doc_presenter.model.doc_units
		doc.methods.set_doc_units(doc_units)
		page = doc.methods.get_page()
		page_format = deepcopy(self.active_page.page_format)
		doc.methods.set_page_format(page, page_format)
		objs = []
		for item in self.selection.objs:
			objs.append(item.copy())
		layer = doc.methods.get_layer(page)
		layer.childs = objs

		saver = get_saver(doc_file)
		if saver is None:
			doc.close()
			raise IOError(_('Unknown file format is requested for saving!'),
						 doc_file)

		pd = ProgressDialog(_('Saving file...'), self.app.mw)
		ret = pd.run(saver, [doc, doc_file], False)
		if ret:
			if not pd.error_info is None:
				pd.destroy()
				doc.close()
				raise IOError(*pd.error_info)
			pd.destroy()
			doc.close()
		else:
			pd.destroy()
			doc.close()
			raise IOError(_('Error while saving'), doc_file)
예제 #3
0
    def save_selected(self, doc_file):
        doc = SK2_Presenter(self.app.appdata)
        origin = self.doc_presenter.model.doc_origin
        doc.methods.set_doc_origin(origin)
        doc_units = self.doc_presenter.model.doc_units
        doc.methods.set_doc_units(doc_units)
        page = doc.methods.get_page()
        page_format = deepcopy(self.active_page.page_format)
        doc.methods.set_page_format(page, page_format)
        objs = []
        for item in self.selection.objs:
            objs.append(item.copy())
        layer = doc.methods.get_layer(page)
        layer.childs = objs

        saver = get_saver(doc_file)
        if saver is None:
            doc.close()
            raise IOError(_('Unknown file format is requested for saving!'),
                          doc_file)

        pd = ProgressDialog(_('Saving file...'), self.app.mw)
        ret = pd.run(saver, [doc, doc_file], False)
        if ret:
            if pd.error_info is not None:
                pd.destroy()
                doc.close()
                raise IOError(*pd.error_info)
            pd.destroy()
            doc.close()
        else:
            pd.destroy()
            doc.close()
            raise IOError(_('Error while saving'), doc_file)
예제 #4
0
    def save(self):
        try:
            if config.make_backup:
                if os.path.lexists(self.doc_file):
                    if os.path.lexists(self.doc_file + '~'):
                        os.remove(self.doc_file + '~')
                    os.rename(self.doc_file, self.doc_file + '~')
            saver = get_saver(self.doc_file, True)
            if saver is None:
                raise IOError(
                    _('Unknown file format is requested for saving!'),
                    self.doc_file)

            pd = ProgressDialog(_('Saving file...'), self.app.mw)
            ret = pd.run(saver, [self.doc_presenter, self.doc_file, False])
            if ret == gtk.RESPONSE_OK:
                if not pd.error_info is None:
                    pd.destroy()
                    raise IOError(*pd.error_info)
                pd.destroy()
            else:
                pd.destroy()
                raise IOError(_('Error while saving'), self.doc_file)

        except IOError:
            raise IOError(*sys.exc_info())
        self.reflect_saving()
예제 #5
0
    def do_cutting(self):
        cut_bbox = None
        ret = get_cut_dialog(self.app)
        if ret == gtk.RESPONSE_ACCEPT:
            #Collect all objects

            page = self.doc_presenter.methods.get_pages()[-1]
            objs = []
            for layer in page.childs:
                for obj in layer.childs:
                    objs.append(obj)

            if not objs:
                first = _('Cannot cutting in file')
                sec = _('There are no objects in document.')
                msg = ("%s '%s'.") % (first, config.output_file)
                msg_dialog(self.app.mw, self.app.appdata.app_name, msg, sec)
                return

            try:
                saver = get_saver('file.plt')

                if config.cut_bbox:
                    bbox = []
                    bbox += objs[0].cache_bbox
                    for obj in objs:
                        bbox = libgeom.sum_bbox(bbox, obj.cache_bbox)

                    layer = page.childs[-1]
                    cut_bbox = model.Rectangle(layer.config, layer, bbox)
                    layer.childs.append(cut_bbox)
                    cut_bbox.update()

                pd = ProgressDialog(_('Cutting...'), self.app.mw)
                ret = pd.run(saver, [
                    self.doc_presenter, config.output_file, True, {
                        'tolerance': config.tolerance
                    }
                ])
                if ret == gtk.RESPONSE_OK:
                    if not pd.error_info is None:
                        pd.destroy()
                        raise IOError(*pd.error_info)
                    pd.destroy()
                else:
                    pd.destroy()
                    raise IOError(_('Error while saving'), config.output_file)

            except IOError:
                details = sys.exc_info()[1].__str__() + sys.exc_info(
                )[2].__str__()
                first = _('Cannot cutting!')
                sec = _('Please check file name and write permissions')
                msg = ("%s '%s'.") % (first, config.output_file)

                msg_dialog(self.app.mw, self.app.appdata.app_name, msg, sec,
                           details)
        if not cut_bbox is None:
            self.doc_presenter.methods.delete_object(cut_bbox)
예제 #6
0
	def do_cutting(self):
		cut_bbox = None
		ret = get_cut_dialog(self.app)
		if ret == gtk.RESPONSE_ACCEPT:
			#Collect all objects

			page = self.doc_presenter.methods.get_pages()[-1]
			objs = []
			for layer in page.childs:
				for obj in layer.childs:
					objs.append(obj)

			if not objs:
				first = _('Cannot cutting in file')
				sec = _('There are no objects in document.')
				msg = ("%s '%s'.") % (first, config.output_file)
				msg_dialog(self.app.mw, self.app.appdata.app_name, msg, sec)
				return

			try:
				saver = get_saver('file.plt')

				if config.cut_bbox:
					bbox = []
					bbox += objs[0].cache_bbox
					for obj in objs:
						bbox = libgeom.sum_bbox(bbox, obj.cache_bbox)

					layer = page.childs[-1]
					cut_bbox = model.Rectangle(layer.config, layer, bbox)
					layer.childs.append(cut_bbox)
					cut_bbox.update()

				pd = ProgressDialog(_('Cutting...'), self.app.mw)
				ret = pd.run(saver, [self.doc_presenter,
									config.output_file,
									True,
									{'tolerance':config.tolerance}])
				if ret == gtk.RESPONSE_OK:
					if not pd.error_info is None:
						pd.destroy()
						raise IOError(*pd.error_info)
					pd.destroy()
				else:
					pd.destroy()
					raise IOError(_('Error while saving'), config.output_file)

			except IOError:
				details = sys.exc_info()[1].__str__() + sys.exc_info()[2].__str__()
				first = _('Cannot cutting!')
				sec = _('Please check file name and write permissions')
				msg = ("%s '%s'.") % (first, config.output_file)

				msg_dialog(self.app.mw, self.app.appdata.app_name, msg, sec, details)
		if not cut_bbox is None:
			self.doc_presenter.methods.delete_object(cut_bbox)
예제 #7
0
 def export_as(self, doc_file):
     pd = ProgressDialog(_('Exporting...'), self.app.mw)
     try:
         saver = get_saver(doc_file)
         if saver is None:
             msg = _('Unknown file format is requested for export <%s>')
             raise IOError(msg % doc_file)
         pd.run(saver, [self.doc_presenter, doc_file])
     except Exception:
         raise
     finally:
         pd.destroy()
예제 #8
0
 def save(self):
     pd = ProgressDialog(_('Saving file...'), self.app.mw)
     try:
         saver = get_saver(self.doc_file)
         if saver is None:
             msg = _('Unknown file format is requested for saving! <%s>')
             raise IOError(msg % self.doc_file)
         pd.run(saver, [self.doc_presenter, self.doc_file])
     except Exception:
         raise
     finally:
         pd.destroy()
     self.reflect_saving()
예제 #9
0
파일: presenter.py 프로젝트: Scrik/sk1-wx
	def export_as(self, doc_file):
		try:
			saver = get_saver(doc_file)
			if saver is None:
				raise IOError(_('Unknown file format is requested for export!'),
							 doc_file)

			pd = ProgressDialog(_('Exporting...'), self.app.mw)
			ret = pd.run(saver, [self.doc_presenter, doc_file], False)
			if ret:
				if not pd.error_info is None:
					pd.destroy()
					raise IOError(*pd.error_info)
				pd.destroy()
			else:
				pd.destroy()
				raise IOError(_('Error while exporting'), doc_file)

		except IOError:
			raise IOError(*sys.exc_info())
예제 #10
0
    def export_as(self, doc_file):
        try:
            saver = get_saver(doc_file)
            if saver is None:
                raise IOError(_('Unknown file format is requested for export!'),
                              doc_file)

            pd = ProgressDialog(_('Exporting...'), self.app.mw)
            ret = pd.run(saver, [self.doc_presenter, doc_file], False)
            if ret:
                if pd.error_info is not None:
                    pd.destroy()
                    raise IOError(*pd.error_info)
                pd.destroy()
            else:
                pd.destroy()
                raise IOError(_('Error while exporting'), doc_file)

        except IOError:
            raise IOError(*sys.exc_info())
예제 #11
0
파일: presenter.py 프로젝트: Scrik/sk1-wx
	def save(self):
		try:
			saver = get_saver(self.doc_file)
			if saver is None:
				raise IOError(_('Unknown file format is requested for saving!'),
							 self.doc_file)

			pd = ProgressDialog(_('Saving file...'), self.app.mw)
			ret = pd.run(saver, [self.doc_presenter, self.doc_file], False)
			if ret:
				if not pd.error_info is None:
					pd.destroy()
					raise IOError(*pd.error_info)
				pd.destroy()
			else:
				pd.destroy()
				raise IOError(_('Error while saving'), self.doc_file)

		except IOError:
			raise IOError(*sys.exc_info())
		self.reflect_saving()
예제 #12
0
    def save(self):
        try:
            saver = get_saver(self.doc_file)
            if saver is None:
                raise IOError(_('Unknown file format is requested for saving!'),
                              self.doc_file)

            pd = ProgressDialog(_('Saving file...'), self.app.mw)
            ret = pd.run(saver, [self.doc_presenter, self.doc_file], False)
            if ret:
                if pd.error_info is not None:
                    pd.destroy()
                    raise IOError(*pd.error_info)
                pd.destroy()
            else:
                pd.destroy()
                raise IOError(_('Error while saving'), self.doc_file)

        except IOError:
            raise IOError(*sys.exc_info())
        self.reflect_saving()
예제 #13
0
파일: application.py 프로젝트: Scrik/sk1-wx
	def run(self):

		if len(sys.argv) < 3 or '--help' in sys.argv:
			self.show_help()

		files = []
		options_list = []
		options = {}

		for item in sys.argv[1:]:
			if item[0] == '-':
				if item == '-verbose':
					events.connect(events.MESSAGES, self.verbose)
				else:
					options_list.append(item)
			else:
				files.append(item)

		if len(files) <> 2: self.show_help()
		if not os.path.lexists(files[0]):self.show_help()

		for item in options_list:
			result = item[1:].split('=')
			if not len(result) == 2:
				continue
			else:
				key, value = result
				if value == 'yes':value = True
				if value == 'no':value = False
				options[key] = value

		self.default_cms = cms.ColorManager()
		self.palettes = PaletteManager(self)

		print ''
		msg = _('Translation of') + ' "%s" ' % (files[0]) + _('into "%s"') % (files[1])
		events.emit(events.MESSAGES, msgconst.JOB, msg)

		saver = get_saver(files[1])
		if saver is None:
			msg = _("Output file format of '%s' is unsupported.") % (files[1])
			events.emit(events.MESSAGES, msgconst.ERROR, msg)

			msg = _('Translation is interrupted')
			events.emit(events.MESSAGES, msgconst.STOP, msg)

			sys.exit(1)

		loader = get_loader(files[0])
		if loader is None:
			msg = _("Input file format of '%s' is unsupported.") % (files[0])
			events.emit(events.MESSAGES, msgconst.ERROR, msg)

			msg = _('Translation is interrupted')
			events.emit(events.MESSAGES, msgconst.STOP, msg)

			sys.exit(1)

		try:
			doc = loader(self.appdata, files[0])
		except:
			msg = _("Error while loading '%s'") % (files[0])
			msg += _("The file may be corrupted or contains unknown file format.")
			events.emit(events.MESSAGES, msgconst.ERROR, msg)

			msg = _('Translation is interrupted')
			events.emit(events.MESSAGES, msgconst.STOP, msg)

			print '\n', sys.exc_info()[1], sys.exc_info()[2]
			sys.exit(1)

		if doc is not None:
			try:
				saver(doc, files[1])
			except:
				msg = _("Error while translation and saving '%s'") % (files[0])
				events.emit(events.MESSAGES, msgconst.ERROR, msg)

				msg = _('Translation is interrupted')
				events.emit(events.MESSAGES, msgconst.STOP, msg)

				print '\n', sys.exc_info()[1], sys.exc_info()[2]
				sys.exit(1)
		else:
			msg = _("Error while model creating for '%s'") % (files[0])
			events.emit(events.MESSAGES, msgconst.ERROR, msg)

			msg = _('Translation is interrupted')
			events.emit(events.MESSAGES, msgconst.STOP, msg)
			sys.exit(1)

		doc.close()
		events.emit(events.MESSAGES, msgconst.OK, _('Translation is successful'))
		print ''

		sys.exit(0)
예제 #14
0
    def run(self):
        if '--help' in sys.argv or '-help' in sys.argv or len(sys.argv) == 1:
            self.show_help()
        elif len(sys.argv) == 2:
            self.show_short_help(_('Not enough arguments!'))

        files = []
        options_list = []
        options = {}

        for item in sys.argv[1:]:
            if item.startswith('--'):
                options_list.append(item)
            elif item.startswith('-'):
                self.show_short_help(_('Unknown option "%s"') % item)
            else:
                files.append(item)

        if not files:
            self.show_short_help(_('File names are not provided!'))
        elif len(files) == 1:
            self.show_short_help(_('Destination file name is not provided!'))
        elif not os.path.lexists(files[0]):
            self.show_short_help(
                _('Source file "%s" is not found!') % files[0])

        for item in options_list:
            result = item[2:].split('=')
            if not len(result) == 2:
                options[result[0]] = True
            else:
                key, value = result
                value = value.replace('"', '').replace("'", '')
                if value.lower() == 'yes':
                    value = True
                if value.lower() == 'no':
                    value = False
                options[key] = value

        self.do_verbose = options.get('verbose', False)
        events.connect(events.MESSAGES, self.verbose)
        log_level = options.get('log', self.config.log_level)
        self.log_filepath = os.path.join(self.appdata.app_config_dir,
                                         'uc2.log')
        config_logging(self.log_filepath, log_level)

        self.default_cms = cms.ColorManager()
        self.palettes = PaletteManager(self)

        echo('')
        msg = _('Translation of "%s" into "%s"') % (files[0], files[1])
        events.emit(events.MESSAGES, msgconst.JOB, msg)

        saver_ids = uc2const.PALETTE_SAVERS
        saver_ids += uc2const.MODEL_SAVERS + uc2const.BITMAP_SAVERS
        sid = options.get('format', '').lower()
        if sid and sid in saver_ids:
            saver_id = sid
            saver = get_saver_by_id(saver_id)
        else:
            saver, saver_id = get_saver(files[1], return_id=True)
        if saver is None:
            msg = _('Output file format of "%s" is unsupported.') % files[1]
            events.emit(events.MESSAGES, msgconst.ERROR, msg)

            msg = _('Translation is interrupted')
            events.emit(events.MESSAGES, msgconst.STOP, msg)

        loader, loader_id = get_loader(files[0], return_id=True)
        if loader is None:
            msg = _('Input file format of "%s" is unsupported.') % files[0]
            events.emit(events.MESSAGES, msgconst.ERROR, msg)

            msg = _('Translation is interrupted')
            events.emit(events.MESSAGES, msgconst.STOP, msg)

        doc = None
        try:
            if loader_id in uc2const.PALETTE_LOADERS and \
                    saver_id in uc2const.PALETTE_SAVERS:
                doc = loader(self.appdata, files[0], convert=True)
            else:
                doc = loader(self.appdata, files[0])
        except Exception as e:
            msg = _('Error while loading "%s"') % files[0]
            msg += _(
                'The file may be corrupted or contains unknown file format.')
            events.emit(events.MESSAGES, msgconst.ERROR, msg)

            msg = _('Loading is interrupted')
            LOG.error('%s %s', msg, e)
            events.emit(events.MESSAGES, msgconst.STOP, msg)

        if doc is not None:
            try:
                if loader_id in uc2const.PALETTE_LOADERS and \
                        saver_id in uc2const.PALETTE_SAVERS:
                    saver(doc, files[1], translate=False, convert=True)
                else:
                    saver(doc, files[1])
            except Exception as e:
                msg = _('Error while translation and saving "%s"') % files[0]
                events.emit(events.MESSAGES, msgconst.ERROR, msg)

                msg = _('Translation is interrupted')
                LOG.error('%s %s', msg, e)
                events.emit(events.MESSAGES, msgconst.STOP, msg)
        else:
            msg = _('Error creating model for "%s"') % files[0]
            events.emit(events.MESSAGES, msgconst.ERROR, msg)

            msg = _('Translation is interrupted')
            events.emit(events.MESSAGES, msgconst.STOP, msg)

        doc.close()
        msg = _('Translation is successful')
        events.emit(events.MESSAGES, msgconst.OK, msg)
        echo('')

        sys.exit(0)
예제 #15
0
    def run(self):

        if len(sys.argv) < 3 or '--help' in sys.argv:
            self.show_help()

        files = []
        options_list = []
        options = {}

        for item in sys.argv[1:]:
            if item[0] == '-':
                if item == '-verbose':
                    events.connect(events.MESSAGES, self.verbose)
                else:
                    options_list.append(item)
            else:
                files.append(item)

        if len(files) <> 2: self.show_help()
        if not os.path.lexists(files[0]): self.show_help()

        for item in options_list:
            result = item[1:].split('=')
            if not len(result) == 2:
                continue
            else:
                key, value = result
                if value == 'yes': value = True
                if value == 'no': value = False
                options[key] = value

        self.default_cms = cms.ColorManager()
        self.palettes = PaletteManager(self)

        print ''
        msg = _('Translation of') + ' "%s" ' % (files[0]) + _('into "%s"') % (
            files[1])
        events.emit(events.MESSAGES, msgconst.JOB, msg)

        saver = get_saver(files[1])
        if saver is None:
            msg = _("Output file format of '%s' is unsupported.") % (files[1])
            events.emit(events.MESSAGES, msgconst.ERROR, msg)

            msg = _('Translation is interrupted')
            events.emit(events.MESSAGES, msgconst.STOP, msg)

            sys.exit(1)

        loader = get_loader(files[0])
        if loader is None:
            msg = _("Input file format of '%s' is unsupported.") % (files[0])
            events.emit(events.MESSAGES, msgconst.ERROR, msg)

            msg = _('Translation is interrupted')
            events.emit(events.MESSAGES, msgconst.STOP, msg)

            sys.exit(1)

        try:
            doc = loader(self.appdata, files[0])
        except:
            msg = _("Error while loading '%s'") % (files[0])
            msg += _(
                "The file may be corrupted or contains unknown file format.")
            events.emit(events.MESSAGES, msgconst.ERROR, msg)

            msg = _('Translation is interrupted')
            events.emit(events.MESSAGES, msgconst.STOP, msg)

            print '\n', sys.exc_info()[1], sys.exc_info()[2]
            sys.exit(1)

        if doc is not None:
            try:
                saver(doc, files[1])
            except:
                msg = _("Error while translation and saving '%s'") % (files[0])
                events.emit(events.MESSAGES, msgconst.ERROR, msg)

                msg = _('Translation is interrupted')
                events.emit(events.MESSAGES, msgconst.STOP, msg)

                print '\n', sys.exc_info()[1], sys.exc_info()[2]
                sys.exit(1)
        else:
            msg = _("Error while model creating for '%s'") % (files[0])
            events.emit(events.MESSAGES, msgconst.ERROR, msg)

            msg = _('Translation is interrupted')
            events.emit(events.MESSAGES, msgconst.STOP, msg)
            sys.exit(1)

        doc.close()
        events.emit(events.MESSAGES, msgconst.OK,
                    _('Translation is successful'))
        print ''

        sys.exit(0)
예제 #16
0
def convert(appdata, files, options):
    dry_run = bool(options.get('dry-run'))
    normalize_options(options)

    msg = 'Translation of "%s" into "%s"' % (files[0], files[1])
    events.emit(events.MESSAGES, msgconst.JOB, msg)

    # Define saver -----------------------------------------
    sid = options.get('format', '').lower()
    if sid and sid in SAVER_IDS:
        saver_id = sid
        saver = get_saver_by_id(saver_id)
    else:
        saver, saver_id = get_saver(files[1], return_id=True)
    if saver is None:
        msg = 'Output file format of "%s" is unsupported.' % files[1]
        events.emit(events.MESSAGES, msgconst.ERROR, msg)

        msg2 = 'Translation is interrupted'
        events.emit(events.MESSAGES, msgconst.STOP, msg2)
        raise Exception(msg)

    # Define loader -----------------------------------------
    loader, loader_id = get_loader(files[0], return_id=True)
    if loader is None:
        msg = 'Input file format of "%s" is unsupported.' % files[0]
        events.emit(events.MESSAGES, msgconst.ERROR, msg)

        msg2 = 'Translation is interrupted'
        events.emit(events.MESSAGES, msgconst.STOP, msg2)
        raise Exception(msg)

    if dry_run:
        return

    # File loading -----------------------------------------
    doc = None
    try:
        if loader_id in uc2const.PALETTE_LOADERS and \
                saver_id in uc2const.PALETTE_SAVERS:
            doc = loader(appdata, files[0], convert=True, **options)
        else:
            doc = loader(appdata, files[0], **options)
    except Exception:
        msg = 'Error while loading "%s"' % files[0]
        msg += 'The file may be corrupted or contains unknown file format.'
        events.emit(events.MESSAGES, msgconst.ERROR, msg)

        LOG.exception(msg)
        msg = 'Loading is interrupted'
        events.emit(events.MESSAGES, msgconst.STOP, msg)
        raise

    # File saving -----------------------------------------
    if doc is not None:
        try:
            if loader_id in uc2const.PALETTE_LOADERS and \
                    saver_id in uc2const.PALETTE_SAVERS:
                saver(doc, files[1], translate=False, convert=True, **options)
            else:
                saver(doc, files[1], **options)
        except Exception:
            msg = 'Error while translation and saving "%s"' % files[0]
            events.emit(events.MESSAGES, msgconst.ERROR, msg)

            LOG.exception(msg)
            msg2 = 'Translation is interrupted'
            events.emit(events.MESSAGES, msgconst.STOP, msg2)
            raise
    else:
        msg = 'Error creating model for "%s"' % files[0]
        events.emit(events.MESSAGES, msgconst.ERROR, msg)

        msg2 = 'Translation is interrupted'
        events.emit(events.MESSAGES, msgconst.STOP, msg2)
        raise Exception(msg)

    doc.close()
    msg = 'Translation is successful'
    events.emit(events.MESSAGES, msgconst.OK, msg)
예제 #17
0
def convert(appdata, files, options):
    dry_run = bool(options.get('dry-run'))
    normalize_options(options)

    msg = 'Translation of "%s" into "%s"' % (files[0], files[1])
    events.emit(events.MESSAGES, msgconst.JOB, msg)

    # Define saver -----------------------------------------
    sid = options.get('format', '').lower()
    if sid and sid in const.SAVER_IDS:
        saver_id = sid
        saver = get_saver_by_id(saver_id)
    else:
        saver, saver_id = get_saver(files[1], return_id=True)
    if saver is None:
        msg = 'Output file format of "%s" is unsupported.' % files[1]
        events.emit(events.MESSAGES, msgconst.ERROR, msg)

        msg2 = 'Translation is interrupted'
        events.emit(events.MESSAGES, msgconst.STOP, msg2)
        raise Exception(msg)

    # Define loader -----------------------------------------
    loader, loader_id = get_loader(files[0], return_id=True)
    if loader is None:
        msg = 'Input file format of "%s" is unsupported.' % files[0]
        events.emit(events.MESSAGES, msgconst.ERROR, msg)

        msg2 = 'Translation is interrupted'
        events.emit(events.MESSAGES, msgconst.STOP, msg2)
        raise Exception(msg)

    if dry_run:
        return

    # File loading -----------------------------------------
    try:
        if loader_id in uc2const.PALETTE_LOADERS and \
                saver_id in uc2const.PALETTE_SAVERS:
            doc = loader(appdata, files[0], convert=True, **options)
        else:
            doc = loader(appdata, files[0], **options)
    except Exception:
        msg = 'Error while loading "%s"' % files[0]
        msg += 'The file may be corrupted or contains unknown file format.'
        events.emit(events.MESSAGES, msgconst.ERROR, msg)

        LOG.exception(msg)
        msg = 'Loading is interrupted'
        events.emit(events.MESSAGES, msgconst.STOP, msg)
        raise

    # Model transforming ----------------------------------
    if doc and doc.cid == uc2const.SK2:
        for action in CLI_ACTIONS:
            if action == const.FIT_PAGE_TO_IMAGE:
                msg = 'ACTION: Fit page to image'
                LOG.info(msg)
                events.emit(events.MESSAGES, msgconst.JOB, msg)
                doc.methods.fit_pages_to_image()
            elif action == const.FIT_TO_PAGE:
                msg = 'ACTION: Fit drawing to page'
                LOG.info(msg)
                events.emit(events.MESSAGES, msgconst.JOB, msg)
                doc.methods.fit_to_pages()

    # File saving -----------------------------------------
    if doc is not None:
        try:
            if loader_id in uc2const.PALETTE_LOADERS and \
                    saver_id in uc2const.PALETTE_SAVERS:
                saver(doc, files[1], translate=False, convert=True, **options)
            else:
                saver(doc, files[1], **options)
        except Exception:
            msg = 'Error while translation and saving "%s"' % files[0]
            events.emit(events.MESSAGES, msgconst.ERROR, msg)

            LOG.exception(msg)
            msg2 = 'Translation is interrupted'
            events.emit(events.MESSAGES, msgconst.STOP, msg2)
            raise
    else:
        msg = 'Error creating model for "%s"' % files[0]
        events.emit(events.MESSAGES, msgconst.ERROR, msg)

        msg2 = 'Translation is interrupted'
        events.emit(events.MESSAGES, msgconst.STOP, msg2)
        raise Exception(msg)

    doc.close()
    msg = 'Translation is successful'
    events.emit(events.MESSAGES, msgconst.OK, msg)