#NEWLINE# @ celery . task #NEWLINE# def process_torrent( torrent_file , torrent_uuid ) : #NEWLINE# #INDENT# '\n    Receives a torrent file from the job queue and decodes it into a python object.\n    Once it is a python object it proceeds to add the database records that make up a Forked Tongue torrent.\n    after all the data has been checked and added to the database, the torrent uuid is pushed for announce to connected\n    clients.\n    ' #NEWLINE# from torrents.models import Files , Torrent #NEWLINE# torrent_data = bencode . bdecode ( torrent_file ) #NEWLINE# torrent_record = Torrent . objects . get ( pk = torrent_uuid ) #NEWLINE# if Files . objects . filter ( torrent = torrent_record ) . exists ( ) : #NEWLINE# #INDENT# Files . objects . filter ( torrent = torrent_record ) . delete ( ) #NEWLINE# #UNINDENT# if ( 'files' in single_file [ 'info' ] ) : #NEWLINE# #INDENT# for single_file in torrent_data [ 'info' ] [ 'files' ] : #NEWLINE# #INDENT# file_record = Files ( torrent = torrent_record , filename = single_file [ 'path' ] [ 0 ] , filesize = single_file [ 'length' ] ) #NEWLINE# file_record . save ( ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# file_record = Files ( torrent = torrent_record , filename = torrent_data [ 'info' ] [ 'name' ] , filesize = torrent_data [ 'info' ] [ 'length' ] ) #NEWLINE# file_record . save ( )