def init_sync_instance_db(instance): b_torrents = instance.get_b_torrents_by_hash() t_torrents = instance.get_t_torrents_by_hash( BibliotikTransTorrent.sync_t_arguments) with transaction.atomic(): for c_hash, t_torrent in t_torrents.items(): if c_hash not in b_torrents: try: bibliotik_torrent = BibliotikTorrent.objects.get( info_hash=c_hash) d_location = DownloadLocation.get_by_full_path( t_torrent.downloadDir) b_torrent = manage_bibliotik.add_bibliotik_torrent( bibliotik_torrent.id, instance, d_location, add_to_client=False) b_torrents[b_torrent.info_hash] = b_torrent except BibliotikTorrent.DoesNotExist: raise Exception(u'Could not find hash {0} for name {1} in ' u'DB during initial sync.'.format( c_hash, t_torrent.name)) b_torrent = b_torrents[c_hash] b_torrent.sync_t_torrent(t_torrent)
def init_sync_instance_db(instance): mam_torrents = instance.get_mam_torrents_by_hash() t_torrents = instance.get_t_torrents_by_hash(MAMTransTorrent.sync_t_arguments) with transaction.atomic(): for c_hash, t_torrent in t_torrents.items(): if c_hash not in mam_torrents: try: mam_torrent = MAMTorrent.objects.get(info_hash=c_hash) d_location = DownloadLocation.get_by_full_path(t_torrent.downloadDir) mam_torrent = manage_mam.add_mam_torrent( mam_torrent.id, instance, d_location, add_to_client=False ) mam_torrents[mam_torrent.info_hash] = mam_torrent except MAMTorrent.DoesNotExist: raise Exception(u'Could not find hash {0} for name {1} in ' u'DB during initial sync.' .format(c_hash, t_torrent.name)) mam_torrent = mam_torrents[c_hash] mam_torrent.sync_t_torrent(t_torrent)
def init_sync_instance_db(instance): b_torrents = instance.get_b_torrents_by_hash() t_torrents = instance.get_t_torrents_by_hash(BibliotikTransTorrent.sync_t_arguments) with transaction.atomic(): for c_hash, t_torrent in t_torrents.items(): if not c_hash in b_torrents: try: bibliotik_torrent = BibliotikTorrent.objects.get(info_hash=c_hash) d_location = DownloadLocation.get_by_full_path(t_torrent.downloadDir) b_torrent = manage_bibliotik.add_bibliotik_torrent( bibliotik_torrent.id, instance, d_location, add_to_client=False ) b_torrents[b_torrent.info_hash] = b_torrent except BibliotikTorrent.DoesNotExist: raise Exception(u'Could not find hash {0} for name {1} in DB during initial sync.'.format( c_hash, t_torrent.name )) b_torrent = b_torrents[c_hash] b_torrent.sync_t_torrent(t_torrent)
def sync_instance_db(request, instance): m_torrents = instance.get_m_torrents_by_hash() t_torrents = instance.get_t_torrents_by_hash(TransTorrent.sync_t_arguments) for hash, m_torrent in m_torrents.items(): if hash not in t_torrents: m_torrent_path = m_torrent.path.encode('utf-8') messages = [] with transaction.atomic(): m_torrent.delete() del m_torrents[hash] if instance.replica_set.is_master: if os.path.exists(m_torrent_path): files = os.listdir(m_torrent_path) if any(f for f in files if '.torrent' not in f and 'ReleaseInfo2.txt' != f): messages.append( u'There are other files so leaving in place.') else: messages.append( u'No other files. Deleting directory.') shutil.rmtree(m_torrent_path) else: messages.append(u'Path does not exist.') LogEntry.add( None, u'action', u'Torrent {0} deleted from instance {1}. {2}'.format( m_torrent, instance, ' '.join(messages))) with transaction.atomic(): for hash, t_torrent in t_torrents.items(): if hash not in m_torrents: w_torrent = WhatTorrent.get_or_create(request, info_hash=hash) d_location = DownloadLocation.get_by_full_path( t_torrent.downloadDir) m_torrent = manage_torrent.add_torrent(request, instance, d_location, w_torrent.id, False) m_torrents[m_torrent.info_hash] = m_torrent LogEntry.add( None, u'action', u'Torrent {0} appeared in instance {1}. Added to DB.'. format(m_torrent, instance)) m_torrent = m_torrents[hash] m_torrent.sync_t_torrent(t_torrent) if (SYNC_SYNCS_FILES or 'sync_files' in request.GET) and instance.replica_set.is_master: m_torrent.sync_files()
def sync_instance_db(instance): b_torrents = instance.get_b_torrents_by_hash() t_torrents = instance.get_t_torrents_by_hash( BibliotikTransTorrent.sync_t_arguments) for c_hash, b_torrent in b_torrents.items(): if c_hash not in t_torrents: b_torrent_path = b_torrent.path.encode('utf-8') messages = [] with transaction.atomic(): b_torrent.delete() del b_torrents[c_hash] if instance.replica_set.is_master: if os.path.exists(b_torrent_path): files = os.listdir(b_torrent_path) if len(files): messages.append( u'There are other files so leaving in place.') else: messages.append( u'No other files. Deleting directory.') os.rmdir(b_torrent_path) else: messages.append(u'Path does not exist.') LogEntry.add( None, u'action', u'Bibliotik torrent {0} deleted from instance {1}. {2}'.format( b_torrent, instance, ' '.join(messages))) with transaction.atomic(): for c_hash, t_torrent in t_torrents.items(): if c_hash not in b_torrents: torrent_id = int(os.path.basename(t_torrent.downloadDir)) w_torrent = BibliotikTorrent.get_or_create(None, torrent_id) d_location = DownloadLocation.get_by_full_path( t_torrent.downloadDir) m_torrent = manage_bibliotik.add_bibliotik_torrent( w_torrent.id, instance, d_location, None, False) b_torrents[m_torrent.info_hash] = m_torrent LogEntry.add( None, u'action', u'Bibliotik torrent {0} appeared in instance {1}.'.format( t_torrent.name, instance)) else: b_torrent = b_torrents[c_hash] b_torrent.sync_t_torrent(t_torrent)
def sync_instance_db(instance): mam_torrents = instance.get_mam_torrents_by_hash() t_torrents = instance.get_t_torrents_by_hash(MAMTransTorrent.sync_t_arguments) for c_hash, mam_torrent in mam_torrents.items(): if c_hash not in t_torrents: mam_torrent_path = mam_torrent.path.encode('utf-8') messages = [] with transaction.atomic(): mam_torrent.delete() del mam_torrents[c_hash] if instance.replica_set.is_master: if os.path.exists(mam_torrent_path): files = os.listdir(mam_torrent_path) if len(files): messages.append(u'There are other files so leaving in place.') else: messages.append(u'No other files. Deleting directory.') os.rmdir(mam_torrent_path) else: messages.append(u'Path does not exist.') LogEntry.add(None, u'action', u'MAM torrent {0} deleted from instance {1}. {2}' .format(mam_torrent, instance, ' '.join(messages))) with transaction.atomic(): for c_hash, t_torrent in t_torrents.items(): if c_hash not in mam_torrents: torrent_id = int(os.path.basename(t_torrent.downloadDir)) w_torrent = MAMTorrent.get_or_create(None, torrent_id) d_location = DownloadLocation.get_by_full_path(t_torrent.downloadDir) m_torrent = manage_mam.add_mam_torrent(w_torrent.id, instance, d_location, None, False) mam_torrents[m_torrent.info_hash] = m_torrent LogEntry.add(None, u'action', u'MAM torrent {0} appeared in instance {1}.' .format(t_torrent.name, instance)) else: mam_torrent = mam_torrents[c_hash] mam_torrent.sync_t_torrent(t_torrent)
def sync_instance_db(request, instance): m_torrents = instance.get_m_torrents_by_hash() t_torrents = instance.get_t_torrents_by_hash(TransTorrent.sync_t_arguments) for hash, m_torrent in m_torrents.items(): if hash not in t_torrents: m_torrent_path = m_torrent.path.encode('utf-8') messages = [] with transaction.atomic(): m_torrent.delete() del m_torrents[hash] if instance.replica_set.is_master: if os.path.exists(m_torrent_path): files = os.listdir(m_torrent_path) if any(f for f in files if '.torrent' not in f and 'ReleaseInfo2.txt' != f): messages.append(u'There are other files so leaving in place.') else: messages.append(u'No other files. Deleting directory.') shutil.rmtree(m_torrent_path) else: messages.append(u'Path does not exist.') LogEntry.add(None, u'action', u'Torrent {0} deleted from instance {1}. {2}' .format(m_torrent, instance, ' '.join(messages))) with transaction.atomic(): for hash, t_torrent in t_torrents.items(): if hash not in m_torrents: w_torrent = WhatTorrent.get_or_create(request, info_hash=hash) d_location = DownloadLocation.get_by_full_path(t_torrent.downloadDir) m_torrent = manage_torrent.add_torrent(request, instance, d_location, w_torrent.id, False) m_torrents[m_torrent.info_hash] = m_torrent LogEntry.add(None, u'action', u'Torrent {0} appeared in instance {1}. Added to DB.' .format(m_torrent, instance)) m_torrent = m_torrents[hash] m_torrent.sync_t_torrent(t_torrent) if (SYNC_SYNCS_FILES or 'sync_files' in request.GET) and instance.replica_set.is_master: m_torrent.sync_files()