def add(cmdline): import sys from sdaps.add import add_image survey = model.survey.Survey.load(cmdline['project']) for file in cmdline['images']: print _('Processing %s') % file add_image(survey, file, cmdline['duplex'], cmdline['force'], cmdline['copy']) print _('Done') survey.save()
def add(cmdline): import sys from sdaps.add import add_image, check_image from sdaps import image error = False survey = model.survey.Survey.load(cmdline['project']) filelist = [] deletelist = [] if not cmdline['convert']: for file in cmdline['images']: filelist.append(file) if not check_image(survey, file, cmdline['duplex'], cmdline['force'], message=True): error=True if error: return else: if not cmdline['copy']: log.error(_("The --no-copy option is not compatible with --convert!")) return 1 try: from sdaps.convert import convert_images except: log.error("Need to convert the images to monochrome TIFF, however the conversion module cannot be imported. You are likely missing the OpenCV dependency.") return 1 print(_("Converting input files into a single temporary file.")) tmp = tempfile.mktemp(suffix='.tif', prefix='sdaps-convert-') deletelist.append(tmp) filelist.append(tmp) # Run conversion # TODO: Allow 3D transformation here! try: convert_images(cmdline['images'], tmp, survey.defs.paper_width, survey.defs.paper_height, cmdline['transform']) if not check_image(survey, tmp, cmdline['duplex'], cmdline['force']): log.error(_("The page count of the created temporary file does not work with this survey.")) raise AssertionError() except Exception as e: log.error(str(e)) log.error(_("Running the conversion failed.")) error = True raise if not error: for file in filelist: print(_('Processing %s') % file) add_image(survey, file, cmdline['duplex'], cmdline['force'], cmdline['copy']) print(_('Done')) for file in deletelist: try: os.unlink(file) except OSError: pass if error: return 1 else: survey.save() return 0
def add(cmdline): import sys from sdaps.add import add_image, check_image from sdaps import image error = False survey = model.survey.Survey.load(cmdline['project']) filelist = [] deletelist = [] if not cmdline['convert']: for file in cmdline['images']: filelist.append(file) if not check_image(survey, file, cmdline['duplex'], cmdline['force'], message=True): error = True if error: return else: if not cmdline['copy']: log.error( _("The --no-copy option is not compatible with --convert!")) return 1 try: from sdaps.convert import convert_images except: log.error( "Need to convert the images to monochrome TIFF, however the conversion module cannot be imported. You are likely missing the OpenCV dependency." ) return 1 print(_("Converting input files into a single temporary file.")) tmp = tempfile.mktemp(suffix='.tif', prefix='sdaps-convert-') deletelist.append(tmp) filelist.append(tmp) # Run conversion # TODO: Allow 3D transformation here! try: convert_images(cmdline['images'], tmp, survey.defs.paper_width, survey.defs.paper_height, cmdline['transform']) if not check_image(survey, tmp, cmdline['duplex'], cmdline['force']): log.error( _("The page count of the created temporary file does not work with this survey." )) raise AssertionError() except Exception as e: log.error(str(e)) log.error(_("Running the conversion failed.")) error = True raise if not error: for file in filelist: print(_('Processing %s') % file) add_image(survey, file, cmdline['duplex'], cmdline['force'], cmdline['copy']) print(_('Done')) for file in deletelist: try: os.unlink(file) except OSError: pass if error: return 1 else: survey.save() return 0
if not check_image(survey, tmp, cmdline['duplex'], cmdline['force']): log.error( _("The page count of the created temporary file does not work with this survey." )) raise AssertionError() except Exception, e: log.error(str(e)) log.error(_("Running the conversion failed.")) error = True if not error: for file in filelist: print _('Processing %s') % file add_image(survey, file, cmdline['duplex'], cmdline['force'], cmdline['copy']) print _('Done') for file in deletelist: os.unlink(file) if error: return 1 else: survey.save() return 0