Esempio n. 1
0
    def _export_file_work(self, dirpath, f):
        images = self._optionsDialog.options["ImageExtensions"]
        other = self._optionsDialog.options["OtherExtensions"]

        ext = os.path.splitext(f)[1].lower()
        srcFile = os.path.abspath(os.path.join(dirpath, f))
        img = None
        exportDatetime = None
        if ext in images or len(images) == 0:
            for img in self._images.iter_images():
                if os.path.abspath(img.get_filename()) == srcFile:
                    wx.CallAfter(self._images.rm_image, img)
                    break
            else:
                img = list(gen_images_from_files(srcFile, exiftool=self._exiftoolChecked))[0]
            exportDatetime = img.dateTime
        if exportDatetime is None and (ext in other or len(other) == 0):
            otherFile = list(gen_images_from_files(srcFile, exiftool=self._exiftoolChecked))[0]
            exportDatetime = otherFile.dateTime
            print f, exportDatetime
            assert exportDatetime is not None
            # exportDatetime = datetime.datetime.fromtimestamp(os.stat(srcFile).st_ctime)
        if exportDatetime is not None:
            exportDir = os.path.join(
                self._optionsDialog.options["FilingDir"],
                exportDatetime.strftime(self._optionsDialog.options["FilingStruct"]),
            )
            if not os.path.isdir(exportDir):
                os.makedirs(exportDir)
            if os.path.exists(os.path.join(exportDir, f)):
                self._do_check(self._export_file_overwrite_check, f, exportDir, srcFile)
            else:
                wx.CallAfter(self._statusBar.SetStatusText, "Exporting " + f)
                shutil.move(srcFile, exportDir)
Esempio n. 2
0
 def _load_file_work(self, path):
     wx.CallAfter(self._statusBar.SetStatusText, "Loading files from " + path)
     include = self._optionsDialog.options["ImageExtensions"]
     if len(include) == 0:
         include = None
     for i in gen_images_from_files(path, include=include, exiftool=self._exiftoolChecked):
         wx.CallAfter(self._statusBar.SetStatusText, "Loading " + i["FileName"])
         wx.CallAfter(self._add_image, i)
Esempio n. 3
0
    def _copy_file_work(self, f, dirpath, workingDir, ext, process, useJpegtran, jpegexiforient, jpegtran):
        wx.CallAfter(self._statusBar.SetStatusText, "Importing " + f)
        srcFile = os.path.join(dirpath, f)
        destFile = os.path.join(workingDir, f)
        if os.path.exists(destFile):
            # User must have OK'd this so delete the destination file then copy the new one into place
            os.remove(destFile)
        shutil.copy(srcFile, workingDir)
        if process and ext in [".jpg", ".jpeg"] and useJpegtran:
            # losslessly rotate
            p = Popen([jpegexiforient, "-n", destFile], stdin=PIPE, stdout=PIPE, stderr=PIPE)
            stdout, stderr = p.communicate()
            try:
                orient = int(stdout)
            except ValueError:
                # No orientation flag? Set orient to the value that prevents any further work
                orient = 1
            if orient > 1:
                wx.CallAfter(self._statusBar.SetStatusText, "Importing %s (losslessly rotating)" % f)
                print destFile, "- using option:", _jpegtranOptions[orient]
                tmpFile = destFile + ".pgtips~.jpg"
                p = Popen(
                    [jpegtran, "-copy", "all"] + _jpegtranOptions[orient] + ["-outfile", tmpFile, destFile],
                    stdin=PIPE,
                    stdout=PIPE,
                    stderr=PIPE,
                )
                stdout, stderr = p.communicate()
                assert p.returncode == 0, "jpegtran failed: " + stderr

                p = Popen([jpegexiforient, "-1", tmpFile], stdin=PIPE, stdout=PIPE, stderr=PIPE)
                stdout, stderr = p.communicate()
                assert p.returncode == 0, "jpegexiforient failed: " + stderr

                os.remove(destFile)
                os.rename(tmpFile, destFile)

        if process:
            # Now that the file is where it needs to be, load the file
            # TODO: Could optimize by batching files together?
            if 1:
                self._importQueue.put(destFile)
            else:
                wx.CallAfter(self._statusBar.SetStatusText, "Loading " + f)
                for i in gen_images_from_files(destFile, exiftool=self._exiftoolChecked):
                    wx.CallAfter(self._add_image, i)
Esempio n. 4
0
 def _ImportThread(self):
     while not self._closing:
         files = []
         try:
             filename = self._importQueue.get_nowait()
         except Queue.Empty:
             self._importing = False
             filename = self._importQueue.get()
         self._importing = True
         if filename is not None:
             files.append(filename)
             try:
                 timeout = 0.5
                 while True:
                     filename = self._importQueue.get(block=timeout > 0, timeout=timeout)
                     if filename is not None:
                         files.append(filename)
                         timeout -= 0.1
                     else:
                         break
             except Queue.Empty:
                 for i in gen_images_from_files(files, exiftool=self._exiftoolChecked):
                     wx.CallAfter(self._statusBar.SetStatusText, "Loading " + i["FileName"])
                     wx.CallAfter(self._add_image, i)