예제 #1
0
    def generate(self, options):
        """makes sure all files exist in other album, and generates if
           necessary."""
        source_file = self.photo.image_path
        try:
            do_export = self._check_need_to_export(source_file, options)

            # if we use links, we update the IPTC data in the original file
            do_iptc = (options.iptc == 1 and do_export) or options.iptc == 2
            if do_iptc and options.link:
                if self.check_iptc_data(source_file, options):
                    do_export = True

            exists = True  # True if the file exists or was updated.
            if do_export:
                exists = imageutils.copy_or_link_file(
                    source_file, self.export_file, options.dryrun,
                    options.link, options.size, options.update)
            else:
                _logger.debug(u'%s up to date.', self.export_file)

            # if we copy, we update the IPTC data in the copied file
            if exists and do_iptc and not options.link:
                self.check_iptc_data(self.export_file, options)

            if (options.originals and self.photo.originalpath
                    and not self.photo.rotation_is_only_edit):
                self._generate_original(options)
        except (OSError, MacOS.Error) as ose:
            su.perr("Failed to export %s: %s" % (source_file, ose))
예제 #2
0
    def generate(self, options):
        """makes sure all files exist in other album, and generates if
           necessary."""
        try:
            source_file = su.resolve_alias(self.photo.image_path)
            do_export = self._check_need_to_export(source_file, options)

            # if we use links, we update the IPTC data in the original file
            do_iptc = (options.iptc == 1 and do_export) or options.iptc == 2
            if do_iptc and options.link:
                if self.check_iptc_data(source_file, options, file_updated=do_export):
                    do_export = True

            exists = True  # True if the file exists or was updated.
            if do_export:
                exists = imageutils.copy_or_link_file(source_file,
                                                      self.export_file,
                                                      options.dryrun,
                                                      options.link,
                                                      self.size,
                                                      options)
            else:
                _logger.debug(u'%s up to date.', self.export_file)

            # if we copy, we update the IPTC data in the copied file
            if exists and do_iptc and not options.link:
                self.check_iptc_data(self.export_file, options, file_updated=do_export)

            if (options.originals and self.photo.originalpath and
                not self.photo.rotation_is_only_edit):
                self._generate_original(options)
        except (OSError, MacOS.Error) as ose:
            su.perr(u"Failed to export %s to %s: %s" % (self.photo.image_path, self.export_file,
                                                        ose))
    def _generate_original(self, options):
        """Exports the original file."""
        do_original_export = False
        export_dir = os.path.split(self.original_export_file)[0]
        if not os.path.exists(export_dir):
            su.pout("Creating folder " + export_dir)
            if not options.dryrun:
                os.mkdir(export_dir)
        original_source_file = su.resolve_alias(self.photo.originalpath)
        if os.path.exists(self.original_export_file):
            # In link mode, check the inode.
            if options.link:
                export_stat = os.stat(self.original_export_file)
                source_stat = os.stat(original_source_file)
                if export_stat.st_ino != source_stat.st_ino:
                    su.pout('Changed:  %s: inodes don\'t match: %d vs. %d' %
                            (self.original_export_file, export_stat.st_ino,
                             source_stat.st_ino))
                    do_original_export = True
            if (os.path.getmtime(self.original_export_file) + _MTIME_FUDGE <
                    os.path.getmtime(original_source_file)):
                su.pout(
                    'Changed:  %s: newer version is available: %s vs. %s' %
                    (self.original_export_file,
                     time.ctime(os.path.getmtime(self.original_export_file)),
                     time.ctime(os.path.getmtime(original_source_file))))
                do_original_export = True
            elif not self.size:
                source_size = os.path.getsize(original_source_file)
                export_size = os.path.getsize(self.original_export_file)
                diff = abs(source_size - export_size)
                if diff > _MAX_FILE_DIFF or (diff > 0 and options.link):
                    su.pout(
                        u'Changed:  %s: file size: %d vs. %d' %
                        (self.original_export_file, export_size, source_size))
                    do_original_export = True
        else:
            do_original_export = True

        do_iptc = (options.iptc == 1
                   and do_original_export) or options.iptc == 2
        if do_iptc and (options.link or options.iptc_masters):
            if self.check_iptc_data(original_source_file,
                                    options,
                                    is_original=True,
                                    file_updated=do_original_export):
                do_original_export = True
        exists = True  # True if the file exists or was updated.
        if do_original_export:
            exists = imageutils.copy_or_link_file(original_source_file,
                                                  self.original_export_file,
                                                  options.dryrun, options.link,
                                                  self.size, options)
        else:
            _logger.debug(u'%s up to date.', self.original_export_file)
        if exists and do_iptc and not options.link:
            self.check_iptc_data(self.original_export_file,
                                 options,
                                 is_original=True,
                                 file_updated=do_original_export)
예제 #4
0
    def _generate_original(self, options):
        """Exports the original file."""
        do_original_export = False
        export_dir = os.path.split(self.original_export_file)[0]
        if not os.path.exists(export_dir):
            su.pout("Creating folder " + export_dir)
            if not options.dryrun:
                os.mkdir(export_dir)
        original_source_file = su.resolve_alias(self.photo.originalpath)
        if os.path.exists(self.original_export_file):
            # In link mode, check the inode.
            if options.link:
                export_stat = os.stat(self.original_export_file)
                source_stat = os.stat(original_source_file)
                if export_stat.st_ino != source_stat.st_ino:
                    su.pout('Changed:  %s: inodes don\'t match: %d vs. %d' %
                            (self.original_export_file, export_stat.st_ino, source_stat.st_ino))
                    do_original_export = True
            if (os.path.getmtime(self.original_export_file) + _MTIME_FUDGE <
                os.path.getmtime(original_source_file)):
                su.pout('Changed:  %s: newer version is available: %s vs. %s' %
                        (self.original_export_file,
                         time.ctime(os.path.getmtime(
                             self.original_export_file)),
                         time.ctime(os.path.getmtime(original_source_file))))
                do_original_export = True
            elif not self.size:
                source_size = os.path.getsize(original_source_file)
                export_size = os.path.getsize(self.original_export_file)
                diff = abs(source_size - export_size)
                if diff > _MAX_FILE_DIFF or (diff > 0 and options.link):
                    su.pout(u'Changed:  %s: file size: %d vs. %d' %
                            (self.original_export_file,
                             export_size, source_size))
                    do_original_export = True
        else:
            do_original_export = True

        do_iptc = (options.iptc == 1 and
                   do_original_export) or options.iptc == 2
        if do_iptc and (options.link or options.iptc_masters):
            if self.check_iptc_data(original_source_file, options,
                                    is_original=True, file_updated=do_original_export):
                do_original_export = True
        exists = True  # True if the file exists or was updated.
        if do_original_export:
            exists = imageutils.copy_or_link_file(original_source_file,
                                                  self.original_export_file,
                                                  options.dryrun,
                                                  options.link,
                                                  self.size,
                                                  options)
        else:
            _logger.debug(u'%s up to date.', self.original_export_file)
        if exists and do_iptc and not options.link:
            self.check_iptc_data(self.original_export_file, options,
                                 is_original=True, file_updated=do_original_export)