Skip to content

Commit

Permalink
Merge pull request #1303 from LipuFei/some_fixes
Browse files Browse the repository at this point in the history
Remove some torrent collecting directory related stuff
  • Loading branch information
whirm committed Mar 5, 2015
2 parents 276c578 + 0c0037f commit 1c6d755
Show file tree
Hide file tree
Showing 16 changed files with 35 additions and 118 deletions.
2 changes: 1 addition & 1 deletion Tribler/Core/APIImplementation/LaunchManyCore.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def register(self, session, sesslock, autoload_discovery=True):

# register TFTP service
from Tribler.Core.TFTP.handler import TftpHandler
self.tftp_handler = TftpHandler(self.session, self.session.get_torrent_collecting_dir(), endpoint,
self.tftp_handler = TftpHandler(self.session, u'', endpoint,
"fffffffd".decode('hex'), block_size=1024)
self.tftp_handler.initialize()

Expand Down
24 changes: 0 additions & 24 deletions Tribler/Core/CacheDB/SqliteCacheDBHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import os
import threading
from copy import deepcopy
from random import sample
from struct import unpack_from
from threading import Lock
from time import time
Expand Down Expand Up @@ -1078,31 +1077,8 @@ def freeSpace(self, torrents2del):
# sql_insert = "insert into Torrent (torrent_id, infohash, relevance) values (?,?,?)"
# self._db.executemany(sql_insert, torrent_id_infohashes)

torrent_dir = self.session.get_torrent_collecting_dir()
deleted = 0 # deleted any file?
insert_files = []
for torrent_file_name, torrent_id, relevance, weight in res_list:
torrent_path = os.path.join(torrent_dir, torrent_file_name)

if os.path.exists(torrent_path):
try:
tdef = TorrentDef.load(torrent_path)
files = [(torrent_id, unicode(path), length)
for path, length in tdef.get_files_as_unicode_with_length()]
files = sample(files, 25)
insert_files.extend(files)
except:
pass
try:
if os.path.exists(torrent_path):
os.remove(torrent_path)

deleted += 1
except WindowsError:
pass
except Exception:
print_exc()
pass

if len(insert_files) > 0:
sql_insert_files = "INSERT OR IGNORE INTO TorrentFiles (torrent_id, path, length) VALUES (?,?,?)"
Expand Down
1 change: 0 additions & 1 deletion Tribler/Core/RemoteTorrentHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ def register(self, dispersy, session, max_num_torrents):
self.session = session
self.dispersy = dispersy
self.max_num_torrents = max_num_torrents
self.tor_col_dir = self.session.get_torrent_collecting_dir()

self.torrent_db = None
if self.session.get_megacache():
Expand Down
6 changes: 0 additions & 6 deletions Tribler/Core/Session.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,6 @@ def set_and_create_dir(dirname, setter, default_dir):

state_dir = scfg.get_state_dir()
set_and_create_dir(state_dir, scfg.set_state_dir, state_dir)
# Note that we are setting it to STATEDIR_TORRENT_STORE_DIR instead of
# STATEDIR_TORRENTCOLL_DIR as that dir is unused and only kept for
# the upgrade process.
set_and_create_dir(scfg.get_torrent_collecting_dir(),
scfg.set_torrent_collecting_dir,
os.path.join(scfg.get_state_dir(), STATEDIR_TORRENT_STORE_DIR))

set_and_create_dir(scfg.get_torrent_store_dir(),
scfg.set_torrent_store_dir,
Expand Down
11 changes: 0 additions & 11 deletions Tribler/Core/TFTP/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,6 @@ def __init__(self, session, root_dir, endpoint, prefix, block_size=DEFAULT_BLOCK

self.session = session
self.root_dir = root_dir
# check the root directory if it is valid
if not os.path.exists(root_dir):
try:
os.makedirs(self.root_dir)
except OSError as ex:
self._logger.critical(u"Could not create root_dir %s: %s", root_dir, ex)
raise ex
if os.path.exists(root_dir) and not os.path.isdir(root_dir):
msg = u"root_dir is not a directory: %s" % root_dir
self._logger.critical(msg)
raise Exception(msg)

self._endpoint = endpoint
self._prefix = prefix
Expand Down
1 change: 0 additions & 1 deletion Tribler/Core/simpledefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@

STATEDIR_DLPSTATE_DIR = 'dlcheckpoints'
STATEDIR_PEERICON_DIR = 'icons'
STATEDIR_TORRENTCOLL_DIR = 'collected_torrent_files'
STATEDIR_TORRENT_STORE_DIR = 'collected_torrents'

STATEDIR_SESSCONFIG = 'libtribler.conf'
Expand Down
50 changes: 9 additions & 41 deletions Tribler/Main/tribler_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
NTFY_MYPREFERENCES, NTFY_TORRENTS, NTFY_COMMENTS, NTFY_PLAYLISTS, NTFY_DELETE,
NTFY_MODIFICATIONS, NTFY_MODERATIONS, NTFY_PEERS, NTFY_MARKINGS, NTFY_FINISHED,
NTFY_MAGNET_GOT_PEERS, NTFY_MAGNET_PROGRESS, NTFY_MAGNET_STARTED,
NTFY_MAGNET_CLOSE, STATEDIR_TORRENTCOLL_DIR, dlstatus_strings,
NTFY_MAGNET_CLOSE, dlstatus_strings,
DLSTATUS_STOPPED_ON_ERROR, DLSTATUS_DOWNLOADING, DLSTATUS_SEEDING,
DLSTATUS_STOPPED, NTFY_DISPERSY, NTFY_STARTED)
from Tribler.Core.Session import Session
Expand Down Expand Up @@ -383,20 +383,13 @@ def InitStage1(self, installdir, autoload_discovery=True):
new_dest_dir = dlg.GetPath()
defaultDLConfig.set_dest_dir(new_dest_dir)
defaultDLConfig.save(dlcfgfilename)
self.sconfig.set_torrent_collecting_dir(os.path.join(new_dest_dir, STATEDIR_TORRENTCOLL_DIR))
self.sconfig.save(cfgfilename)
else:
# Quit
self.onError = lambda e: self._logger.error(
"tribler: quitting due to non-existing destination directory")
raise Exception()

# Setting torrent collection dir based on default download dir
if not self.sconfig.get_torrent_collecting_dir():
self.sconfig.set_torrent_collecting_dir(
os.path.join(defaultDLConfig.get_dest_dir(),
STATEDIR_TORRENTCOLL_DIR))

if FORCE_ENABLE_TUNNEL_COMMUNITY:
self.sconfig.set_tunnel_community_enabled(True)

Expand Down Expand Up @@ -668,13 +661,8 @@ def sesscb_states_callback(self, dslist):
dlg.Destroy()

# Pass DownloadStates to libaryView
no_collected_list = []
no_collected_list = [ds for ds in dslist]
try:
coldir = os.path.basename(os.path.abspath(self.utility.session.get_torrent_collecting_dir()))
for ds in dslist:
destdir = os.path.basename(ds.get_download().get_dest_dir())
if destdir != coldir:
no_collected_list.append(ds)
# Arno, 2012-07-17: Retrieving peerlist for the DownloadStates takes CPU
# so only do it when needed for display.
wantpeers.extend(self.guiUtility.library_manager.download_state_callback(no_collected_list))
Expand All @@ -697,15 +685,12 @@ def sesscb_states_callback(self, dslist):
download = ds.get_download()
tdef = download.get_def()

coldir = os.path.basename(os.path.abspath(self.utility.session.get_torrent_collecting_dir()))
destdir = os.path.basename(download.get_dest_dir())
if destdir != coldir:
infohash = tdef.get_infohash()
infohash = tdef.get_infohash()

notifier = Notifier.getInstance()
notifier.notify(NTFY_TORRENTS, NTFY_FINISHED, infohash, safename)
notifier = Notifier.getInstance()
notifier.notify(NTFY_TORRENTS, NTFY_FINISHED, infohash, safename)

doCheckpoint = True
doCheckpoint = True

self.prevActiveDownloads = newActiveDownloads
if doCheckpoint:
Expand Down Expand Up @@ -738,28 +723,11 @@ def sesscb_states_callback(self, dslist):
return 1.0, wantpeers

def loadSessionCheckpoint(self):
# Niels: first remove all "swift" torrent collect checkpoints
dir = self.utility.session.get_downloads_pstate_dir()
coldir = os.path.basename(os.path.abspath(self.utility.session.get_torrent_collecting_dir()))
pstate_dir = self.utility.session.get_downloads_pstate_dir()

filelist = os.listdir(dir)
filelist = os.listdir(pstate_dir)
if any([filename.endswith('.pickle') for filename in filelist]):
convertDownloadCheckpoints(dir)
filelist = os.listdir(dir)

filelist = [os.path.join(dir, filename) for filename in filelist if filename.endswith('.state')]

for file in filelist:
try:
pstate = self.utility.session.lm.load_download_pstate(file)

saveas = pstate.get('downloadconfig', 'saveas')
if saveas:
destdir = os.path.basename(saveas)
if destdir == coldir:
os.remove(file)
except:
pass
convertDownloadCheckpoints(pstate_dir)

from Tribler.Main.vwxGUI.UserDownloadChoice import UserDownloadChoice
user_download_choice = UserDownloadChoice.get_singleton()
Expand Down
2 changes: 0 additions & 2 deletions Tribler/Main/vwxGUI/SearchGridManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ def __init__(self, guiUtility):

self.guiUtility = guiUtility
self.dispersy = None
self.col_torrent_dir = None
self.connected = False

# Contains all matches for keywords in DB, not filtered by category
Expand Down Expand Up @@ -197,7 +196,6 @@ def connect(self, session, library_manager, channel_manager):
if not self.connected:
self.connected = True
self.session = session
self.col_torrent_dir = self.session.get_torrent_collecting_dir()

self.misc_db = session.open_dbhandler(NTFY_MISC)
self.metadata_db = session.open_dbhandler(NTFY_METADATA)
Expand Down
5 changes: 3 additions & 2 deletions Tribler/Main/vwxGUI/TorrentStateManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,9 @@ def create_and_seed_metadata_thumbnail(self, thumbnail_file, torrent, modificati
file_name = u"%s.%s" % (thumbnail_hash_str, fmt)

sub_file_path = os.path.join(hexlify(torrent.infohash), file_name)
sub_dir_path = os.path.join(self.session.get_torrent_collecting_dir(), hexlify(torrent.infohash))
file_path = os.path.join(self.session.get_torrent_collecting_dir(), sub_file_path)
# FIXME(lipu): fix the thumbnail path to use metadata
sub_dir_path = os.path.join(u"", hexlify(torrent.infohash))
file_path = os.path.join(u"", sub_file_path)

if not os.path.exists(sub_dir_path):
os.mkdir(sub_dir_path)
Expand Down
3 changes: 2 additions & 1 deletion Tribler/Main/vwxGUI/home.py
Original file line number Diff line number Diff line change
Expand Up @@ -968,8 +968,9 @@ def SetData(self, delayedResult):
torrents = delayedResult.get()

for torrent in torrents:
# FIXME(lipu): fix the thumbnail path to use metadata
thumb_path = os.path.join(
self.utility.session.get_torrent_collecting_dir(),
u"",
binascii.hexlify(torrent.infohash))
if os.path.isdir(thumb_path):
if not self.guiutility.getFamilyFilter() or not self.IsXXX(torrent, thumb_path):
Expand Down
6 changes: 4 additions & 2 deletions Tribler/Main/vwxGUI/list_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,8 @@ def updateDetailsTab(self):
self.channel.Show(show_channel)

# Toggle thumbnails
thumb_dir = os.path.join(self.guiutility.utility.session.get_torrent_collecting_dir(),
# FIXME(lipu): fix the thumbnail path to use metadata
thumb_dir = os.path.join(u"",
binascii.hexlify(self.torrent.infohash))
thumb_files = [os.path.join(dp, fn) for dp, _, fns in os.walk(thumb_dir)
for fn in fns if os.path.splitext(fn)[1] in THUMBNAIL_FILETYPES]
Expand Down Expand Up @@ -1655,7 +1656,8 @@ def do_gui(delayedResult):
self.playlist_torrents = delayedResult.get()
bmps = []
for torrent in self.playlist_torrents:
thumb_dir = os.path.join(self.guiutility.utility.session.get_torrent_collecting_dir(),
# FIXME(lipu): fix the thumbnail path to use metadata
thumb_dir = os.path.join(u"",
binascii.hexlify(torrent.infohash))
thumb_files = [os.path.join(dp, fn) for dp, _, fns in os.walk(thumb_dir)
for fn in fns if os.path.splitext(fn)[1] in THUMBNAIL_FILETYPES]
Expand Down
12 changes: 8 additions & 4 deletions Tribler/Main/vwxGUI/list_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,8 @@ def RefreshData(self, data):
'completed' not in self.original_data.state and 'active' not in self.original_data.state)

def SetThumbnailIcon(self):
torcoldir = self.guiutility.utility.session.get_torrent_collecting_dir()
# FIXME(lipu): fix the thumbnail path to use metadata
torcoldir = u""
rel_thumbdir = binascii.hexlify(self.original_data.infohash)
abs_thumbdir = os.path.join(torcoldir, rel_thumbdir)
has_thumbnails = os.path.exists(abs_thumbdir) and os.listdir(abs_thumbdir)
Expand Down Expand Up @@ -1043,8 +1044,9 @@ def CreateBitmaps(self):

bitmap = None

# FIXME(lipu): fix the thumbnail path to use metadata
thumb_dir = os.path.join(
self.guiutility.utility.session.get_torrent_collecting_dir(),
u"",
binascii.hexlify(self.original_data.infohash))
thumb_files = [os.path.join(dp, fn) for dp, _, fns in os.walk(thumb_dir)
for fn in fns if os.path.splitext(fn)[1] in THUMBNAIL_FILETYPES]
Expand Down Expand Up @@ -1388,8 +1390,9 @@ def AddComponents(self, leftSpacer, rightSpacer):
self.guiutility = GUIUtility.getInstance()
self.session = self.guiutility.utility.session

# FIXME(lipu): fix the thumbnail path to use metadata
thumb_dir = os.path.join(
self.session.get_torrent_collecting_dir(),
u"",
binascii.hexlify(modification.torrent.infohash))
self.body = []
if os.path.exists(thumb_dir):
Expand Down Expand Up @@ -1462,8 +1465,9 @@ def AddComponents(self, leftSpacer, rightSpacer):
self.guiutility = GUIUtility.getInstance()
self.session = self.guiutility.utility.session

# FIXME(lipu): fix the thumbnail path to use metadata
thumb_dir = os.path.join(
self.session.get_torrent_collecting_dir(),
u"",
binascii.hexlify(modification.torrent.infohash))
self.body = []
if os.path.exists(thumb_dir):
Expand Down
9 changes: 1 addition & 8 deletions Tribler/Main/vwxGUI/settingsDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from Tribler.Core.Session import Session
from Tribler.Core.SessionConfig import SessionStartupConfig
from Tribler.Core.osutils import get_picture_dir
from Tribler.Core.simpledefs import UPLOAD, DOWNLOAD, STATEDIR_TORRENTCOLL_DIR
from Tribler.Core.simpledefs import UPLOAD, DOWNLOAD
from Tribler.Core.DownloadConfig import get_default_dscfg_filename
from Tribler.Main.globals import DefaultDownloadStartupConfig
from Tribler.Main.vwxGUI.GuiImageManager import GuiImageManager, data2wxBitmap, ICON_MAX_DIM
Expand Down Expand Up @@ -349,14 +349,7 @@ def saveDefaultDownloadConfig(self, scfg):
self.defaultDLConfig.save(dlcfgfilename)

# Save SessionStartupConfig
# Also change torrent collecting dir, which is by default in the default destdir
cfgfilename = Session.get_default_config_filename(state_dir)
defaultdestdir = self.defaultDLConfig.get_dest_dir()
for target in [scfg, self.utility.session]:
try:
target.set_torrent_collecting_dir(os.path.join(defaultdestdir, STATEDIR_TORRENTCOLL_DIR))
except:
self._logger.exception("Could not set target torrent collecting dir")

scfg.save(cfgfilename)

Expand Down
5 changes: 2 additions & 3 deletions Tribler/Test/test_metadata_community.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# see LICENSE.txt for license information

import os
import sys
import json
import time
from unittest.case import skip
Expand Down Expand Up @@ -47,8 +46,8 @@ def check_for_modifications():
5, do_overview), 'No valid channel modifications received')

def do_thumbnails(torrentfilename):
thumb_dir = os.path.join(
self.session.get_torrent_collecting_dir(), '8bb88a02da691636a7ed929b87d467f24700e490')
# FIXME(lipu): fix the thumbnail path to use metadata
thumb_dir = os.path.join(u"", '8bb88a02da691636a7ed929b87d467f24700e490')
self.CallConditional(120, lambda: os.path.isdir(thumb_dir) and len(
os.listdir(thumb_dir)) > 0, lambda: do_modifications(torrentfilename), 'No thumbnails were created')

Expand Down
11 changes: 5 additions & 6 deletions Tribler/Test/test_remote_torrent_handler.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# see LICENSE.txt for license information

import os
import sys
from shutil import copyfile, rmtree, copytree
from shutil import rmtree, copytree
from time import sleep
from threading import Event

Expand Down Expand Up @@ -108,7 +107,7 @@ def test_metadatadownload(self):
self._logger.info(u"Start metadata download test...")

def do_check_download(torrent_file=None):
des_file_path = os.path.join(self.session2.get_torrent_collecting_dir(), self.metadata_dir)
des_file_path = os.path.join(u"", self.metadata_dir)
self.assertTrue(os.path.exists(des_file_path) and os.path.isdir(des_file_path),
u"Failed to download metadata.")

Expand Down Expand Up @@ -141,8 +140,8 @@ def setup_metadatadownloader(self):

# copy file to the uploader's torrent_collecting_dir
src_dir_path = os.path.join(BASE_DIR, u"data", self.metadata_dir)
des_dir_path = os.path.join(self.session.get_torrent_collecting_dir(), self.metadata_dir)
self._logger.info(u"Uploader's torrent_collect_dir = %s", self.session.get_torrent_collecting_dir())
des_dir_path = os.path.join(u"", self.metadata_dir)
self._logger.info(u"Uploader's torrent_collect_dir = %s", u"")
copytree(src_dir_path, des_dir_path)

from Tribler.Core.Session import Session
Expand All @@ -164,6 +163,6 @@ def setup_metadatadownloader(self):
self.session2.start()
sleep(1)

self._logger.info(u"Downloader's torrent_collect_dir = %s", self.session2.get_torrent_collecting_dir())
self._logger.info(u"Downloader's torrent_collect_dir = %s", u"")
self._logger.info(u"Uploader port: %s, Downloader port: %s",
self.session1_port, self.session2.get_dispersy_port())
Loading

0 comments on commit 1c6d755

Please sign in to comment.