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
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
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
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