コード例 #1
0
ファイル: utils_test.py プロジェクト: Letractively/pytof
    def testTar(self):
        '''
        Create an archve from a temp dir created with create_dummy_dir
        put one file at the prefix level, tar the archive
        extract the archive, and check that the file is there and
        that its size is the same as the original one.

        FIXME: we should check for other files at other levels in the tar hierarchy.
        '''
        
        dummyDir = self.create_dummy_dir('tar_test_dir')
        tmpftpfile = 'level_2_fileA'
        topLevelFile = join(dummyDir, tmpftpfile)
        topLevelFileSize = getsize(topLevelFile)
        
        tarFile = join(self.tempdir, 'foo.tar')
        mkarchive(tarFile, dummyDir, 'a_dir', [topLevelFile], Zip = False, tar = True)

        # now list the file within the archive and look for topLevelFile
        tar = tarfile.open(tarFile)
        found = False
        for tarinfo in tar:
            if tarinfo.name == tmpftpfile:
                found = True
                size = tarinfo.size
                break

        self.assert_(found)
        self.assertEquals(size, topLevelFileSize)
コード例 #2
0
ファイル: utils_test.py プロジェクト: Letractively/pytof
 def testZip(self):
     dummyDir = self.create_dummy_dir('tar_test_dir')
     tmpftpfile = 'level_2_fileA'
     topLevelFile = join(dummyDir, tmpftpfile)
     topLevelFileSize = getsize(topLevelFile)
     
     zipFile = join(self.tempdir, 'foo.zip')
     mkarchive(zipFile, dummyDir, 'a_dir', [topLevelFile])
     # you also have printdirs to have a ls like output
     # of the content of the zip file
     self.assert_(tmpftpfile in ZipFile(zipFile).namelist())
コード例 #3
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")