Exemplo n.º 1
0
Arquivo: db.py Projeto: peircej/jbrout
    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)
Exemplo n.º 2
0
Arquivo: db.py Projeto: peircej/jbrout
 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
Exemplo n.º 3
0
Arquivo: db.py Projeto: peircej/jbrout
    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)
Exemplo n.º 4
0
Arquivo: db.py Projeto: peircej/jbrout
 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
Exemplo n.º 5
0
Arquivo: db.py Projeto: peircej/jbrout
    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)
Exemplo n.º 6
0
Arquivo: db.py Projeto: peircej/jbrout
    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
Exemplo n.º 7
0
Arquivo: db.py Projeto: peircej/jbrout
    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
Exemplo n.º 8
0
Arquivo: db.py Projeto: peircej/jbrout
    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
Exemplo n.º 9
0
Arquivo: db.py Projeto: peircej/jbrout
    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
Exemplo n.º 10
0
Arquivo: db.py Projeto: peircej/jbrout
    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
Exemplo n.º 11
0
Arquivo: db.py Projeto: peircej/jbrout
    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)
Exemplo n.º 12
0
Arquivo: db.py Projeto: peircej/jbrout
    def setRating(self, val):
        assert type(val) == int

        pc = PhotoCmd(self.file)
        if pc.addRating(val):  # always true
            self.updateInfo(pc)
Exemplo n.º 13
0
Arquivo: db.py Projeto: peircej/jbrout
    def setComment(self, txt):
        assert type(txt) == unicode

        pc = PhotoCmd(self.file)
        if pc.addComment(txt):
            self.updateInfo(pc)
Exemplo n.º 14
0
Arquivo: db.py Projeto: peircej/jbrout
 def clearTags(self):
     pc = PhotoCmd(self.file)
     if pc.clear():
         self.updateInfo(pc)
Exemplo n.º 15
0
Arquivo: db.py Projeto: peircej/jbrout
 def setDate(self, date):
     pc = PhotoCmd(self.file)
     pc.setDate(date)
     self.updateInfo(pc)
     self.updateName()
Exemplo n.º 16
0
Arquivo: db.py Projeto: peircej/jbrout
    def rotate(self, sens):
        assert sens in ["R", "L"]

        pc = PhotoCmd(self.file)
        pc.rotate(sens)
        self.updateInfo(pc)
Exemplo n.º 17
0
Arquivo: db.py Projeto: peircej/jbrout
 def rebuildThumbnail(self):
     pc = PhotoCmd(self.file)
     pc.rebuildExifTB()
     self.updateInfo(pc)
Exemplo n.º 18
0
Arquivo: db.py Projeto: peircej/jbrout
    def delTag(self, tag):
        assert type(tag) == unicode

        pc = PhotoCmd(self.file)
        if pc.sub(tag):
            self.updateInfo(pc)
Exemplo n.º 19
0
Arquivo: db.py Projeto: peircej/jbrout
    def addTags(self, tags):
        assert type(tags) == list

        pc = PhotoCmd(self.file)
        if pc.addTags(tags):
            self.updateInfo(pc)
Exemplo n.º 20
0
Arquivo: db.py Projeto: peircej/jbrout
 def setDate(self, date):
     pc = PhotoCmd(self.file)
     pc.setDate(date)
     self.updateInfo(pc)
     self.updateName()
Exemplo n.º 21
0
Arquivo: db.py Projeto: peircej/jbrout
 def redate(self, w, d, h, m, s):
     pc = PhotoCmd(self.file)
     pc.redate(w, d, h, m, s)
     self.updateInfo(pc)
     self.updateName()
Exemplo n.º 22
0
Arquivo: db.py Projeto: peircej/jbrout
    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
Exemplo n.º 23
0
Arquivo: db.py Projeto: peircej/jbrout
 def rebuildThumbnail(self):
     pc = PhotoCmd(self.file)
     pc.rebuildExifTB()
     self.updateInfo(pc)
Exemplo n.º 24
0
Arquivo: db.py Projeto: peircej/jbrout
    def addTag(self, tag):
        assert type(tag) == unicode

        pc = PhotoCmd(self.file)
        if pc.add(tag):
            self.updateInfo(pc)
Exemplo n.º 25
0
Arquivo: db.py Projeto: peircej/jbrout
 def setNormalizeNameFormat(self, v):
     assert isinstance(v, basestring)
     PhotoCmd.setNormalizeNameFormat(v)
Exemplo n.º 26
0
Arquivo: db.py Projeto: peircej/jbrout
    def addTags(self, tags):
        assert type(tags) == list

        pc = PhotoCmd(self.file)
        if pc.addTags(tags):
            self.updateInfo(pc)
Exemplo n.º 27
0
Arquivo: db.py Projeto: peircej/jbrout
    def addTag(self, tag):
        assert type(tag) == unicode

        pc = PhotoCmd(self.file)
        if pc.add(tag):
            self.updateInfo(pc)
Exemplo n.º 28
0
Arquivo: db.py Projeto: peircej/jbrout
 def clearTags(self):
     pc = PhotoCmd(self.file)
     if pc.clear():
         self.updateInfo(pc)
Exemplo n.º 29
0
Arquivo: db.py Projeto: peircej/jbrout
    def setRating(self, val):
        assert type(val) == int

        pc = PhotoCmd(self.file)
        if pc.addRating(val):  # always true
            self.updateInfo(pc)
Exemplo n.º 30
0
Arquivo: db.py Projeto: peircej/jbrout
    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
Exemplo n.º 31
0
Arquivo: db.py Projeto: peircej/jbrout
    def rotate(self, sens):
        assert sens in ["R", "L"]

        pc = PhotoCmd(self.file)
        pc.rotate(sens)
        self.updateInfo(pc)
Exemplo n.º 32
0
Arquivo: db.py Projeto: peircej/jbrout
 def redate(self, w, d, h, m, s):
     pc = PhotoCmd(self.file)
     pc.redate(w, d, h, m, s)
     self.updateInfo(pc)
     self.updateName()
Exemplo n.º 33
0
Arquivo: db.py Projeto: peircej/jbrout
    def setComment(self, txt):
        assert type(txt) == unicode

        pc = PhotoCmd(self.file)
        if pc.addComment(txt):
            self.updateInfo(pc)
Exemplo n.º 34
0
Arquivo: db.py Projeto: peircej/jbrout
 def setNormalizeNameFormat(self, v):
     assert isinstance(v, basestring)
     PhotoCmd.setNormalizeNameFormat(v)
Exemplo n.º 35
0
Arquivo: db.py Projeto: peircej/jbrout
    def delTag(self, tag):
        assert type(tag) == unicode

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