Beispiel #1
0
    def test_Command(f):
       c=_Command
       com = u"""héllçàé€$£'"€&&<>~^à"""
       t=c.getExif(f)
       res = t["resolution"]
       c.setJpegComment(f,com)
       c.rotate(f,"L")
       t=c.getExif(f)
       com2 = t["jpegcomment"]
       print [com,com2]
       assert res != t["resolution"], "rotate is bad"
       #~ assert com == com2, "jpegcomment problem"
       c.rotate(f,"R")
       c.setJpegComment(f,"")

       newf="jp.jpg"
       import shutil
       shutil.copy(f,newf)

       d=datetime.datetime(2000,11,14,12,10,59)
       c.setDate(newf,d)
       t=c.getExif(newf)
       assert cd2d(t["filedate"]) == cd2d(t["exifdate"]) == d,"dates problem"

       newNewf = c.normalizeName(newf)
       c.rebuildExifThumb(newNewf)
       c.removeExif(newNewf)
       os.unlink(newNewf)   #raise error if a problem
Beispiel #2
0
    def test_Command(f):
        c = _Command
        com = u"""héllçàé€$£'"€&&<>~^à"""
        t = c.getExif(f)
        res = t["resolution"]
        c.setJpegComment(f, com)
        c.rotate(f, "L")
        t = c.getExif(f)
        com2 = t["jpegcomment"]
        print[com, com2]
        assert res != t["resolution"], "rotate is bad"
        # ~ assert com == com2, "jpegcomment problem"
        c.rotate(f, "R")
        c.setJpegComment(f, "")

        newf = "jp.jpg"
        import shutil
        shutil.copy(f, newf)

        d = datetime.datetime(2000, 11, 14, 12, 10, 59)
        c.setDate(newf, d)
        t = c.getExif(newf)
        assert cd2d(t["filedate"]) == cd2d(t["exifdate"]) == d, "dates problem"

        newNewf = c.normalizeName(newf)
        c.rebuildExifThumb(newNewf)
        c.removeExif(newNewf)
        os.unlink(newNewf)  # raise error if a problem
Beispiel #3
0
    def getExif(file):
        #-----------------------------------------------------------------------
        """ return a dict of exif info of the file(jpeg) 'file'
            filedate,resolution,exifdate,isflash,jpegcomment
        """

        tag = {}

        buf = _Command._run([_Command.__jhead, file])
        assert type(buf) == unicode

        try:
            tag["filedate"] = \
                re.findall(
                    "File date    : (\d\d\d\d:\d\d:\d\d \d\d:\d\d:\d\d)",
                    buf)[0].strip()
            tag["resolution"] = \
                re.findall("Resolution   : (.*)", buf)[0].strip()
        except:
            raise CommandException("Exif decoding trouble in " + file + "\n" +
                                   buf)

        # try to get exif info (from jhead)
        try:
            exifdate = \
                re.findall(
                    "Date/Time    : (\d\d\d\d:\d\d:\d\d \d\d:\d\d:\d\d)",
                    buf)[0].strip()
            isflash = re.findall("Flash used   : (.*)", buf)[0].strip()
        except IndexError:
            exifdate = ""
            isflash = ""

        try:
            cd2d(ed2cd(exifdate))  # just to test if it's a real date
        except:
            exifdate = ""

        tag["exifdate"] = exifdate
        tag["isflash"] = isflash

        # get the comment (which can be multilines)
        mo_comm = re.findall("Comment      : (.*)", buf)
        comment = u""
        for i in mo_comm:
            if comment != "":
                comment = comment + "\n"
            comment = comment + i.strip()
        tag["jpegcomment"] = comment

        # convert date to format yyyymmddhhiiss
        tag["filedate"] = ed2cd(tag["filedate"])
        tag["exifdate"] = ed2cd(tag["exifdate"])

        return tag
Beispiel #4
0
    def getExif(file):
    #-----------------------------------------------------------------------
        """ return a dict of exif info of the file(jpeg) 'file'
            filedate,resolution,exifdate,isflash,jpegcomment
        """

        tag = {}

        buf = _Command._run([_Command.__jhead, file])
        assert type(buf) == unicode

        try:
            tag["filedate"] = \
                re.findall(
                    "File date    : (\d\d\d\d:\d\d:\d\d \d\d:\d\d:\d\d)",
                    buf)[0].strip()
            tag["resolution"] = \
                re.findall("Resolution   : (.*)", buf)[0].strip()
        except:
            raise CommandException("Exif decoding trouble in " +
                                   file + "\n" + buf)

        # try to get exif info (from jhead)
        try:
            exifdate = \
                re.findall(
                    "Date/Time    : (\d\d\d\d:\d\d:\d\d \d\d:\d\d:\d\d)",
                    buf)[0].strip()
            isflash = re.findall("Flash used   : (.*)", buf)[0].strip()
        except IndexError:
            exifdate = ""
            isflash = ""

        try:
            cd2d(ed2cd(exifdate))  # just to test if it's a real date
        except:
            exifdate = ""

        tag["exifdate"] = exifdate
        tag["isflash"] = isflash

        # get the comment (which can be multilines)
        mo_comm = re.findall("Comment      : (.*)", buf)
        comment = u""
        for i in mo_comm:
            if comment != "":
                comment = comment + "\n"
            comment = comment + i.strip()
        tag["jpegcomment"] = comment

        # convert date to format yyyymmddhhiiss
        tag["filedate"] = ed2cd(tag["filedate"])
        tag["exifdate"] = ed2cd(tag["exifdate"])

        return tag
Beispiel #5
0
 def getMinMaxDates(self):
     """ return a tuple of the (min, max) of photo dates
         or none if no photos
     """
     ln = self.root.xpath("//photo")
     if ln:
         ma = 11111111111111
         mi = 99999999999999
         for i in ln:
             a = int(i.attrib["date"])
             ma = max(a, ma)
             mi = min(a, mi)
         return cd2d(str(mi)), cd2d(str(ma))
Beispiel #6
0
 def getMinMaxDates(self):
     """ return a tuple of the (min, max) of photo dates
         or none if no photos
     """
     ln = self.root.xpath("//photo")
     if ln:
         ma = 11111111111111
         mi = 99999999999999
         for i in ln:
             a = int(i.attrib["date"])
             ma = max(a, ma)
             mi = min(a, mi)
         return cd2d(str(mi)), cd2d(str(ma))
Beispiel #7
0
   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
Beispiel #8
0
    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