Example #1
0
 def test_cache_iterator(self):
     """Test that files added to the cache show up in the iterator
     and are accessed correctly via 'in'
     """
     cache = pdk.cache.Cache(os.path.join(self.work_dir, 'cache'))
     make_path_to(cache.file_path('sha-1:someotherid'))
     open(cache.file_path('sha-1:someotherid'), 'w')\
             .write('helloalso')
     make_path_to(cache.file_path('md5:yetanotherid'))
     open(cache.file_path('md5:yetanotherid'), 'w') \
             .write('helloalso')
     contents = [x for x in cache]
     assert 'sha-1:someotherid' in cache
     assert 'sha-1:someotherid' in contents
     assert 'md5:yetanotherid' in cache
     assert 'md5:yetanotherid' in contents
Example #2
0
 def test_cache_iterator(self):
     """Test that files added to the cache show up in the iterator
     and are accessed correctly via 'in'
     """
     cache = pdk.cache.Cache(os.path.join(self.work_dir, 'cache'))
     make_path_to(cache.file_path('sha-1:someotherid'))
     open(cache.file_path('sha-1:someotherid'), 'w')\
             .write('helloalso')
     make_path_to(cache.file_path('md5:yetanotherid'))
     open(cache.file_path('md5:yetanotherid'), 'w') \
             .write('helloalso')
     contents = [ x for x in cache ]
     assert 'sha-1:someotherid' in cache
     assert 'sha-1:someotherid' in contents
     assert 'md5:yetanotherid' in cache
     assert 'md5:yetanotherid' in contents
Example #3
0
    def _add_links(self, source, blob_ids):
        '''Create visible links to the blob contained in source.

        Assume the blob_ids are correct.
        '''
        seed = self.make_download_filename()
        try:
            # optimization opportunity
            # we could attempt linking directly from source
            # to visible link to save on a copy here.
            copy2(source, seed)
            for blob_id in blob_ids:
                filename = self.file_path(blob_id)
                if os.path.exists(filename):
                    continue
                make_path_to(filename)
                os.link(seed, filename)
        finally:
            os.unlink(seed)
Example #4
0
    def _add_links(self, source, blob_ids):
        '''Create visible links to the blob contained in source.

        Assume the blob_ids are correct.
        '''
        seed = self.make_download_filename()
        try:
            # optimization opportunity
            # we could attempt linking directly from source
            # to visible link to save on a copy here.
            copy2(source, seed)
            for blob_id in blob_ids:
                filename = self.file_path(blob_id)
                if os.path.exists(filename):
                    continue
                make_path_to(filename)
                os.link(seed, filename)
        finally:
            os.unlink(seed)