Exemple #1
0
    def transform(self, sens):
        assert sens in ["auto", "rotate90", "rotate180", "rotate270",
                        "flipHorizontal", "flipVertical", "transpose",
                        "transverse"]

        pc = PhotoCmd(self.file)
        pc.transform(sens)
        self.updateInfo(pc)
Exemple #2
0
 def redoIPTC(self):
     """ refresh IPTC in file and db """
     ln = self.root.xpath(u"""//photo[t]""")
     for i in ln:
         p = PhotoNode(i)
         print p.name
         pc = PhotoCmd(p.file)
         pc.__maj()              # rewrite iptc in file
         p.updateInfo(pc)      # rewrite iptc in db.xml
Exemple #3
0
    def transform(self, sens):
        assert sens in [
            "auto", "rotate90", "rotate180", "rotate270", "flipHorizontal",
            "flipVertical", "transpose", "transverse"
        ]

        pc = PhotoCmd(self.file)
        pc.transform(sens)
        self.updateInfo(pc)
Exemple #4
0
 def redoIPTC(self):
     """ refresh IPTC in file and db """
     ln = self.root.xpath(u"""//photo[t]""")
     for i in ln:
         p = PhotoNode(i)
         print p.name
         pc = PhotoCmd(p.file)
         pc.__maj()  # rewrite iptc in file
         p.updateInfo(pc)  # rewrite iptc in db.xml
Exemple #5
0
    def getInfoFrom(self, copy):
        """ rewrite info from a 'copy' to the file (exif, iptc, ...)
            and rebuild thumb
            (used to ensure everything is back after a run in another program
             see plugin 'touch')
        """
        pc = PhotoCmd(copy)
        pc.copyInfoTo(self.file)

        #and update infos
        # generally, it's not necessary ... but if size had changed, jhead
        # correct automatically width/height exif, so we need to put back in db
        pc = PhotoCmd(self.file)
        self.updateInfo(pc)
Exemple #6
0
    def __addPhoto(self, nodeDir, file, tags, filesInBasket):
        assert type(file) == unicode

        newNode = Element("photo")
        nodeDir.append(newNode)

        node = PhotoNode(newNode)
        if file in filesInBasket:
            node.addToBasket()

        try:
            iii = PhotoCmd(
                file,
                needAutoRename=DBPhotos.normalizeName,
                needAutoRotation=DBPhotos.autorotAtImport,
            )
            if iii.exifdate == "":
                # exif is not present, and photocmd can't reach
                # to recreate minimal exif tags (because it's readonly ?)
                # we can't continue to import this photo
                raise Exception(
                    "Exif couldn't be set in this picture (readonly?)")
        except Exception, m:
            # remove the bad node
            nodeDir.remove(newNode)

            return m
Exemple #7
0
    def updateName(self):
        #photo has been redated
        #it should be renamed if in config ...
        if DBPhotos.normalizeName:
            pc = PhotoCmd(self.file, needAutoRename=True)
            self.updateInfo(pc)

        return True
Exemple #8
0
    def moveToFolder(self, nodeFolder):
        assert nodeFolder.__class__ == FolderNode

        name = self.name
        while os.path.isfile(os.path.join(nodeFolder.file, name)):
            name = PhotoCmd.giveMeANewName(name)

        try:
            shutil.move(self.file, os.path.join(nodeFolder.file, name))
            moved = True
        except os.error, detail:
            raise Exception(detail)
            moved = False
Exemple #9
0
    def moveToFolder(self, nodeFolder):
        assert nodeFolder.__class__ == FolderNode

        name = self.name
        while os.path.isfile(os.path.join(nodeFolder.file, name)):
            name = PhotoCmd.giveMeANewName(name)

        try:
            shutil.move(self.file, os.path.join(nodeFolder.file, name))
            moved = True
        except os.error, detail:
            raise Exception(detail)
            moved = False
Exemple #10
0
    def getInfo(self):
        """
        get real infos from photocmd
        """
        pc = PhotoCmd(self.file)
        info = {}
        info["tags"] = pc.tags
        info["comment"] = pc.comment
        info["exifdate"] = pc.exifdate
        info["rating"] = pc.rating  # huh, did i use that?
        info["filedate"] = pc.filedate
        info["resolution"] = pc.resolution
        info["readonly"] = pc.readonly
        info["filesize"] = os.stat(self.file)[6]

        return info
Exemple #11
0
    def getInfoFrom(self, copy):
        """ rewrite info from a 'copy' to the file (exif, iptc, ...)
            and rebuild thumb
            (used to ensure everything is back after a run in another program
             see plugin 'touch')
        """
        pc = PhotoCmd(copy)
        pc.copyInfoTo(self.file)

        #and update infos
        # generally, it's not necessary ... but if size had changed, jhead
        # correct automatically width/height exif, so we need to put back in db
        pc = PhotoCmd(self.file)
        self.updateInfo(pc)
Exemple #12
0
    def setRating(self, val):
        assert type(val) == int

        pc = PhotoCmd(self.file)
        if pc.addRating(val):  # always true
            self.updateInfo(pc)
Exemple #13
0
    def setComment(self, txt):
        assert type(txt) == unicode

        pc = PhotoCmd(self.file)
        if pc.addComment(txt):
            self.updateInfo(pc)
Exemple #14
0
 def clearTags(self):
     pc = PhotoCmd(self.file)
     if pc.clear():
         self.updateInfo(pc)
Exemple #15
0
 def setDate(self, date):
     pc = PhotoCmd(self.file)
     pc.setDate(date)
     self.updateInfo(pc)
     self.updateName()
Exemple #16
0
    def rotate(self, sens):
        assert sens in ["R", "L"]

        pc = PhotoCmd(self.file)
        pc.rotate(sens)
        self.updateInfo(pc)
Exemple #17
0
 def rebuildThumbnail(self):
     pc = PhotoCmd(self.file)
     pc.rebuildExifTB()
     self.updateInfo(pc)
Exemple #18
0
    def delTag(self, tag):
        assert type(tag) == unicode

        pc = PhotoCmd(self.file)
        if pc.sub(tag):
            self.updateInfo(pc)
Exemple #19
0
    def addTags(self, tags):
        assert type(tags) == list

        pc = PhotoCmd(self.file)
        if pc.addTags(tags):
            self.updateInfo(pc)
Exemple #20
0
 def setDate(self, date):
     pc = PhotoCmd(self.file)
     pc.setDate(date)
     self.updateInfo(pc)
     self.updateName()
Exemple #21
0
 def redate(self, w, d, h, m, s):
     pc = PhotoCmd(self.file)
     pc.redate(w, d, h, m, s)
     self.updateInfo(pc)
     self.updateName()
Exemple #22
0
    def copyTo(self,
               path,
               resize=None,
               keepInfo=True,
               delTags=False,
               delCom=False):
        """ copy self to the path "path", and return its newfilename or none
            by default, it keeps IPTC/THUMB/EXIF, but it can be removed by
            setting keepInfo at False. In all case, new file keep its filedate
            system

            image can be resized/recompressed (preserving ratio) if resize
            (which is a tuple=(size, qual)) is provided:
                if size is a float : it's a percent of original
                if size is a int : it's the desired largest side
                qual : is the percent for the quality
        """
        assert type(path) == unicode, "photonod.copyTo() : path is not unicode"
        dest = os.path.join(path, self.name)

        while os.path.isfile(dest):
            dest = os.path.join(
                path, PhotoCmd.giveMeANewName(os.path.basename(dest)))

        if resize:
            assert len(resize) == 2
            size, qual = resize
            assert type(size) in [int, float]

            pb = self.getImage()  # a gtk.PixBuf
            (wx, wy) = pb.get_width(), pb.get_height()

            # compute the new size -> wx/wy
            if type(size) == float:
                # size is a percent
                size = int(size * 100)
                wx = int(wx * size / 100)
                wy = int(wy * size / 100)

            else:
                # size is the largest side in pixels
                if wx > wy:
                    # format landscape
                    wx, wy = size, (size * wy) / wx
                else:
                    # format portrait
                    wx, wy = (size * wx) / wy, size

            # 3= best quality (gtk.gdk.INTERP_HYPER)
            pb = pb.scale_simple(wx, wy, 3)
            pb.save(dest, "jpeg", {"quality": str(int(qual))})

            if keepInfo:
                pc = PhotoCmd(self.file)
                pc.copyInfoTo(dest)
            del (pb)
            gc.collect()  # so it cleans pixbufs
        else:
            shutil.copy2(self.file, dest)
            if not keepInfo:
                # we must destroy info
                PhotoCmd(dest).destroyInfo()
        if keepInfo:
            if delCom:
                PhotoCmd(dest).addComment(u"")
            if delTags:
                PhotoCmd(dest).clear()

        return dest
Exemple #23
0
 def rebuildThumbnail(self):
     pc = PhotoCmd(self.file)
     pc.rebuildExifTB()
     self.updateInfo(pc)
Exemple #24
0
    def addTag(self, tag):
        assert type(tag) == unicode

        pc = PhotoCmd(self.file)
        if pc.add(tag):
            self.updateInfo(pc)
Exemple #25
0
 def setNormalizeNameFormat(self, v):
     assert isinstance(v, basestring)
     PhotoCmd.setNormalizeNameFormat(v)
Exemple #26
0
    def addTags(self, tags):
        assert type(tags) == list

        pc = PhotoCmd(self.file)
        if pc.addTags(tags):
            self.updateInfo(pc)
Exemple #27
0
    def addTag(self, tag):
        assert type(tag) == unicode

        pc = PhotoCmd(self.file)
        if pc.add(tag):
            self.updateInfo(pc)
Exemple #28
0
 def clearTags(self):
     pc = PhotoCmd(self.file)
     if pc.clear():
         self.updateInfo(pc)
Exemple #29
0
    def setRating(self, val):
        assert type(val) == int

        pc = PhotoCmd(self.file)
        if pc.addRating(val):  # always true
            self.updateInfo(pc)
Exemple #30
0
    def copyTo(self, path, resize=None, keepInfo=True, delTags=False,
               delCom=False):
        """ copy self to the path "path", and return its newfilename or none
            by default, it keeps IPTC/THUMB/EXIF, but it can be removed by
            setting keepInfo at False. In all case, new file keep its filedate
            system

            image can be resized/recompressed (preserving ratio) if resize
            (which is a tuple=(size, qual)) is provided:
                if size is a float : it's a percent of original
                if size is a int : it's the desired largest side
                qual : is the percent for the quality
        """
        assert type(path) == unicode, "photonod.copyTo() : path is not unicode"
        dest = os.path.join(path, self.name)

        while os.path.isfile(dest):
            dest = os.path.join(path,
                                PhotoCmd.giveMeANewName(
                                    os.path.basename(dest)))

        if resize:
            assert len(resize) == 2
            size, qual = resize
            assert type(size) in [int, float]

            pb = self.getImage()  # a gtk.PixBuf
            (wx, wy) = pb.get_width(), pb.get_height()

            # compute the new size -> wx/wy
            if type(size) == float:
                # size is a percent
                size = int(size * 100)
                wx = int(wx * size / 100)
                wy = int(wy * size / 100)

            else:
                # size is the largest side in pixels
                if wx > wy:
                    # format landscape
                    wx, wy = size, (size * wy) / wx
                else:
                    # format portrait
                    wx, wy = (size * wx) / wy, size

            # 3= best quality (gtk.gdk.INTERP_HYPER)
            pb = pb.scale_simple(wx, wy, 3)
            pb.save(dest, "jpeg", {"quality": str(int(qual))})

            if keepInfo:
                pc = PhotoCmd(self.file)
                pc.copyInfoTo(dest)
            del(pb)
            gc.collect()  # so it cleans pixbufs
        else:
            shutil.copy2(self.file, dest)
            if not keepInfo:
                # we must destroy info
                PhotoCmd(dest).destroyInfo()
        if keepInfo:
            if delCom:
                PhotoCmd(dest).addComment(u"")
            if delTags:
                PhotoCmd(dest).clear()

        return dest
Exemple #31
0
    def rotate(self, sens):
        assert sens in ["R", "L"]

        pc = PhotoCmd(self.file)
        pc.rotate(sens)
        self.updateInfo(pc)
Exemple #32
0
 def redate(self, w, d, h, m, s):
     pc = PhotoCmd(self.file)
     pc.redate(w, d, h, m, s)
     self.updateInfo(pc)
     self.updateName()
Exemple #33
0
    def setComment(self, txt):
        assert type(txt) == unicode

        pc = PhotoCmd(self.file)
        if pc.addComment(txt):
            self.updateInfo(pc)
Exemple #34
0
 def setNormalizeNameFormat(self, v):
     assert isinstance(v, basestring)
     PhotoCmd.setNormalizeNameFormat(v)
Exemple #35
0
    def delTag(self, tag):
        assert type(tag) == unicode

        pc = PhotoCmd(self.file)
        if pc.sub(tag):
            self.updateInfo(pc)