コード例 #1
0
ファイル: makefs_test.py プロジェクト: Letractively/pytof
    def testiPhoto6(self):
        self.albumName = 'Livre Yosemite'
        self.libraryPath = join('data', 'fake_iphoto_library')
        self.xmlFilename = 'AlbumData_fake_iphoto-6.0.5.xml'

        parser = AlbumDataParser(self.libraryPath, self.xmlFilename)
        self.xmlData = parser.parse()

        main(self.albumName, self.topDir, self.xmlData)
コード例 #2
0
    def _testAlbumNames(self, xml):
        ''' TODO: try with album with non-ascii chars '''
        parser = AlbumDataParser(self.libraryPath, xml)
        xmlData = parser.parse()
        albumList = xmlData.getAlbumList()

        for album in self.albums.splitlines():
            album = album.strip()
            if album:
                self.assert_(album in albumList)
コード例 #3
0
ファイル: config_test.py プロジェクト: Letractively/pytof
 def testTwoInitFromXmlWithNewObject(self):
     '''
     Check that two consecutive loads works even
     if we delete the pickled file, and create a new object
     '''
     self._InitFromXml()
     
     # destroy the pickle file name and try to reload.
     remove(self.conf.pickleFilename)
     adp = AlbumDataParser(self.libraryPath, self.xmlFilename)
     adp.maybeLoadFromXML(self.conf)
コード例 #4
0
ファイル: makefs_test.py プロジェクト: Letractively/pytof
    def testiPhoto2(self):

        self.albumName = 'Youpi gallery'
        self.libraryPath = join('data', 'fake_iphoto_library')
        self.xmlFilename = 'AlbumData_fake_iphoto-2.xml'

        parser = AlbumDataParser(self.libraryPath, self.xmlFilename)
        self.xmlData = parser.parse()

        albumList = self.xmlData.getAlbumList()
        self.assertEquals(albumList[0], 'Youpi gallery')
        
        main(self.albumName, self.topDir, self.xmlData)
コード例 #5
0
ファイル: config_test.py プロジェクト: Letractively/pytof
    def _InitFromXml(self):
        self._InitAndSetLibrarySection()

        self.adp = AlbumDataParser(self.libraryPath, self.xmlFilename)
        self.adp.maybeLoadFromXML(self.conf)
コード例 #6
0
ファイル: config_test.py プロジェクト: Letractively/pytof
class TestConfigHandler(TestCase):

    def setUp(self):
        self.tempdir = mkdtemp()

    def tearDown(self):
        rmtree(self.tempdir)

    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)

    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)        

    def testInitAndSetLibrarySection(self):
        self._InitAndSetLibrarySection()
    
    def _InitFromXml(self):
        self._InitAndSetLibrarySection()

        self.adp = AlbumDataParser(self.libraryPath, self.xmlFilename)
        self.adp.maybeLoadFromXML(self.conf)

    def testInitFromXml(self):
        self._InitFromXml()

    def testTwoInitFromXml(self):
        '''
        Check that two consecutive loads works even
        if we delete the pickled file
        '''        
        self._InitFromXml()

        # destroy the pickle file name and try to reload.
        remove(self.conf.pickleFilename)
        self.adp.maybeLoadFromXML(self.conf)

    def testTwoInitFromXmlWithNewObject(self):
        '''
        Check that two consecutive loads works even
        if we delete the pickled file, and create a new object
        '''
        self._InitFromXml()
        
        # destroy the pickle file name and try to reload.
        remove(self.conf.pickleFilename)
        adp = AlbumDataParser(self.libraryPath, self.xmlFilename)
        adp.maybeLoadFromXML(self.conf)
コード例 #7
0
ファイル: pytofmain.py プロジェクト: Letractively/pytof
    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")