summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKostyantyn Ovechko <fastinetserver@gmail.com>2010-07-30 22:41:21 +0300
committerKostyantyn Ovechko <fastinetserver@gmail.com>2010-07-30 22:41:21 +0300
commit7c6f655c2e65eb0644ecec6f1bd508c954862711 (patch)
treefafb1f2a5baffe65e765b0a05d92b48ad561aa64 /segget/distfile.cpp
parentAdd options: GENERAL_LOG_TIME_FORMAT, ERROR_LOG_TIME_FORMAT and DEBUG_LOG_TIM... (diff)
downloadidfetch-7c6f655c2e65eb0644ecec6f1bd508c954862711.tar.gz
idfetch-7c6f655c2e65eb0644ecec6f1bd508c954862711.tar.bz2
idfetch-7c6f655c2e65eb0644ecec6f1bd508c954862711.zip
Add [scripting_and_scheduling] section to segget.conf file.
[scripting_and_scheduling] Segget provides Python scripting functionalyty to support scheduling. Each time segget tries to start a new connection certain network it calls a python script (client.py) to accept or reject this connection and if necessary adjusts its settings. PYTHON_PATH Define path to python Default: python_path=/usr/bin/python SCRIPTS_DIR Define a path to the dir with python scripts. Before establishing connection for a particular segment via network# segget checks SCRIPTS_DIR. If SCRIPTS_DIR contains net#.py file, segget will launch schedule() function from this file to apply settings for connetion and accept or reject this segment for the moment. net#.py file is a python script file with a user-writen schedule() function. It's necessary to import functions before using get("variable"), set("variable",value), accept_segment() and reject_segment() in schedule(). get() function can obtain values for the following variables: connection.num, connection.url, connection.max_speed_limit, network.num, network.mode, network.active_connections_count, distfile.name, distfile.size, distfile.dld_segments_count, distfile.segments_count, distfile.active_connections_count, segment.num, segment.try_num, segment.size, segment.range set() function can change connection.max_speed_limit, see example: -----------------EXAMPLE STARTS----------------- from functions import * import time; def schedule(): localtime = time.localtime(time.time()); hour=localtime[3]; # disable downloading distfiles that have size more than 5 000 000 bytes # from 8-00 to 22-00. if hour>8 and hour<22 and (get("distfile.size"))>5000000: print "reject because distfile is too big" reject_segment() # set speed limit 50 000 cps for distfiles larger than 1 000 000 bytes if get("distfile.size")>1000000: print "limit connection speed" set(connection.max_speed_limit, 50000) accept_segment() -----------------EXAMPLE ENDS----------------- From example above localtime returns following tuple: Index Attributes Values 0 tm_year e.i.: 2008 1 tm_mon 1 to 12 2 tm_mday 1 to 31 3 tm_hour 0 to 23 4 tm_min 0 to 59 5 tm_sec 0 to 61 (60 or 61 are leap-seconds) 6 tm_wday 0 to 6 (0 is Monday) 7 tm_yday 1 to 366 (Julian day) 8 tm_isdst -1, 0, 1, -1 means library determines DST Therefore localtime[3] provides hours. Segment will be accecpted by default if it was neither accepted nor rejected during the schedule() function. sagget saves logs of resulting stdout and stderr in the log folder separatly for each network. Hence, if there's an error in net3.py file python error message would be saved to net3_script_stderr.log. Results of print would be saved in net3_script_stdout.log. Default: scripts_dir=./scripts SCRIPT_SOCKET_PATH Segget uses AF_UNIX domain sockets for communication with python. Specify path for the socket on your filesystem. Default: script_socket_path=/tmp/segget_script_socket
Diffstat (limited to 'segget/distfile.cpp')
-rw-r--r--segget/distfile.cpp15
1 files changed, 12 insertions, 3 deletions
diff --git a/segget/distfile.cpp b/segget/distfile.cpp
index 11b7be7..4f56bbe 100644
--- a/segget/distfile.cpp
+++ b/segget/distfile.cpp
@@ -340,8 +340,12 @@ bool Tdistfile::choose_best_mirror(CURLM* cm, uint connection_num, uint network_
debug("Downloading from BEST_MIRROR:"+url_str);
// Pbest_mirror->start();
// active_connections_num++;
- connection_array[connection_num].start(cm, network_num, num, &dn_segments[seg_num], best_mirror_num);
- return R_R_DOWNLOAD_STARTED;
+ int result=connection_array[connection_num].start(cm, network_num, num, &dn_segments[seg_num], best_mirror_num);
+ if (result){
+ return result;
+ }else{
+ return R_R_DOWNLOAD_STARTED;
+ }
}
else{
error_log("Can't choose mirror for segment:"+dn_segments[seg_num].file_name);
@@ -384,7 +388,12 @@ bool Tdistfile::choose_best_local_mirror(CURLM* cm, uint connection_num, uint ne
if (best_mirror_num!=-1){
debug("Downloading from BEST_LOCAL_MIRROR:"+network_array[network_num].benchmarked_mirror_list[best_mirror_num].url);
// active_connections_num++;
- connection_array[connection_num].start(cm, network_num, num, &dn_segments[seg_num], best_mirror_num);
+ int result=connection_array[connection_num].start(cm, network_num, num, &dn_segments[seg_num], best_mirror_num);
+ if (result){
+ return result;
+ }else{
+ return R_R_DOWNLOAD_STARTED;
+ }
return R_R_DOWNLOAD_STARTED;
}
else{