def handle_logout(): if loggedin(): session.pop('user_name', None) else: return error_page(env, 'Not logged in') return redirect_client('main_view_page')
def torrent_get_file(env, target, torrent, filename): """ Download a file contained within a torrent. env: The WSGI environment target: The target bittorrent client torrent_hash: Hash of the torrent being examined filename: path to file within torrent (should not start with a /) """ # Is file fetching enabled? print target if not target.has_key('storage_mode'): print "File fetching disabled, 404" return None s_mode = target['storage_mode'] print "Requested file (un-unquoted):", filename filename = urllib.unquote_plus(filename) print "Requested file:", filename # Fetch absolute path to torrent try: t_path = torrent.get_full_path() except InvalidTorrentException, e: return error_page(env, str(e))
def main_view_page(env, view): """ Main page. Shows all torrents, per target. Does two XMLRPC calls per target. """ if not loggedin_and_require(env): return handle_login(env) rtorrent_data = fetch_global_info() user = fetch_user(env) # if view not in rtorrent_data.get_view_list: # return error_page(env, 'Invalid view: %s' % view) torrents = {} for target in targets: if user == None and USE_AUTH: continue if user and (target['name'] not in user.targets): continue try: t = TorrentRequester(target, view) t.get_name().get_download_rate().get_upload_rate() \ .is_complete().get_size_bytes().get_download_total().get_hash() torrents[target['name']] = t.all() except InvalidTorrentException, e: return error_page(env, str(e))
def handle_logout(env): if loggedin(env): s = env['beaker.session'] s.delete() else: return error_page(env, 'Not logged in') return main_page(env)
def torrent_file(target, torrent, rtorrent): try: filepath = torrent.get_loaded_file() # TODO: Check for errors. (Permission denied, non existing file, etc) contents = rtorrent.execute_command('sh', '-c', 'cat ' + filepath + ' | base64') except InvalidTorrentException, e: return error_page(env, str(e))
def torrent_info_page(env, target, torrent): """ Page for torrent information. Files, messages, active, etc. """ try: q = torrent.query() q.get_hash().get_name().get_size_bytes().get_download_total().\ get_loaded_file().get_message().is_active() torrentinfo = q.all()[0] # .first() ? except InvalidTorrentException, e: return error_page(env, str(e))
def torrent_get_file(target, torrent, filename): # Is file fetching enabled? print target if not target.has_key('storage_mode'): print "File fetching disabled, 404" abort(404) s_mode = target['storage_mode'] print "Requested file:", filename # Fetch absolute path to torrent try: # FIXME: rtorrent get_full_path() apparently isn't always ``full''. t_path = torrent.get_full_path() except InvalidTorrentException, e: return error_page(env, str(e))
def torrent_info(target, torrent, action=None): print torrent, action if action in ('open', 'close', 'start', 'stop', 'pause', 'resume'): print 'Executing action', action print getattr(torrent, action)() flash('Executed %s on torrent %s' % (action, torrent.get_name())) try: q = torrent.query() q.get_hash().get_name().get_size_bytes().get_download_total().\ get_loaded_file().get_message().is_active() h = hash(q) torrentinfo = cache.get(h) if torrentinfo is None: torrentinfo = q.all()[0] # .first() ? cache.set(h, torrentinfo, CACHE_TIMEOUT) except InvalidTorrentException, e: return error_page(env, str(e))
def main_view_page(view='default'): rtorrent_data = fetch_global_info() # if view not in rtorrent_data.get_view_list: # return error_page(env, 'Invalid view: %s' % view) torrents = {} for target in targets: if g.user == None and USE_AUTH: continue if g.user and (target['name'] not in g.user.targets): continue try: t = TorrentRequester(target, view) t.get_name().get_download_rate().get_upload_rate() \ .is_complete().get_size_bytes().get_download_total().get_hash() h = hash(t) torrents[target['name']] = cache.get(h) if torrents[target['name']]: continue torrents[target['name']] = cache.get(target['name']) if torrents[target['name']] is not None: continue torrents[target['name']] = t.all() cache.set(h, torrents[target['name']], timeout=CACHE_TIMEOUT) except InvalidTorrentException, e: return error_page(env, str(e))