예제 #1
0
파일: pages.py 프로젝트: cjlucas/DarTui
 def main(self):
     args = web.input()
     rpc_ids = args.get("rpc_id", None)
     rt = common.conf.get_rt()
     json_data = {}
     json_data["torrents"] = []
     json_data["client_info"] = {}
     json_data["trackers"] = {}
     json_data["error_code"] = 0
     json_data["error_msg"] = ""
     
     if rt is not None:
         rt.update()
         torrents = actions.get_torrents_and_update_cache()
         json_data["trackers"] = common.conf.tracker_cache
         
         # if specific rpc ids were specified
         if rpc_ids is not None:
             #rpc_ids = parse_qs(rpc_ids).get("ids", []) # not needed?
             if isinstance(rpc_ids, (str, unicode)): rpc_ids = [rpc_ids]
         
             for rpc_id in rpc_ids:
                 t = actions.get_torrent(rpc_id)
                 json_data["torrents"].append(actions.build_torrent_info(t))
     
         else:
             # return all torrents (plus extra info)
             try:
                 du = utils.get_disk_usage(common.conf.settings["du_path"])
             except OSError:
                 print("{0} not found".format(common.conf.settings["du_path"]))
                 du = utils.get_disk_usage("/")
                 
             json_data["torrents"] = actions.build_torrent_info(torrents)        
         
             json_data["client_info"]["disk_free_str"] = formatters.format_size(du.free)
             json_data["client_info"]["disk_total_str"] = formatters.format_size(du.total)
             json_data["client_info"]["disk_free_percentage"] = formatters.format_percentage(du.free, du.total)
             json_data["client_info"]["down_rate"] = formatters.format_speed(rt.down_rate)
             json_data["client_info"]["up_rate"] = formatters.format_speed(rt.up_rate)
             json_data["client_info"]["client_version"] = rt.client_version
             json_data["client_info"]["library_version"] = rt.library_version
             json_data["client_info"]["dartui_version"] = common.__version__
             json_data["client_info"]["recent_torrent_dests"] = common.recent_torrent_dests
     else:
         json_data["error_code"] = 1
         json_data["error_msg"] = "Couldn't connect to rTorrent."
   
     return(to_json(json_data))
예제 #2
0
파일: actions.py 프로젝트: cjlucas/DarTui
def build_torrent_info(torrent_list):
    ret_list = []
    cur_time = time.time()
    
    if not isinstance(torrent_list, list):
        torrent_list = [torrent_list]
        
    for t in torrent_list:
        if os.path.exists(t.base_path): 
            ctime = os.stat(t.base_path).st_ctime
            time_added = formatters.format_time_difference(cur_time - ctime)
        else:
            ctime = 0
            time_added = "NOT FOUND"
            
        eta = formatters.calc_eta(t.down_rate, t.left_bytes)
            
        torrent_dict = {
            "rpc_id"            : t.rpc_id,
            "name"              : t.name,
            "message"           : t.message,
            "ctime"             : ctime,
            "up_rate"           : t.up_rate,
            "up_rate_str"       : formatters.format_speed(t.up_rate),
            "down_rate"         : t.down_rate,
            "down_rate_str"     : formatters.format_speed(t.down_rate),
            "ratio"             : formatters.format_ratio(t.ratio),
            "total_bytes"       : t.size_bytes,
            "total_str"         : formatters.format_size(t.size_bytes),
            "left_bytes"        : t.left_bytes,
            "completed_bytes"   : t.completed_bytes,
            "completed_str"     : formatters.format_size(t.completed_bytes),
            "percent_complete"  : formatters.format_percentage(t.completed_bytes, t.size_bytes),
            "state"             : t.state,
            "active"            : t.active,
            "hashing"           : t.hash_checking,
            "hashing_queued"    : t.hash_checking_queued,
            "peers_connected"   : t.peers_connected,
            "total_peers"       : t.peers_connected + t.peers_not_connected,
            "time_added"        : time_added,
            "eta"               : eta,
            "eta_str"           : formatters.format_time_difference(eta),
        }
        ret_list.append(torrent_dict)

    if len(ret_list) == 1: return(ret_list[0])
    else: return(ret_list)