コード例 #1
0
ファイル: download.py プロジェクト: zy-sunshine/pygtk-example
    def _buildListSource(self):
        """Builds list of files to be downloaded"""
        self.invalidSource = False
        self.invalidDest = True
        self.imLst.clear()
        self.statusBar.push(self.cidStatusBar,
            _('Finding source files in "%s"') % self.srcFolder)
        yield True
        self.imgInfs = []
        fileList = self._listFiles(self.srcFolder)
        fileList.sort()
        self.statusBar.pop(self.cidStatusBar)
        self.statusBar.push(self.cidStatusBar,
            _('Reading source file information from "%s"') % self.srcFolder)
        yield True

        model = self.imLst.get_model()
        self.imLst.set_model(None)

        if self.invalidSource or self.quitNow:
            self.statusBar.pop(self.cidStatusBar)
            self.buildListRunning = False
            yield False
        for srcFile in fileList:
            exifData=pyexiv.Image(srcFile)
            exifData.readMetadata()
            size=os.path.getsize(srcFile)
            if 'Exif.Photo.DateTimeOriginal' in exifData.exifKeys():
                date = ed2d(exifData.interpretedExifValue('Exif.Photo.DateTimeOriginal'))
            else:
                date = datetime.datetime.fromtimestamp(os.path.getmtime(srcFile))
            row=[
                srcFile[len(self.srcFolder)+1:],
                format_file_size_for_display(size),
                size,
                date,
                date,
                exifData,
                '',
                '',
                '',
                '',
                '']
            self.imgInfs.append(row[:-4])
            self.imLst.appendRows([row])

            if self.invalidSource or self.quitNow:
                self.statusBar.pop(self.cidStatusBar)
                self.buildListRunning = False
                yield False
            yield True

        self.imLst.set_model(model)

        self.buildListRunning = False
        self.statusBar.pop(self.cidStatusBar)
        yield False
コード例 #2
0
ファイル: download.py プロジェクト: peircej/jbrout
    def _buildListSource(self):
        """Builds list of files to be downloaded"""
        self.invalidSource = False
        self.invalidDest = True
        self.imLst.clear()
        self.statusBar.push(self.cidStatusBar,
                            _('Finding source files in "%s"') % self.srcFolder)
        yield True
        self.imgInfs = []
        fileList = self._listFiles(self.srcFolder)
        fileList.sort()
        self.statusBar.pop(self.cidStatusBar)
        self.statusBar.push(
            self.cidStatusBar,
            _('Reading source file information from "%s"') % self.srcFolder)
        yield True

        model = self.imLst.get_model()
        self.imLst.set_model(None)

        if self.invalidSource or self.quitNow:
            self.statusBar.pop(self.cidStatusBar)
            self.buildListRunning = False
            yield False
        for srcFile in fileList:
            exifData = pyexiv.Exiv2Metadata(pyexiv2.ImageMetadata(srcFile))
            exifData.readMetadata()
            size = os.path.getsize(srcFile)
            if 'Exif.Photo.DateTimeOriginal' in exifData.exifKeys():
                date = ed2d(
                    exifData.interpretedExifValue(
                        'Exif.Photo.DateTimeOriginal'))
            else:
                date = datetime.datetime.fromtimestamp(
                    os.path.getmtime(srcFile))
            row = [
                srcFile[len(self.srcFolder) + 1:],
                format_file_size_for_display(size), size, date, date, exifData,
                '', '', '', '', ''
            ]
            self.imgInfs.append(row[:-4])
            self.imLst.appendRows([row])

            if self.invalidSource or self.quitNow:
                self.statusBar.pop(self.cidStatusBar)
                self.buildListRunning = False
                yield False
            yield True

        self.imLst.set_model(model)

        self.buildListRunning = False
        self.statusBar.pop(self.cidStatusBar)
        yield False
コード例 #3
0
ファイル: download.py プロジェクト: peircej/jbrout
    def _buildListDest(self):
        """Adds destination file name, download status and rotation to a list
        of files to be downloaded"""
        self.invalidDest = False
        # Check that the list is not empty
        if self.imLst.getCount() == 0:
            self.buildListRunning = False
            yield False

        model = self.imLst.get_model()
        self.imLst.set_model(None)

        # Start new
        # Build image Names
        # Build names without seralisation
        self.statusBar.push(self.cidStatusBar, _('Building destination Names'))
        yield True
        # Clear all destination information
        for rowIdx in range(self.imLst.getCount()):
            self.imLst.setItem(rowIdx, dc.C_SS, '')
            self.imLst.setItem(rowIdx, dc.C_STAT, '')
            self.imLst.setItem(rowIdx, dc.C_RS, '')
            self.imLst.setItem(rowIdx, dc.C_ROT, '')
        for imageInfo in self.imgInfs:
            imageInfo[dc.C_DEST] = self.nb.name(
                imageInfo[dc.C_SRC],
                '',  # Dest folder blank as not needed here
                self.__conf['nameFormat'],
                imageInfo[dc.C_EXIF],
                imageInfo[dc.C_DATE],
                self.__conf['jobCode'])
        if not self.nb.seralize(self.imgInfs, dc.C_SRC, dc.C_DATE, dc.C_DEST):
            MessageBox(
                self.main_widget,
                _("More than one serialisation tag used please use preferencess to remove from File Naming > Parttern"
                  ))
            self.statusBar.pop(self.cidStatusBar)
            self.invalidDest - True
            self.badPattern = True
            self.buildListRunning = False
            yield False
        if self.invalidSource or self.invalidDest or self.quitNow:
            self.statusBar.pop(self.cidStatusBar)
            self.buildListRunning = False
            yield False
        yield True
        # Note need to make sure self.imgInfs is sorted by source file
        # for the below to work
        # Write destination names into imList
        for imgIdx, imgInf in enumerate(self.imgInfs):
            if self.imLst.getItem(imgIdx, dc.C_SRC) != imgInf[dc.C_SRC]:
                print "No Match at %d ?" % (imgIdx)
                print "List: %s" % self.imLst.getItem(imageIndex, dc.C_SRC)
                print "Source: %s" % imgInf[dc.C_SRC]
            else:
                self.imLst.setItem(imgIdx, dc.C_DEST, imgInf[dc.C_DEST])
            if self.invalidSource or self.invalidDest or self.quitNow:
                self.statusBar.pop(self.cidStatusBar)
                self.buildListRunning = False
                yield False
            yield True
        self.statusBar.pop(self.cidStatusBar)
        # Check Status
        self.statusBar.push(self.cidStatusBar, _('Checking Status of Images'))
        yield True
        for rowIdx, row in enumerate(self.imLst.iterAllRows()):
            destFile = os.path.join(self.destFolder, row[dc.C_DEST])
            count = 0
            for chkRow in self.imLst.iterAllRows():
                if chkRow[dc.C_DEST] == row[dc.C_DEST]:
                    count += 1
            if count > 1:
                statS = 'C'
                statL = _('Collision with New')
            elif os.path.isfile(destFile):
                destExif = pyexiv.Exiv2Metadata(
                    pyexiv2.ImageMetadata(destFile))
                destExif.readMetadata()
                if 'Image DateTime' in destExif.exifKeys():
                    destDate = ed2d(
                        destExif.interpretedExifValue(
                            'Exif.Photo.DateTimeOriginal'))
                else:
                    destDate = datetime.datetime.fromtimestamp(
                        os.path.getmtime(destFile))
                if destDate.timetuple() == row[dc.C_DATE].timetuple():
                    statS = 'D'
                    statL = _('Downloaded')
                else:
                    statS = 'C'
                    statL = _('Collision with Existing')
            else:
                statS = 'N'
                statL = _('New')
            if self.invalidSource or self.invalidDest or self.quitNow:
                self.statusBar.pop(self.cidStatusBar)
                self.buildListRunning = False
                yield False
            self.imLst.setItem(rowIdx, dc.C_SS, statS)
            self.imLst.setItem(rowIdx, dc.C_STAT, statL)
            yield True
        self.statusBar.pop(self.cidStatusBar)
        # Check Rotation
        self.statusBar.push(self.cidStatusBar,
                            _('Checking Rotation Required for Images'))
        yield True
        for rowIdx, row in enumerate(self.imLst.iterAllRows()):
            if self.__conf["autoRotate"] == 1:
                try:
                    rotS = autoTrans[int(
                        row[dc.C_EXIF]['Exif.Image.Orientation'])][0]
                    rotL = autoTrans[int(
                        row[dc.C_EXIF]['Exif.Image.Orientation'])][1]
                except KeyError:
                    rotS = autoTrans[1][0]
                    rotL = autoTrans[1][1]
            else:
                rotS = autoTrans[1][0]
                rotL = _('Disabled')
            if self.invalidSource or self.invalidDest or self.quitNow:
                self.statusBar.pop(self.cidStatusBar)
                self.buildListRunning = False
                yield False
            self.imLst.setItem(rowIdx, dc.C_RS, rotS)
            self.imLst.setItem(rowIdx, dc.C_ROT, rotL)
            yield True
        self.statusBar.pop(self.cidStatusBar)

        self.imLst.set_model(model)

        # Completed exiting
        self.btnExecute.set_sensitive(True)
        self.buildListRunning = False
        yield False
コード例 #4
0
ファイル: download.py プロジェクト: zy-sunshine/pygtk-example
    def _buildListDest (self):
        """Adds destination file name, download status and rotation to a list
        of files to be downloaded"""
        self.invalidDest = False
        # Check that the list is not empty
        if self.imLst.getCount() == 0:
            self.buildListRunning = False
            yield False

        model = self.imLst.get_model()
        self.imLst.set_model(None)

        # Start new
        # Build image Names
        # Build names without seralisation
        self.statusBar.push(self.cidStatusBar, _('Building destination Names'))
        yield True
        # Clear all destination information
        for rowIdx in range(self.imLst.getCount()):
            self.imLst.setItem(rowIdx, dc.C_SS, '')
            self.imLst.setItem(rowIdx, dc.C_STAT, '')
            self.imLst.setItem(rowIdx, dc.C_RS, '')
            self.imLst.setItem(rowIdx, dc.C_ROT, '')
        for imageInfo in self.imgInfs:
            imageInfo[dc.C_DEST] = self.nb.name(
                                    imageInfo[dc.C_SRC],
                                    '', # Dest folder blank as not needed here
                                    self.__conf['nameFormat'],
                                    imageInfo[dc.C_EXIF],
                                    imageInfo[dc.C_DATE],
                                    self.__conf['jobCode'])
        if not self.nb.seralize(self.imgInfs,dc.C_SRC,dc.C_DATE,dc.C_DEST):
            MessageBox(self.main_widget,
            _("More than one serialisation tag used please use preferencess to remove from File Naming > Parttern"))
            self.statusBar.pop(self.cidStatusBar)
            self.invalidDest - True
            self.badPattern = True
            self.buildListRunning = False
            yield False
        if self.invalidSource or self.invalidDest or self.quitNow:
            self.statusBar.pop(self.cidStatusBar)
            self.buildListRunning = False
            yield False
        yield True
        # Note need to make sure self.imgInfs is sorted by source file
        # for the below to work
        # Write destination names into imList
        for imgIdx, imgInf in enumerate(self.imgInfs):
            if self.imLst.getItem(imgIdx,dc.C_SRC) != imgInf[dc.C_SRC]:
                print "No Match at %d ?" % (imgIdx)
                print "List: %s" % self.imLst.getItem(imageIndex,dc.C_SRC)
                print "Source: %s" % imgInf[dc.C_SRC]
            else:
                self.imLst.setItem(imgIdx,
                                   dc.C_DEST,
                                   imgInf[dc.C_DEST])
            if self.invalidSource or self.invalidDest or self.quitNow:
                self.statusBar.pop(self.cidStatusBar)
                self.buildListRunning = False
                yield False
            yield True
        self.statusBar.pop(self.cidStatusBar)
        # Check Status
        self.statusBar.push(self.cidStatusBar, _('Checking Status of Images'))
        yield True
        for rowIdx, row in enumerate(self.imLst.iterAllRows()):
            destFile = os.path.join(self.destFolder,row[dc.C_DEST])
            count = 0
            for chkRow in self.imLst.iterAllRows():
                if chkRow[dc.C_DEST] == row[dc.C_DEST]:
                    count += 1
            if count > 1:
                statS = 'C'
                statL = _('Collision with New')
            elif os.path.isfile(destFile):
                destExif = pyexiv.Image(destFile)
                destExif.readMetadata()
                if 'Image DateTime' in destExif.exifKeys():
                    destDate = ed2d(destExif.interpretedExifValue('Exif.Photo.DateTimeOriginal'))
                else:
                    destDate = datetime.datetime.fromtimestamp(
                        os.path.getmtime(destFile))
                if destDate.timetuple() == row[dc.C_DATE].timetuple():
                    statS = 'D'
                    statL = _('Downloaded')
                else:
                    statS = 'C'
                    statL = _('Collision with Existing')
            else:
                statS = 'N'
                statL = _('New')
            if self.invalidSource or self.invalidDest or self.quitNow:
                self.statusBar.pop(self.cidStatusBar)
                self.buildListRunning = False
                yield False
            self.imLst.setItem(rowIdx, dc.C_SS, statS)
            self.imLst.setItem(rowIdx, dc.C_STAT, statL)
            yield True
        self.statusBar.pop(self.cidStatusBar)
        # Check Rotation
        self.statusBar.push(self.cidStatusBar, _('Checking Rotation Required for Images'))
        yield True
        for rowIdx, row in enumerate(self.imLst.iterAllRows()):
            if self.__conf["autoRotate"] == 1:
                try:
                    rotS = autoTrans[int(row[dc.C_EXIF]['Exif.Image.Orientation'])][0]
                    rotL = autoTrans[int(row[dc.C_EXIF]['Exif.Image.Orientation'])][1]
                except KeyError:
                    rotS = autoTrans[1][0]
                    rotL = autoTrans[1][1]
            else:
                rotS = autoTrans[1][0]
                rotL = _('Disabled')
            if self.invalidSource or self.invalidDest or self.quitNow:
                self.statusBar.pop(self.cidStatusBar)
                self.buildListRunning = False
                yield False
            self.imLst.setItem(rowIdx, dc.C_RS, rotS)
            self.imLst.setItem(rowIdx, dc.C_ROT, rotL)
            yield True
        self.statusBar.pop(self.cidStatusBar)

        self.imLst.set_model(model)

        # Completed exiting
        self.btnExecute.set_sensitive(True)
        self.buildListRunning = False
        yield False