def get_global(encode_json=False): C = config.Config() RT = rtorrent.rtorrent(C.get("rtorrent_socket")) handler = torrentHandler.Handler() diskused, disktotal = hdd(C.get("root_directory")) memused, memtotal = mem() load1, load5, load15 = os.getloadavg() uprate = handler.humanSize(RT.getGlobalUpRate()) downrate = handler.humanSize(RT.getGlobalDownRate()) uptot = handler.humanSize(RT.getGlobalUpBytes()) downtot = handler.humanSize(RT.getGlobalDownBytes()) diskused = handler.humanSize(diskused) disktotal = handler.humanSize(disktotal) memused = handler.humanSize(memused) memtotal = handler.humanSize(memtotal) load1 = "%.02f" % load1 load5 = "%.02f" % load5 load15 = "%.02f" % load15 throttle_up = handler.humanSize(RT.getGlobalUpThrottle()) throttle_down = handler.humanSize(RT.getGlobalDownThrottle()) server_uptime = str(uptime()) if not encode_json: return Global(locals()) else: return json.dumps(Global(locals()).__dict__)
def get_global(encode_json=False): C = config.Config() RT = rtorrent.rtorrent(C.get("rtorrent_socket")) handler = torrentHandler.Handler() diskused, disktotal = hdd(C.get("root_directory")) memused, memtotal = mem() load1, load5, load15 = os.getloadavg() data = { "uprate": handler.humanSize(RT.getGlobalUpRate()), "downrate": handler.humanSize(RT.getGlobalDownRate()), "uptot": handler.humanSize(RT.getGlobalUpBytes()), "downtot": handler.humanSize(RT.getGlobalDownBytes()), "diskused": handler.humanSize(diskused), "disktotal": handler.humanSize(disktotal), "memused": handler.humanSize(memused), "memtotal": handler.humanSize(memtotal), "load1": "%.02f" % load1, "load5": "%.02f" % load5, "load15": "%.02f" % load15, "throttle_up": handler.humanSize(RT.getGlobalUpThrottle()), "throttle_down": handler.humanSize(RT.getGlobalDownThrottle()), "server_uptime": handler.humanTimeDiff(uptime()), } if not encode_json: return Global(**data) else: return json.dumps(Global(**data).__dict__)
def index(self, password=None, view=None, sortby=None, reverse=None): if not view or view not in ["main","started","stopped","complete","incomplete","hashing","seeding","active"]: view = "main" if not sortby: sortby = "none" RT = rtorrent.rtorrent(self.Config.get("rtorrent_socket")) handler = torrentHandler.Handler() torrentList = RT.getTorrentList2(view) return handler.torrentHTML(torrentList, sortby, view, reverse)
def index(self, password=None, view=None, sortby=None, reverse=None): if not view or view not in [ "main", "started", "stopped", "complete", "incomplete", "hashing", "seeding", "active" ]: view = "main" if not sortby: sortby = "none" RT = rtorrent.rtorrent(self.Config.get("rtorrent_socket")) handler = torrentHandler.Handler() torrentList = RT.getTorrentList2(view) return handler.torrentHTML(torrentList, sortby, view, reverse)
def generalHTML(): C = config.Config() RT = rtorrent.rtorrent(C.get("rtorrent_socket")) handler = torrentHandler.Handler() diskused, disktotal = hdd() memused, memtotal = mem() load1, load5, load15 = os.getloadavg() return """ <h2>Global Stats</h2> <div class="column-1">Upload Rate:</div><div class="column-2">%(uprate)s/s</div> <div class="column-3">Total Up:</div><div class="column-4">%(uptot)s</div> <div class="column-5">Disk Usage:</div><div class="column-6">%(diskused)s / %(disktotal)s</div> <div class="column-1">Download Rate:</div><div class="column-2">%(downrate)s/s</div> <div class="column-3">Total Down:</div><div class="column-4">%(downtot)s</div> <div class="column-5">Mem Usage:</div><div class="column-6">%(memused)s / %(memtotal)s</div> <div class="column-1">Load Average:</div> <div class="column-2"> <span title="Last minute">%(load1)s</span>, <span title="Last 5 minutes">%(load5)s</span>, <span title="Last 15 minutes">%(load15)s</span> </div> <div class="column-3">Uptime:</div><div class="column-4">%(uptime)s</div> <div class="column-5">CPU Usage:</div><div class="column-6">%(cpuusage)s%%</div> """ % { "uprate": handler.humanSize(RT.getGlobalUpRate()), "downrate": handler.humanSize(RT.getGlobalDownRate()), "uptot": handler.humanSize(RT.getGlobalUpBytes()), "downtot": handler.humanSize(RT.getGlobalDownBytes()), "diskused": handler.humanSize(diskused), "disktotal": handler.humanSize(disktotal), "memused": handler.humanSize(memused), "memtotal": handler.humanSize(memtotal), "load1": "%.02f" % load1, "load5": "%.02f" % load5, "load15": "%.02f" % load15, "cpuusage": "None", "uptime": str(uptime()), }
def generalHTML(): C = config.Config() RT = rtorrent.rtorrent(C.get("rtorrent_socket")) handler = torrentHandler.Handler() diskused, disktotal = hdd(C.get("root_directory")) memused, memtotal = mem() load1, load5, load15 = os.getloadavg() return """ <h2>Global Stats</h2> <div class="column-1">Upload Rate:</div><div class="column-2">%(uprate)s/s</div> <div class="column-3">Total Up:</div><div class="column-4">%(uptot)s</div> <div class="column-5">Disk Usage:</div><div class="column-6">%(diskused)s / %(disktotal)s</div> <div class="column-1">Download Rate:</div><div class="column-2">%(downrate)s/s</div> <div class="column-3">Total Down:</div><div class="column-4">%(downtot)s</div> <div class="column-5">Mem Usage:</div><div class="column-6">%(memused)s / %(memtotal)s</div> <div class="column-1">Load Average:</div> <div class="column-2"> <span title="Last minute">%(load1)s</span>, <span title="Last 5 minutes">%(load5)s</span>, <span title="Last 15 minutes">%(load15)s</span> </div> <div class="column-3">Uptime:</div><div class="column-4">%(uptime)s</div> <div class="column-5">CPU Usage:</div><div class="column-6">%(cpuusage)s%%</div> """ % { "uprate" : handler.humanSize(RT.getGlobalUpRate()), "downrate" : handler.humanSize(RT.getGlobalDownRate()), "uptot" : handler.humanSize(RT.getGlobalUpBytes()), "downtot" : handler.humanSize(RT.getGlobalDownBytes()), "diskused" : handler.humanSize(diskused), "disktotal" : handler.humanSize(disktotal), "memused" : handler.humanSize(memused), "memtotal" : handler.humanSize(memtotal), "load1" : "%.02f" % load1, "load5" : "%.02f" % load5, "load15" : "%.02f" % load15, "cpuusage" : "None", "uptime" : str(uptime()), }
def __init__(self): self.Config = config.Config() self.RT = rtorrent.rtorrent(self.Config.get("rtorrent_socket")) self.Handler = torrentHandler.Handler()
def index(self, password=None, view=None, sortby=None, reverse=None): if not view or view not in ["main","started","stopped","complete","incomplete","hashing","seeding","active"]: view = "main" if not sortby: sortby = "none" Config = config.Config() RT = rtorrent.rtorrent(Config.get("rtorrent_socket")) handler = torrentHandler.Handler() torrentList = RT.getTorrentList2(view) html = handler.torrentHTML(torrentList, sortby, view, reverse) def genHTML(type, VIEW): if VIEW == type: return '<div class="topbar-tab selected" onmouseover="select_tab(this);" onmouseout="deselect_tab(this);" onclick="navigate_tab(this);" title="%s" id="tab_%s">%s</div>' % (type, type, type.capitalize()) else: return '<div class="topbar-tab" onmouseover="select_tab(this);" onmouseout="deselect_tab(this);" onclick="navigate_tab(this);" title="%s" id="tab_%s">%s</div>' % (type, type, type.capitalize()) ttmain = genHTML("main", view) ttstarted = genHTML("started",view) ttstopped = genHTML("stopped",view) ttcomplete = genHTML("complete",view) ttincomplete = genHTML("incomplete",view) tthashing = genHTML("hashing",view) ttseeding = genHTML("seeding",view) ttactive = genHTML("active",view) if not reverse: reverse = "none" else: reverse = "true" html_insert = """ <div id="header"> <div id="topbar"> %(main)s %(started)s %(stopped)s %(complete)s %(incomplete)s %(hashing)s %(seeding)s %(active)s <div id="tools-bar"> <div class="topbar-tab_options" onmouseover="select_tab(this);" onmouseout="deselect_tab(this);" onclick="navigate_options(this);" title="Options" id="tab_options">Options</div> </div> </div> <div id="actions-bar"> <a href="#" id="add-torrent-button">Add torrent</a> </div> </div> <div id="main_body"> <div id="wrapper"> <div id="add_torrent" style="display: none" title="Add a torrent"> <form id="add_torrent_form" action="upload_torrent" method="post" enctype="multipart/form-data"> <label>Select file:</label> <input id="add_torrent_input" accept="application/x-bittorrent" type="file" name="torrent"> <div class="add_torrent_start_text"> <input id="add_torrent_start" type="checkbox" name="start"> Start Immediately? </div> </form> </div> <div id="global_stats"> %(global_stats)s </div> <button class="hidden" onclick="refresh_content();">Click!</button> <div id="this_view" class="hidden">%(view)s</div> <div id="this_sort" class="hidden">%(sortby)s</div> <div id="this_reverse" class="hidden">%(reverse)s</div> """ % { "main" : ttmain, "started" : ttstarted, "stopped" : ttstopped, "complete" : ttcomplete, "incomplete" : ttincomplete, "hashing" : tthashing, "seeding" : ttseeding, "active" : ttactive, "global_stats" : system.generalHTML(), "view" : view, "sortby" : sortby, "reverse" : reverse, } return html.replace("<!-- BODY PLACEHOLDER -->",html_insert).replace("</body>","</div></div>\n\t</body>")
def __init__(self, conf=config.Config()): self.Config = conf self.RT = rtorrent.rtorrent(self.Config.get("rtorrent_socket")) self.Handler = torrentHandler.Handler()
#!/usr/bin/env python import sys import json import time import rtorrent RT = rtorrent.rtorrent(5000) timer = json.loads(open(".timer.json").read()) config = open("strauto.config").read() SRC_TTL = int(config.split("SRC_TTL = ")[1].split("\n")[0]) STR_TTL_SEEDED = int(config.split("STR_TTL_SEEDED = ")[1].split("\n")[0]) STR_TTL_UNSEEDED = int(config.split("STR_TTL_UNSEEDED = ")[1].split("\n")[0]) db = {} for id in timer.keys(): try: name = RT.getNameByID(id) except: print "ID: %s doesn't exist" % id continue type = timer[id][0] added = timer[id][1] if type == "SRC": timediff = time.time() - added timeleft = SRC_TTL - timediff elif type == "STR": timediff = time.time() - added ratio = RT.getRatio(id) if ratio > 1:
def __init__(self, torrent_id, conf=config.Config()): self.Config = conf self.RT = rtorrent.rtorrent(self.Config.get("rtorrent_socket")) self.Handler = torrentHandler.Handler() self.HTML = """ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html;charset=utf-8"> <title>rTorrent - %(tname)s</title> <link rel="stylesheet" type="text/css" href="/css/detail.css"> <link rel="stylesheet" type="text/css" href="/css/smoothness/jquery-ui-1.8.13.custom.css"> <link rel="stylesheet" type="text/css" href="/css/jquery.treeview.css"> <script src="/javascript/jquery-1.6.1.min.js" type="text/javascript"></script> <script src="/javascript/jquery-ui-1.8.13.custom.min.js" type="text/javascript"></script> <script src="/javascript/jquery.cookie.js" type="text/javascript"></script> <!-- <script src="/javascript/jquery.jstree.js" type="text/javascript"></script> --> <script src="/javascript/jquery.treeview.js" type="text/javascript"></script> <script src="/javascript/detail.js" type="text/javascript"></script> </head> <body> <div id="accordion"> <h3><a href="#">Torrent info</a></h3> <div id="info_within"> <p>Name: %(tname)s</p> <p>ID: %(tid)s</p> <p>Created: %(tcreated)s</p> <p>Path: %(tpath)s</p> <p>Priority: %(tpriority)s</p> <p class="%(tstate)s">State: %(tstate)s</p> <p>Completion: %(tdone)s%%</p> <p>Size: %(tsize)s</p> <p>Ratio: %(tratio)s</p> <p>Downloaded: %(tdownloaded)s</p> <p>Uploaded: %(tuploaded)s</p> <p>Upload Rate: %(tuprate)s</p> <p>Download Rate: %(tdownrate)s</p> <p>Leechers: %(tleechs_connected)s (%(tleechs_total)s)</p> <p>Seeders: %(tseeds_connected)s (%(tseeds_total)s)</p> </div> <h3><a href="#">Peers</a></h3> <div id="peers_within"> <div id="peers_table"> <table> <tr> <td class="heading">IP Address</td> <td class="heading">Port</td> <td class="heading">Client</td> <td class="heading">Completed</td> <td class="heading">Download Rate</td> <td class="heading">Download Total</td> <td class="heading">Upload Rate</td> <td class="heading">Upload Total</td> <td class="heading">Peer Rate</td> <td class="heading">Peer Total</td> </tr> %(peer_table_rows)s </table> </div> </div> <h3><a href="#">File list</a></h3> <div id="files_within"> <div> %(filelist)s </div> </div> <h3><a href="#">Tracker list</a></h3> <div id="trackers_within"> <div id="trackers_table"> <table> <tr> <td class="heading">URL</td> <td class="heading">Type</td> <td class="heading">Announce Interval</td> <td class="heading">Seeders</td> <td class="heading">Leechers</td> <td class="heading">Enabled</td> </tr> %(tracker_table_rows)s </table> </div> </div> </div> </body> </html> """ % self._getInfo(torrent_id)
def __init__(self, torrent_id, conf=config.Config()): self.Config = conf self.RT = rtorrent.rtorrent(self.Config.get("rtorrent_socket")) self.Handler = torrentHandler.Handler() self.HTML = """ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html;charset=utf-8"> <title>rTorrent - %(tname)s</title> <link rel="stylesheet" type="text/css" href="/css/detail.css"> <link rel="stylesheet" type="text/css" href="/css/smoothness/jquery-ui-1.8.13.custom.css"> <link rel="stylesheet" type="text/css" href="/css/jquery.treeview.css"> <script src="/javascript/jquery-1.6.1.min.js" type="text/javascript"></script> <script src="/javascript/jquery-ui-1.8.13.custom.min.js" type="text/javascript"></script> <script src="/javascript/jquery.cookie.js" type="text/javascript"></script> <!-- <script src="/javascript/jquery.jstree.js" type="text/javascript"></script> --> <script src="/javascript/jquery.treeview.js" type="text/javascript"></script> <script src="/javascript/detail.js" type="text/javascript"></script> </head> <body> <div id="accordion"> <h3><a href="#">Torrent info</a></h3> <div id="info_within"> <p>Name: %(tname)s</p> <p>ID: %(tid)s</p> <p>Created: %(tcreated)s</p> <p>Path: %(tpath)s</p> <p>Priority: %(tpriority)s</p> <p class="%(tstate)s">State: %(tstate)s</p> <p>Completion: %(tdone)s%%</p> <p>Size: %(tsize)s</p> <p>Ratio: %(tratio)s</p> <p>Downloaded: %(tdownloaded)s</p> <p>Uploaded: %(tuploaded)s</p> <p>Upload Rate: %(tuprate)s</p> <p>Download Rate: %(tdownrate)s</p> <p>Leechers: %(tleechs_connected)s (%(tleechs_total)s)</p> <p>Seeders: %(tseeds_connected)s (%(tseeds_total)s)</p> </div> <h3><a href="#">Peers</a></h3> <div id="peers_within"> <div id="peers_table"> <table> <tr> <td class="heading">IP Address</td> <td class="heading">Port</td> <td class="heading">Client</td> <td class="heading">Completed</td> <td class="heading">Download Rate</td> <td class="heading">Download Total</td> <td class="heading">Upload Rate</td> <td class="heading">Upload Total</td> <td class="heading">Peer Rate</td> <td class="heading">Peer Total</td> </tr> %(peer_table_rows)s </table> </div> </div> <h3><a href="#">File list</a></h3> <div id="files_within"> <div> %(filelist)s </div> </div> <h3><a href="#">Tracker list</a></h3> <div id="trackers_within"> <div id="trackers_table"> <table> <tr> <td class="heading">URL</td> <td class="heading">Type</td> <td class="heading">Announce Interval</td> <td class="heading">Seeders</td> <td class="heading">Leechers</td> <td class="heading">Enabled</td> </tr> %(tracker_table_rows)s </table> </div> </div> </div> </body> </html> """ % self._getInfo( torrent_id )