pass
# 26.456787 -> 26 (seconds)
def tribler_canon_eta(non_canon_value):
- return int(float(non_canon_value))
+ if non_canon_value != 'None':
+ return int(float(non_canon_value))
+ return None
+""" Get date and timestamp and transform it into datetime format.
+ Format: dd-mm-yyyy hh:mm:ss
+"""
+def tribler_parse_timestamp(date, time):
+
+ date_array = date.split("-");
+ time_array = time.split(":");
+ if len(date_array) != 3 or len(time_array) != 3:
+ return None
+
+ timestamp = datetime.datetime(int(date_array[2]), int(date_array[1]), int(date_array[0]), #year, month, day
+ int(time_array[0]), int(time_array[1]), int(time_array[2])) #hour, min, sec
+ return timestamp
#
# sample tribler status line
-# 03 Nov 2009 12:18:55 aqua.mpeg DLSTATUS_DOWNLOADING 29.84% None up 0.00KB/s down 4414.39KB/s eta 12 peers 2
+# 03-Nov-2009 12:18:55 aqua.mpeg DLSTATUS_DOWNLOADING 29.84% None up 0.00KB/s down 4414.39KB/s eta 12 peers 2
#
def tribler_parse_status_line(line):
num_peers = 0
if DEBUG == True:
print "string_array is: ", string_array
- if len(string_array) != 16:
+ if len(string_array) != 14:
print "Error: Invalid line format!"
return None
# get timestamp and transform it in datetime format
- time_array = string_array[3].split(":");
- if len(time_array) != 3:
- timestamp = None
- else:
- timestamp = datetime.datetime(int(string_array[2]), int(string_array[1]), int(string_array[0]), #year, month, day
- int(time_array[0]), int(time_array[1]), int(time_array[2])) #hour, min, sec
+ timestamp= tribler_parse_timestamp(string_array[0], string_array[1])
- filename = string_array[4]
+ filename = string_array[2]
- i = 5
+ i = 3
while i < len(string_array): #string_array:
if string_array[i] == "peers":
num_peers = tribler_canon_num_peers(string_array[i+1])
- print "num_peers = %d" %(num_peers)
+ if DEBUG == True: print "num_peers = %d" %(num_peers)
i = i + 2
continue
if string_array[i] == "down":
download_speed = tribler_canon_download_speed(string_array[i+1])
- print "download_speed = %d" %(download_speed)
+ if DEBUG == True: print "download_speed = %d" %(download_speed)
i = i + 2
continue
if string_array[i] == "up":
upload_speed = tribler_canon_upload_speed(string_array[i+1])
- print "upload_speed= %d" %(upload_speed)
+ if DEBUG == True: print "upload_speed= %d" %(upload_speed)
i = i + 2
continue
if string_array[i] == "DLSTATUS_DOWNLOADING" or string_array[i] == "DLSTATUS_SEEDING":
download_size = tribler_canon_download_size(string_array[i+1], filename)
- print "download_size = %d" %(download_size)
+ if DEBUG == True: print "download_size = %d" %(download_size)
i = i + 2
continue
if string_array[i] == "eta":
eta = tribler_canon_eta(string_array[i+1])
- print "eta = %d" %(eta)
+ if DEBUG == True: print "eta = %s" %(eta)
i = i + 2
continue
i = i + 1
-
- print "-----------------------------gata o linie----------------"
+ if DEBUG == True:
+ print "-----------------------------gata o linie----------------"
return (timestamp, num_peers, dht, download_speed, upload_speed, download_size, upload_size, eta)
def tribler_parse_status_file(dbw, client_session_id, filename):
(time, num_peers, dht, download_speed, upload_speed, download_size, upload_size, eta_time) = tribler_parse_status_line(line)
if DEBUG == True:
- print "(%d, %s, %d, %d kb/s, %d kb/s, %d bytes, %d bytes)" % (num_peers, time, eta_time, download_speed, upload_speed,
+ print "(%d, %s, %s, %d kb/s, %d kb/s, %d bytes, %d bytes)" % (num_peers, time, eta_time, download_speed, upload_speed,
download_size, upload_size)
dbw.add_status_message_datetime(client_session_id, time, num_peers, dht, download_speed, upload_speed,
download_size, upload_size, eta_time)