file filtering

This commit is contained in:
Alon Zakai 2006-12-05 19:41:57 +00:00
parent cbd8f6bad2
commit 9e36eb21f5
2 changed files with 32 additions and 22 deletions

View File

@ -85,7 +85,7 @@ class torrent_info:
self.user_paused = False # start out unpaused
self.uploaded_memory = 0
self.filter_out = []
self.file_filter = []
self.delete_me = False # set this to true, to delete it on next sync
@ -125,7 +125,7 @@ class manager:
self.constants = pytorrent_core.constants()
# Unique IDs are NOT in the state, since they are temporary for each session
self.unique_IDs = {} # unique_ID -> a torrent object, i.e. persistent data
self.unique_IDs = {} # unique_ID -> a torrent_info object, i.e. persistent data
# Saved torrent core_states. We do not poll the core in a costly manner, necessarily
self.saved_torrent_core_states = {} # unique_ID -> torrent_state
@ -163,6 +163,9 @@ class manager:
# Sync with the core: tell core about torrents, and get unique_IDs
self.sync()
# Apply all the file filters, right after adding the torrents
self.apply_all_file_filters()
except IOError:
self.state = persistent_state()
else:
@ -360,6 +363,30 @@ class manager:
return ret
# Filtering functions
def set_file_filter(self, unique_ID, file_filter):
assert(len(file_filter) == self.get_torrent_core_state(unique_ID, True))
self.unique_IDs[unique_ID].file_filter = file_filter[:]
pytorrent_core.set_filter_out(file_filter)
def get_file_filter(self, unique_ID):
try:
return self.unique_IDs[unique_ID].file_filter[:]
except AttributeError:
return None
# Call this when a session starts, to apply existing filters
def apply_all_file_filters(self):
for unique_ID in unique_IDs.keys():
try:
self.set_file_filter(self.unique_IDs[unique_ID].file_filter)
except AttributeError:
pass
# Miscellaneous minor functions
def set_user_pause(self, unique_ID, new_value):

View File

@ -549,24 +549,6 @@ static PyObject *torrent_resume(PyObject *self, PyObject *args)
Py_INCREF(Py_None); return Py_None;
}
static PyObject *torrent_get_torrent_info(PyObject *self, PyObject *args)
{
python_long unique_ID;
if (!PyArg_ParseTuple(args, "i", &unique_ID))
return NULL;
long index = get_index_from_unique_ID(unique_ID);
if (PyErr_Occurred())
return NULL;
torrent_t &t = M_torrents->at(index);
return Py_BuildValue("{s:s,s:l}",
"name", t.handle.get_torrent_info().name().c_str(),
"num_files", t.handle.get_torrent_info().num_files()
);
}
static PyObject *torrent_get_torrent_state(PyObject *self, PyObject *args)
{
python_long unique_ID;
@ -593,7 +575,9 @@ static PyObject *torrent_get_torrent_state(PyObject *self, PyObject *args)
else
total_peers++;
return Py_BuildValue("{s:l,s:l,s:l,s:f,s:f,s:d,s:f,s:l,s:l,s:s,s:s,s:f,s:d,s:l,s:l,s:l,s:d,s:l,s:l,s:l,s:l,s:l,s:l,s:d,s:d,s:l,s:l}",
return Py_BuildValue("{s:s,s:l,s:l,s:l,s:l,s:f,s:f,s:d,s:f,s:l,s:l,s:s,s:s,s:f,s:d,s:l,s:l,s:l,s:d,s:l,s:l,s:l,s:l,s:l,s:l,s:d,s:d,s:l,s:l}",
"name", t.handle.get_torrent_info().name().c_str(),
"num_files", t.handle.get_torrent_info().num_files()
"state", s.state,
"num_peers", s.num_peers,
"num_seeds", s.num_seeds,
@ -1184,7 +1168,6 @@ static PyMethodDef pytorrent_core_methods[] = {
{"reannounce", torrent_reannounce, METH_VARARGS, "."},
{"pause", torrent_pause, METH_VARARGS, "."},
{"resume", torrent_resume, METH_VARARGS, "."},
{"get_torrent_info", torrent_get_torrent_info, METH_VARARGS, "."},
{"get_torrent_state", torrent_get_torrent_state, METH_VARARGS, "."},
{"pop_event", torrent_pop_event, METH_VARARGS, "."},
{"get_session_info", torrent_get_session_info, METH_VARARGS, "."},