コード例 #1
0
ファイル: download.py プロジェクト: sww/itchynzb
def download(files, settings):
    temp_dir = settings['temp_dir']
    download_path = settings['download_path']

    download = DownloadPool(settings)
    decode = Decode()
    pool = GreenPool(settings['connections'])
    progress_tracker = greenthread.spawn(show_progress)

    for file_ in files:
        # Check if file from subject exists.
        subject_filename = helper.get_filename_from(file_['file_subject'])

        if helper.file_exists(download_path, subject_filename):
            Tracker.total_size -= sum([i['segment_bytes'] for i in file_['segments']])
            print subject_filename, 'already exists'
            continue

        # Download.
        for segment_path in pool.imap(download.download, file_['segments']):
            # Decode.
            if segment_path:
                tpool.execute(decode.decode, segment_path, temp_dir, download_path)

    if decode.tracker:
        print 'have broken files...'
        #return False
        print decode.tracker
        broken_files = decode.tracker.keys()
        for fname in broken_files:
            #print 'decoding', fname
            decode.join_files(fname, temp_dir, download_path)

    #progress_tracker.kill()
    progress_tracker.wait()

    # All OK.
    return 0
コード例 #2
0
ファイル: test_common.py プロジェクト: sww/itchynzb
 def test_file_exists(self):
     self.assertTrue(helper.file_exists('.', 'test_common.py'))
     self.assertFalse(helper.file_exists('.', 'nosuch file'))