Exemple #1
0
def set_cache(cache_id, content):
    '''Set a value in the cache'''

    mkdir_p(settings.CACHE_DIR)

    cache_file = os.path.join(settings.CACHE_DIR, cache_id)
    with open(cache_file, 'wb') as f:
        pickle.dump(content, f)
Exemple #2
0
    def dump_processing_stats(self):
        '''Write down the status of objects currently loaded by tests in a HTML file'''

        c = self.client
        response = c.get('/status')

        mkdir_p(settings.COVERAGE_REPORT_HTML_OUTPUT_DIR)
        with open(os.path.join(settings.COVERAGE_REPORT_HTML_OUTPUT_DIR, "completion.html"), 'w') as f:
            f.write(response.content)
Exemple #3
0
            def open_url(url):
                url_id = url.replace('/', '_')
                cache_path = os.path.join(settings.CACHE_DIR, url_id)

                # TVDB's parsing really wants a fp to an actual file
                # Instead of using get/set_cache, prepare the file directly
                mkdir_p(settings.CACHE_DIR)
                if not os.path.isfile(cache_path):
                    cache_fp = default_open_url(url)
                    with open(cache_path, 'w') as f:
                        f.write(cache_fp.read())

                return open(cache_path)
Exemple #4
0
            def update_queued_torrents(self):
                for torrent in Torrent.objects.filter(status='Queued'):
                    # Mark directly as completed only if enough seeds
                    if torrent.seeds < 1:
                        torrent.status = 'Error'
                        torrent.save()
                    
                    torrent.status = 'Completed'
                    torrent.save()

                    # Iterate over each of the torrent files
                    for torrent_file_info in json.loads(torrent.file_list):
                        torrent_file = os.path.join(settings.TEST_DOWNLOAD_DIR, torrent_file_info['path'])
                        mkdir_p(os.path.split(torrent_file)[0])
                        
                        # Fill the files with fake data, to keep file sizes poportional
                        with open(torrent_file, 'w') as f: 
                            f.write('#' * (torrent_file_info['size']/1000)) 
Exemple #5
0
    def test_find_single_episode_in_single_file_season_torrent_error(self):
        """When an season torrent is a single file, fail racefully when looking for a single episode"""

        filename='Test.avi'

        # Fake episode
        episode = Episode(number=1, tvdb_id=1, name='Test episode')
        episode.season = self.create_fake_season(name='Test series')
        episode.torrent = Torrent(hash='aaaa', name=filename, type='season', status='Completed')
        episode.torrent.save()
        episode.save()

        # Create torrent file
        mkdir_p(settings.TEST_DOWNLOAD_DIR)
        settings.DOWNLOAD_DIR = settings.TEST_DOWNLOAD_DIR
        shutil.copy2(settings.TEST_VIDEO_PATH, os.path.join(settings.TEST_DOWNLOAD_DIR, filename))

        episode.get_or_create_video()

        # Check that the season/episode/video was found
        self.api_check('video', 1, { 'status': 'Not found' })
Exemple #6
0
    def create_torrent_dir(self, name):
        '''Create torrent directory in the test download dir'''

        mkdir_p(settings.TEST_DOWNLOAD_DIR)
        mkdir_p(os.path.join(settings.TEST_DOWNLOAD_DIR, name))
        settings.DOWNLOAD_DIR = settings.TEST_DOWNLOAD_DIR