예제 #1
0
 def testInit(self):
     '''
     The config file should be called pytof.ini,
     and be located inside the config dir
     '''
     conf = configHandler(join('data','conf'))
     self.assertEquals(join('data','conf','pytof.ini'), conf.confFilename)
예제 #2
0
파일: photo.py 프로젝트: Letractively/pytof
    def EXIF_infos(self):
        logger.info('Getting EXIF_infos for a photo object')
        try:
            ok = False
            logger.info('Getting a config handler instance')
            conf = configHandler()
            fn = conf.exifFilename 
            exifTags = {}
            logger.info('Checking if cache file %s exists' % fn)
            if exists(fn):
                exifFD = open(fn)
                exifTags = load(exifFD)
                if self.fileName in exifTags:
                    tags = exifTags[self.fileName]
                    ok = True
                else:
                    logger.info('This picture was not found in cache')
            else:
                logger.info('No exif cache file exists')

            logger.info('Status: %s' % ok)
            if not ok:
                logger.info('EXIF datas, not found in cache')
                a = 1
                tags = EXIF_tags(self.fileName)
                logger.info('EXIF datas retrieved by direct call')
                exifFD = open(fn, 'w')

                # Just write in the cache what we really need
                smallTags = {}
                smallTags['Image Model'] = str(tags.get('Image Model', 'Unknown'))
                smallTags['EXIF DateTimeOriginal'] = str(tags.get('EXIF DateTimeOriginal', 'Unknown'))
                smallTags['EXIF Flash'] = str(tags.get('EXIF Flash', 'Unknown'))
                smallTags['Image Orientation'] = str(tags.get('Image Orientation', 'Unknown'))

                exifTags[self.fileName] = smallTags
                dump(exifTags, exifFD)

            exifFD.close()

        except ValueError:
            logger.error('%s: EXIF extraction failed' % self.fileName)
            tags = {}
        self.rotation = str(tags.get('Image Orientation', 'Unknown'))

        class _datablob:
            def __init__(self, **args):
                self.__dict__.update(args)

        infos = _datablob()
        infos.model = str(tags.get('Image Model', 'Unknown'))
        infos.date = str(tags.get('EXIF DateTimeOriginal', 'Unknown'))
        infos.flash = str(tags.get('EXIF Flash', 'Unknown'))

        return infos
예제 #3
0
    def _InitAndSetLibrarySection(self):
        '''
        As we do some real stuff with the config file we
        should work on a copy.
        '''
        libraries = join('data', 'fake_iphoto_library')
        mkdir(join(self.tempdir, 'data'))
        tget = join(self.tempdir, libraries)
        copytree(libraries, tget)

        self.xmlFilename = 'AlbumData_gnocchi.xml'
        self.xmlFilename = 'AlbumData_fake_iphoto-2.xml'
        self.libraryPath = tget
        
        self.conf = configHandler(join(tget,'conf'))

        self.conf.setLibraryPath(self.libraryPath)
        self.conf.setXmlFileName(self.xmlFilename)

        self.assertEquals(self.conf.getLibraryPath(), self.libraryPath)
        self.assertEquals(self.conf.getXmlFileName(), self.xmlFilename)        
예제 #4
0
    def main(self):
        # init the config file
        conf = configHandler()
        if not conf.ok:
            _err_exit('Problem with the config file')

        libraryPath, xmlFileName, outputDir = \
                     conf.getValuesAndUpdateFromUser(self.libraryPath,
                                                     self.xmlFileName,
                                                     self.outputDir)

        ##
        # get iPhoto datas or flat dir pictures list
        if self.fb:
            logger.info('generate gallery from photos in %s dir' % self.fromDir)
            xmlData = None
            self.albumName = 'My Facebook pictures'
            self.fromDir = '/tmp/fb_files'

            facebook_download(self.fromDir, self.fb_uid)
            # sys.exit(0)

        elif not self.fromDir:
            try:
                adp = AlbumDataParser(libraryPath, xmlFileName)
                xmlData = adp.maybeLoadFromXML(conf)
            except(AlbumDataParserError):
                _err_exit("Problem parsing AlbumData.xml")
        else:
            logger.info('generate gallery from photos in %s dir' % self.fromDir)
            xmlData = None
            # FIXME: this '/' may not be portable ...
            self.albumName = basename(rstrip(self.fromDir, '/'))
            logger.info('albumName is %s' % self.albumName)

	# FIXME: remove the output dir if a problem occur
        up = 'pytof'
        topDir = join(self.outputDir, up, self.albumName)
        try:
            if not exists(topDir):
                os.makedirs(topDir)
        except (os.error):
            _err_exit('Cannot create %s' %(topDir))

        echo('output dir is %s' % (topDir))

        try:
            if self.info:
                for a in xmlData.getAlbumList():
                    try: 
                        print a.encode('utf8')
                    except UnicodeDecodeError:
                        print a
            else:
                if self.fs:
                    makefs.main(self.albumName, topDir, xmlData)
                else:
                    makepage.main(self.albumName, topDir, xmlData,
                                  self.stripOriginals, self.style,
                                  self.fromDir, self.progress)

            archive = None
            if self.Zip or self.tar:
                archive = mkarchive(fn = join(outputDir, up, self.albumName),
                                    prefix = join(outputDir, up),
                                    mainDir = self.albumName,
                                    files = [],
                                    Zip = self.Zip,
                                    tar = self.tar)
                echo('output archive is %s' % (archive))

            if not self.info and not self.fs:
                import webbrowser
                url = 'file:///'
                url += '/'.join(topDir.split(sep)) + '/'
                url += '/'.join(['..', 'index.html'])
                webbrowser.open(url)

            if self.ftp:
                ftpPush(conf, archive, topDir, self.fs)

        except (KeyboardInterrupt):

            if not self.info:
                if not self.fs:
                    # os.remove(makepage.cssfile)
                    # we should remove the css file if there aren't
                    # any other exported albums left... hard to know,
                    # may be stored in the rc file, under the Internal section.
                    # => if that's the only file in the pytof dir we should be good to go.
                    pass

                if exists(topDir):
                    rmtree(topDir)

                _err_exit("\nAborted by user")