def set_photoinputdir(self, value=None, log=True): if value != None: photoinputdir = os.path.normpath(os.path.expandvars(value)) else: if self.options.has_key('photoinputdir'): photoinputdir = os.path.expandvars( self.options['photoinputdir']) else: msg = _( "Directory with input photos not defined ... Nothing to do!" ) if log: self.__logger.error(msg) tip = _("Select a input photos directory to continue!") raise Error(msg, tip) if not isinstance(photoinputdir, unicode): try: photoinputdir = unicode(photoinputdir, PLATFORMENCODING) except: pass if not os.path.isdir(photoinputdir): msg = _("Photo input directory '%s' not found!.") % \ photoinputdir.encode(PLATFORMENCODING) self.__logger.error(msg) tip = _("Check if the selected directory exist.") raise Error(msg, tip) self._photoinputdir = photoinputdir self._set_photouri()
def set_utczoneminutes(self, value=None): utczoneminutes = timedelta_to_minutes(local_utc()) try: if value != None: utczoneminutes = int(value) else: utczoneminutes = int(self.options["utczoneminutes"]) except KeyError: self.__logger.debug( _("Value of 'utczoneminutes' not defined in the " "configuration file. Estimated local value is '%s'.") % utczoneminutes) except ValueError as valueerror: dgettext = {'error': str(valueerror), 'value': utczoneminutes} msg = _("Value of 'utczoneminutes' incorrect: %(error)s. " "Setting default value '%(value)s'.") % dgettext self.__logger.error(msg) tip = _( "Set the value of UTC Time Zone to continue. The value may " "be positive or negative.") raise Error(msg, tip, "ValueError") self._utczoneminutes = utczoneminutes # Time Zone correction self.tzdiff = datetime.timedelta(minutes=utczoneminutes) self.stzdiff = '+' if utczoneminutes < 0: utczoneminutes = -utczoneminutes self.stzdiff = '-' hours, remainder = divmod(utczoneminutes, 60) minutes, seconds = divmod(remainder, 60) self.stzdiff = self.stzdiff + "%.2d:%.2d" % (hours, minutes)
def set_kmltemplate(self, value, dirtemplates=u'templates'): filename = self.get_template(value, dirtemplates) if filename != None and os.path.isfile(filename): self._kmltemplate = filename else: msg = _("Main KML template file '%s' not found!.") self.__logger.error(msg % value.encode(PLATFORMENCODING)) tip = _( "Check if it is defined properly in the configuration file.") raise Error(msg, tip)
def set_gpxinputfile(self, value=None, log=True): if value != None: gpxinputfile = os.path.normpath(os.path.expandvars(value)) else: if self.options.has_key('gpxinputfile'): gpxinputfile = os.path.expandvars(self.options['gpxinputfile']) else: msg = _("GPX file not defined ... Nothing to do!") if log: self.__logger.error(msg) tip = _("Select a GPX input file to continue!") raise Error(msg, tip) if not isinstance(gpxinputfile, unicode): try: gpxinputfile = unicode(gpxinputfile, PLATFORMENCODING) except: pass if not os.path.isfile(gpxinputfile): msg = _("GPX input file '%s' not found!.") % \ gpxinputfile.encode(PLATFORMENCODING) self.__logger.error(msg) tip = _("Check the selected GPX input file to continue.") raise Error(msg, tip) self._gpxinputfile = gpxinputfile
def set_jpgzoom(self, value=None): try: if value != None: jpgzoom = float(value) else: jpgzoom = float(self.options["jpgzoom"]) except KeyError: jpgzoom = PhotoPlace_Cfg_main_jpgzoom self.__logger.debug( _("Value of 'jpgzoom' not defined " "in the configuration file. Setting default value '%s'.") % jpgzoom) except ValueError as valueerror: msg = _("Value of 'JPGZoom' incorrect: %s. ") % str(valueerror) self.__logger.error(msg) tip = _("Set a correct value of 'JPGZoom'.") raise Error(msg, tip, "ValueError") self._jpgzoom = jpgzoom
def set_jpgsize(self, size=None): try: if size != None: (width, height) = size w = int(width) h = int(height) else: (w, h) = tuple( int(s) for s in self.options["jpgsize"][1:-1].split(',')) except KeyError: (w, h) = PhotoPlace_Cfg_main_jpgsize self.__logger.debug( _("Value of 'jpgwidth' and/or 'jpgheight' not defined " "in the configuration file. Setting default value '%s'.") % str((w, h))) except (TypeError, ValueError) as error: msg = _("Value of 'JPGWidth' and/or 'JPGHeight' incorrect: %s. " ) % str(error) self.__logger.error(msg) tip = _("Set a correct value of 'JPGWidth' and/or 'JPGHeight'.") raise Error(msg, tip, error.__class__.__name__) self._jpgsize = (w, h)
def set_quality(self, value=None): quality = PhotoPlace_Cfg_main_quality try: if value != None: quality = int(value) else: quality = int(self.options["quality"]) if quality >= len(PhotoPlace_Cfg_quality) \ or quality < 0: raise ValueError("0 <= quality < %" % len(PhotoPlace_Cfg_quality)) except KeyError: quality = PhotoPlace_Cfg_main_quality self.__logger.debug( _("Value of 'quality' not defined " "in the configuration file. Setting default value '%s'.") % quality) except ValueError as valueerror: msg = _("Value of 'quality' incorrect: %s. ") % str(valueerror) self.__logger.error(msg) tip = _("Set a correct value of 'quality'.") raise Error(msg, tip, "ValueError") self._quality = quality self.quality = PhotoPlace_Cfg_quality[quality]
def set_outputfile(self, value=None, log=True): dgettext = {} if value != None: outputfile = os.path.expandvars(value) else: if not self.options.has_key('outputfile'): if self._photoinputdir: outputfile = self._photoinputdir + u".kmz" else: try: outputfile = self.options['photoinputdir'] + u".kmz" outputfile = os.path.expandvars(outputfile) except: msg = _("Output file not selected!") if log: self.__logger.error(msg) tip = _("Choose an output file to continue!") raise Error(msg, tip, e.__class__.__name__) else: outputfile = os.path.expandvars(self.options['outputfile']) self._outputfile = os.path.normpath(outputfile) if not isinstance(self._outputfile, unicode): try: self._outputfile = unicode(self._outputfile, PLATFORMENCODING) except: pass self.tmpdir = None self.outputkmz = None self.outputkml = None self.outputdir = os.path.dirname(self._outputfile) outputfile = os.path.basename(self._outputfile) (outputfilebase, outpufileext) = os.path.splitext(outputfile) dgettext['output_dir'] = self.outputdir.encode(PLATFORMENCODING) if outpufileext == '.kmz': try: deletedir = tempfile.mkdtemp(u"_tmp", PhotoPlace_name + u"-", self.outputdir) shutil.rmtree(deletedir) except Exception as e: self._outputfile = None self.outputdir = None dgettext['error'] = str(e) msg = _( "Cannot create temporary directory in '%(output_dir)s': %(error)s." ) msg = msg % dgettext self.__logger.error(msg) tip = _("Check output directory write permissions") raise Error(msg, tip, e.__class__.__name__) self.outputdir = deletedir self.tmpdir = deletedir self.outputkmz = self._outputfile self.outputkml = os.path.join(deletedir, outputfilebase + u".kml") elif outpufileext == '.kml': try: # Write test testfile = tempfile.NamedTemporaryFile(dir=self.outputdir, delete=True) except Exception as e: self._outputfile = None self.outputdir = None dgettext['error'] = str(e) msg = _("Cannot create files in '%(output_dir)s': %(error)s." ) % dgettext self.__logger.error(msg) tip = _("Check output directory write permissions") raise Error(msg, tip, e.__class__.__name__) finally: try: testfile.close() except: pass self.outputkml = self._outputfile else: self._outputfile = None self.outputdir = None msg = _( "Unknown extension of output file '%s'.") % self._outputfile tip = _("The extension of output file determines the program mode") self.__logger.error(msg) raise Error(msg, tip, "NameError") self._set_photouri()