Beispiel #1
0
    def __read(self):
        t = _Command.getExif(self.file)

        self.comment = t["jpegcomment"]
        self.filedate = t["filedate"]
        self.resolution = t["resolution"]
        self.exifdate = t["exifdate"]
        self.isflash = t["isflash"]
        self.readonly = not os.access(self.file, os.W_OK)

        self.__iptc = IPTCInfo(self.file, True)

        self.__iptc.keywords.sort()
Beispiel #2
0
   def copyInfoTo(self,file2):
      """ copy exif/iptc to "file2"
          and redate filesystem date of file2 according exif
      """
      assert type(file2)==unicode

      #copy iptc tags
      i=IPTCInfo(file2,True)
      i.keywords=[]
      i.keywords+=self.__iptc.keywords
      i.save()

      # copy exif (exif, thumb + jpegcomment), and redate
      _Command.copyExif(self.file,file2)

      # and rebuild i-thumb (should set good resolution in exif)
      ds = DateSave(file2)
      _Command.rebuildExifThumb(file2)
      ds.touch()
Beispiel #3
0
    def copyInfoTo(self, file2):
        """ copy exif/iptc to "file2"
            and redate filesystem date of file2 according exif
        """
        assert type(file2) == unicode

        # copy iptc tags
        i = IPTCInfo(file2, True)
        i.keywords = []
        i.keywords += self.__iptc.keywords
        i.save()

        # copy exif (exif, thumb + jpegcomment), and redate
        _Command.copyExif(self.file, file2)

        # and rebuild i-thumb (should set good resolution in exif)
        ds = DateSave(file2)
        _Command.rebuildExifThumb(file2)
        ds.touch()
Beispiel #4
0
   def __read(self):
      t = _Command.getExif(self.file)

      self.comment      = t["jpegcomment"]
      self.filedate     = t["filedate"]
      self.resolution   = t["resolution"]
      self.exifdate     = t["exifdate"]
      self.isflash      = t["isflash"]
      self.readonly     = not os.access( self.file, os.W_OK)

      self.__iptc = IPTCInfo(self.file,True)

      self.__iptc.keywords.sort()
Beispiel #5
0
class PhotoCmd(object):
# ============================================================================================
   """ Manipulate photos(jpg)
   """
   @staticmethod
   def normalizeName(file):
        """
        normalize name (only real exif pictures !!!!)
        """
        assert type(file)==unicode

        return _Command.prepareFile(file,needRename=True,needAutoRot=False)

   @staticmethod
   def prepareFile(file,needRename,needAutoRot):
        """
        prepare file, rotating/autorotating according exif tags
        (same things as normalizename + autorot, in one action)
        only called at IMPORT/REFRESH albums
        """
        assert type(file)==unicode

        return _Command.prepareFile(file,needRename,needAutoRot)


   @staticmethod
   def setNormalizeNameFormat(format):
        """ set format for normalized files (see prepareFile())"""
        _Command.format = format


   def __init__(self,file):
      assert type(file)==unicode,"ERROR:"+str(type(file))
      assert os.path.isfile(file)



      self.file = file
      self.__read()

      # save filesystem mtime/atime
      self.ds = DateSave(self.file)

   def __getTags(self):
       return self.__iptc.keywords
   tags = property(__getTags)

   def __read(self):
      t = _Command.getExif(self.file)

      self.comment      = t["jpegcomment"]
      self.filedate     = t["filedate"]
      self.resolution   = t["resolution"]
      self.exifdate     = t["exifdate"]
      self.isflash      = t["isflash"]
      self.readonly     = not os.access( self.file, os.W_OK)

      self.__iptc = IPTCInfo(self.file,True)

      self.__iptc.keywords.sort()


   def sub(self,t):
      assert type(t)==unicode
      if t in self.__iptc.keywords:
         self.__iptc.keywords.remove(t)
         return self._write()
      else:
         return False

   def add(self,t):
      assert type(t)==unicode
      if t in self.__iptc.keywords:
         return False
      else:
         self.__iptc.keywords.append(t)
         return self._write()

   def addTags(self,tags): # *new*
        """ add a list of tags to the file, return False if it can't """
        isModified = False
        for t in tags:
            assert type(t)==unicode
            if t not in self.__iptc.keywords:
                isModified = True
                self.__iptc.keywords.append(t)

        if isModified:
            return self._write()
        return True

   def _setCommentAndTags(self,c,t): # **special convert**
        assert type(c)==unicode,str(type(c))+" : "+c
        for i in t:
            assert type(i)==unicode
            pass
        self.comment = c
        self.__iptc.keywords = t
        return self._write()


   def subTags(self,tags): # *new*
        """ sub a list of tags to the file, return False if it can't """
        isModified = False
        for t in tags:
            assert type(t)==unicode
            if t in self.__iptc.keywords:
                isModified = True
                self.__iptc.keywords.remove(t)

        if isModified:
            return self._write()
        return True

   def clear(self):
      self.__iptc.keywords = []
      return self._write()

   def addComment(self,c):
      assert type(c)==unicode
      self.comment = c
      return self._write()


   def _write(self):
      """ writes tags/comment (sub(),add(),addTags(),subTags(),clear(),addComment())
          return True if tags/comment were written, false if not
      """

      if self.__iptc.save():
         _Command.setJpegComment(self.file,self.comment)
         self.ds.touch()    # retouch filesystem mtime/atime
         return True
      else:
         return False

   def redate(self,w,d,h,m,s ):
        """
        redate jpeg file from offset : weeks, days, hours, minutes,seconds
        if exif : redate internal date and fs dates (jhead -ft)
        if not : redate file dates (atime/mtime)
        """
        if self.exifdate:
            # redate internal exif date
            # and redate "filesystem dates" with "jhead -ft" !!!
            newDate=cd2d(self.exifdate)
            newDate+=timedelta(weeks=w, days=d,hours=h,minutes=m,seconds=s)

            _Command.setDate(self.file,newDate )
        else:
            # ONLY redate "filesystem dates"
            self.ds.redate(w,d,h,m,s )
        self.__read() # read again, exifdate has changed

   def rotate(self,sens):
      _Command.rotate(self.file,sens)
      self.ds.touch()    # retouch filesystem mtime/atime
      self.__read() # read again, because resolution has changed

   def rebuildExifTB(self):
      _Command.rebuildExifThumb(self.file)
      self.ds.touch()    # retouch filesystem mtime/atime
      self.__read() # read again, perhaps something has changed

   def getExifInfo(self):
      """ return the result of jhead on this file """
      return _Command.getExifInfo(self.file)

   def destroyInfo(self):
      """ destroy info (exif/iptc) of the file
          but keep filesystem date

          *IMPORTANT* : it doesn't kill IPTC-block, only KEYWORDS !
      """
      _Command.removeExif(self.file)
      self.clear()      # clear IPTC tags
      self.ds.touch()    # retouch filesystem mtime/atime
      self.__read() # read again, perhaps something has changed

   def copyInfoTo(self,file2):
      """ copy exif/iptc to "file2"
          and redate filesystem date of file2 according exif
      """
      assert type(file2)==unicode

      #copy iptc tags
      i=IPTCInfo(file2,True)
      i.keywords=[]
      i.keywords+=self.__iptc.keywords
      i.save()

      # copy exif (exif, thumb + jpegcomment), and redate
      _Command.copyExif(self.file,file2)

      # and rebuild i-thumb (should set good resolution in exif)
      ds = DateSave(file2)
      _Command.rebuildExifThumb(file2)
      ds.touch()
Beispiel #6
0
class PhotoCmd(object):
    # ===========================================================================
    """ Manipulate photos(jpg)
    """
    @staticmethod
    def normalizeName(file):
        """
        normalize name (only real exif pictures !!!!)
        """
        assert type(file) == unicode

        return _Command.prepareFile(file, needRename=True, needAutoRot=False)

    @staticmethod
    def prepareFile(file, needRename, needAutoRot):
        """
        prepare file, rotating/autorotating according exif tags
        (same things as normalizename + autorot, in one action)
        only called at IMPORT/REFRESH albums
        """
        assert type(file) == unicode

        return _Command.prepareFile(file, needRename, needAutoRot)

    @staticmethod
    def setNormalizeNameFormat(format):
        """ set format for normalized files (see prepareFile())"""
        _Command.format = format

    def __init__(self, file):
        assert type(file) == unicode, "ERROR:" + str(type(file))
        assert os.path.isfile(file)

        self.file = file
        self.__read()

        # save filesystem mtime/atime
        self.ds = DateSave(self.file)

    def __getTags(self):
        return self.__iptc.keywords

    tags = property(__getTags)

    def __read(self):
        t = _Command.getExif(self.file)

        self.comment = t["jpegcomment"]
        self.filedate = t["filedate"]
        self.resolution = t["resolution"]
        self.exifdate = t["exifdate"]
        self.isflash = t["isflash"]
        self.readonly = not os.access(self.file, os.W_OK)

        self.__iptc = IPTCInfo(self.file, True)

        self.__iptc.keywords.sort()

    def sub(self, t):
        assert type(t) == unicode
        if t in self.__iptc.keywords:
            self.__iptc.keywords.remove(t)
            return self._write()
        else:
            return False

    def add(self, t):
        assert type(t) == unicode
        if t in self.__iptc.keywords:
            return False
        else:
            self.__iptc.keywords.append(t)
            return self._write()

    def addTags(self, tags):  # *new*
        """ add a list of tags to the file, return False if it can't """
        isModified = False
        for t in tags:
            assert type(t) == unicode
            if t not in self.__iptc.keywords:
                isModified = True
                self.__iptc.keywords.append(t)

        if isModified:
            return self._write()
        return True

    def _setCommentAndTags(self, c, t):  # **special convert**
        assert type(c) == unicode, str(type(c)) + " : " + c
        for i in t:
            assert type(i) == unicode
            pass
        self.comment = c
        self.__iptc.keywords = t
        return self._write()

    def subTags(self, tags):  # *new*
        """ sub a list of tags to the file, return False if it can't """
        isModified = False
        for t in tags:
            assert type(t) == unicode
            if t in self.__iptc.keywords:
                isModified = True
                self.__iptc.keywords.remove(t)

        if isModified:
            return self._write()
        return True

    def clear(self):
        self.__iptc.keywords = []
        return self._write()

    def addComment(self, c):
        assert type(c) == unicode
        self.comment = c
        return self._write()

    def _write(self):
        """ writes tags/comment (sub(),add(),addTags(),subTags(),clear(),
                                 addComment())
            return True if tags/comment were written, false if not
        """

        if self.__iptc.save():
            _Command.setJpegComment(self.file, self.comment)
            self.ds.touch()  # retouch filesystem mtime/atime
            return True
        else:
            return False

    def redate(self, w, d, h, m, s):
        """
        redate jpeg file from offset : weeks, days, hours, minutes,seconds
        if exif : redate internal date and fs dates (jhead -ft)
        if not : redate file dates (atime/mtime)
        """
        if self.exifdate:
            # redate internal exif date
            # and redate "filesystem dates" with "jhead -ft" !!!
            newDate = cd2d(self.exifdate)
            newDate += timedelta(weeks=w,
                                 days=d,
                                 hours=h,
                                 minutes=m,
                                 seconds=s)

            _Command.setDate(self.file, newDate)
        else:
            # ONLY redate "filesystem dates"
            self.ds.redate(w, d, h, m, s)
        self.__read()  # read again, exifdate has changed

    def rotate(self, sens):
        _Command.rotate(self.file, sens)
        self.ds.touch()  # retouch filesystem mtime/atime
        self.__read()  # read again, because resolution has changed

    def rebuildExifTB(self):
        _Command.rebuildExifThumb(self.file)
        self.ds.touch()  # retouch filesystem mtime/atime
        self.__read()  # read again, perhaps something has changed

    def getExifInfo(self):
        """ return the result of jhead on this file """
        return _Command.getExifInfo(self.file)

    def destroyInfo(self):
        """ destroy info (exif/iptc) of the file
            but keep filesystem date

            *IMPORTANT* : it doesn't kill IPTC-block, only KEYWORDS !
        """
        _Command.removeExif(self.file)
        self.clear()  # clear IPTC tags
        self.ds.touch()  # retouch filesystem mtime/atime
        self.__read()  # read again, perhaps something has changed

    def copyInfoTo(self, file2):
        """ copy exif/iptc to "file2"
            and redate filesystem date of file2 according exif
        """
        assert type(file2) == unicode

        # copy iptc tags
        i = IPTCInfo(file2, True)
        i.keywords = []
        i.keywords += self.__iptc.keywords
        i.save()

        # copy exif (exif, thumb + jpegcomment), and redate
        _Command.copyExif(self.file, file2)

        # and rebuild i-thumb (should set good resolution in exif)
        ds = DateSave(file2)
        _Command.rebuildExifThumb(file2)
        ds.touch()