예제 #1
0
    def getJpegPath(self):

        if self.exif is None:
            self.exif = Exif(self.strRawFile)
            self.exif.read()
        if self.strJepgFile is None:
            self.strJepgFile = unicode2ascii("%s-%s.jpg" % (
                    self.exif.interpretedExifValue("Exif.Photo.DateTimeOriginal").replace(" ", os.sep).replace(":", "-", 2).replace(":", "h", 1).replace(":", "m", 1),
                    self.exif.interpretedExifValue("Exif.Image.Model").strip().split(",")[-1].replace("/", "").replace(" ", "_")
                    ))
            while op.isfile(op.join(config.DefaultRepository, self.strJepgFile)):
                number = ""
                idx = None
                listChar = list(self.strJepgFile[:-4])
                listChar.reverse()
                for val in listChar:
                    if val.isdigit():
                        number = val + number
                    elif val == "-":
                        idx = int(number)
                        break
                    else:
                        break
                if idx is None:
                    self.strJepgFile = self.strJepgFile[:-4] + "-1.jpg"
                else:
                    self.strJepgFile = self.strJepgFile[:-5 - len(number)] + "-%i.jpg" % (idx + 1)
        dirname = op.dirname(op.join(config.DefaultRepository, self.strJepgFile))
        if not op.isdir(dirname):
            makedir(dirname)

        return self.strJepgFile
예제 #2
0
파일: search_day.py 프로젝트: kif/imagizer
 def search(self, *args):
     logger.debug("search button pressed")
     t = self.calB.get_date()
     begin = "%04d-%02d-%02d" % (t[0], t[1] + 1, t[2])
     t = self.calE.get_date()
     end = "%04d-%02d-%02d" % (t[0], t[1] + 1, t[2])
     if end < begin:
         logger.warning("End date more recent than start time !!!")
         return
     inTitle = unicode2ascii(self.xml.get_widget("InTitle").get_text().lower()).split()
     inComment = unicode2ascii(self.xml.get_widget("InComment").get_text().lower()).split()
     t0 = time.time()
     match = []
     for d in self.days:
         date = d[:10]
         if (end >= date >= begin):
             if len(inTitle) + len(inComment) == 0:
                 match.append(d)
             else:
                 day = Day.get(d)
                 good = False
                 for k in inTitle:
                     if k and (k in unicode2ascii(day.title.lower())):
                         good = True
                 if not good:
                     for k in inComment:
                         if k and (k in unicode2ascii(day.comment.lower())):
                             good = True
                 if good:
                     match.append(d)
     logger.info("search took %.3f" , (time.time() - t0))
     self.store = gtk.ListStore(str, str, str, str)
     for i in match:
         d = Day.get(i)
         comment = d.comment.replace("<BR>", " ")
         if len(comment) > 60:
             comment = comment[:60] + "..."
         self.store.append([i, "%02i/%02i/%04i" % (d.day, d.month, d.year), d.title, comment])
     self.results.set_model(self.store)
     return match
    def start(self, rootDir):
        """ Lance les calculs
        
        @param rootDir: top level directory to start processing
        @return: 2tuple containing the list of all images and the start-index
        @rtype: (list,integer)
        """
        config.DefaultRepository = rootDir
        AllJpegs = fileutils.findFiles(rootDir)
        AllFilesToProcess = []
        AllreadyDone = []
        NewFiles = []
        uid = os.getuid()
        gid = os.getgid()
        for i in AllJpegs:
            if i.find(config.TrashDirectory) == 0: continue
            if i.find(config.SelectedDirectory) == 0: continue
            try:
                a = int(i[:4])
                m = int(i[5:7])
                j = int(i[8:10])
                if (a >= 0000) and (m <= 12) and (j <= 31) and (i[4] in ["-", "_", "."]) and (i[7] in ["-", "_"]):
                    AllreadyDone.append(i)
                else:
                    AllFilesToProcess.append(i)
            except ValueError:
                AllFilesToProcess.append(i)
        AllFilesToProcess.sort()
        NumFiles = len(AllFilesToProcess)
        self.startSignal.emit(self.__label, NumFiles)
        for h in range(NumFiles):
            i = AllFilesToProcess[h]
            self.refreshSignal.emit(h, i)
            myPhoto = Photo(i, dontCache=True)
            data = myPhoto.readExif()
            try:
                datei, heurei = data["Heure"].split()
                date = re.sub(":", "-", datei)
                heurej = re.sub(":", "h", heurei, 1)
                model = data["Modele"].split(",")[-1]
                heure = unicode2ascii("%s-%s.jpg" % (re.sub(":", "m", heurej, 1), re.sub("/", "", re.sub(" ", "_", model))))
            except ValueError:
                date = time.strftime("%Y-%m-%d", time.gmtime(os.path.getctime(os.path.join(rootDir, i))))
                heure = unicode2ascii("%s-%s.jpg" % (time.strftime("%Hh%Mm%S", time.gmtime(os.path.getctime(os.path.join(rootDir, i)))), re.sub("/", "-", re.sub(" ", "_", os.path.splitext(i)[0]))))
            if not (os.path.isdir(os.path.join(rootDir, date))) :
                fileutils.mkdir(os.path.join(rootDir, date))
#            strImageFile = os.path.join(rootDir, date, heure)
            ToProcess = os.path.join(date, heure)
            bSkipFile = False
            for strImageFile in fileutils.list_files_in_named_dir(rootDir, date, heure):
                logger.warning("%s -x-> %s", i, strImageFile)
                existing = Photo(strImageFile, dontCache=True)
                try:
                    existing.readExif()
                    originalName = existing.exif["Exif.Photo.UserComment"]
                except:
                    logger.error("in ModelRangeTout: reading Exif for %s", i)
                else:
                    if "human_value" in dir(originalName):
                        originalName = originalName.human_value
                    if os.path.basename(originalName) == os.path.basename(i):
                        logger.info("File already in repository, leaving as it is")
                        bSkipFile = True
                        continue #to next file, i.e. leave the existing one
            if bSkipFile:
                continue
            else:
                strImageFile = os.path.join(rootDir, date, heure)
            if os.path.isfile(strImageFile):
                s = 0
                for j in os.listdir(os.path.join(rootDir, date)):
                    if j.find(heure[:-4]) == 0:s += 1
                ToProcess = os.path.join(date, heure[:-4] + "-%s.jpg" % s)
                strImageFile = os.path.join(rootDir, ToProcess)
            shutil.move(os.path.join(rootDir, i), strImageFile)
            try:
                os.chown(strImageFile, uid, gid)
                os.chmod(strImageFile, config.DefaultFileMode)
            except OSError:
                logger.warning("in ModelRangeTout: unable to chown ot chmod  %s" , strImageFile)
            myPhoto = Photo(strImageFile, dontCache=True)
#            Save the old image name in exif tag
            myPhoto.storeOriginalName(i)

            if config.AutoRotate:
                myPhoto.autorotate()
            AllreadyDone.append(ToProcess)
            NewFiles.append(ToProcess)
        AllreadyDone.sort()
        self.finishSignal.emit()

        if len(NewFiles) > 0:
            FirstImage = min(NewFiles)
            return AllreadyDone, AllreadyDone.index(FirstImage)
        else:
            return AllreadyDone, 0