mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2024-12-29 17:28:53 +00:00
Convert status.py over to MultiFormatPage
This commit is contained in:
parent
5a30bd6169
commit
6e4c4b7abc
@ -4,8 +4,16 @@ import json
|
|||||||
from twisted.internet import defer
|
from twisted.internet import defer
|
||||||
from nevow import rend, inevow, tags as T
|
from nevow import rend, inevow, tags as T
|
||||||
from allmydata.util import base32, idlib
|
from allmydata.util import base32, idlib
|
||||||
from allmydata.web.common import getxmlfile, get_arg, \
|
from allmydata.web.common import (
|
||||||
abbreviate_time, abbreviate_rate, abbreviate_size, plural, compute_rate, render_time
|
getxmlfile,
|
||||||
|
abbreviate_time,
|
||||||
|
abbreviate_rate,
|
||||||
|
abbreviate_size,
|
||||||
|
plural,
|
||||||
|
compute_rate,
|
||||||
|
render_time,
|
||||||
|
MultiFormatPage,
|
||||||
|
)
|
||||||
from allmydata.interfaces import IUploadStatus, IDownloadStatus, \
|
from allmydata.interfaces import IUploadStatus, IDownloadStatus, \
|
||||||
IPublishStatus, IRetrieveStatus, IServermapUpdaterStatus
|
IPublishStatus, IRetrieveStatus, IServermapUpdaterStatus
|
||||||
|
|
||||||
@ -950,7 +958,8 @@ class MapupdateStatusPage(rend.Page, RateAndTimeMixin):
|
|||||||
return T.li["Per-Server Response Times: ", l]
|
return T.li["Per-Server Response Times: ", l]
|
||||||
|
|
||||||
|
|
||||||
class Status(rend.Page):
|
|
||||||
|
class Status(MultiFormatPage):
|
||||||
docFactory = getxmlfile("status.xhtml")
|
docFactory = getxmlfile("status.xhtml")
|
||||||
addSlash = True
|
addSlash = True
|
||||||
|
|
||||||
@ -958,14 +967,7 @@ class Status(rend.Page):
|
|||||||
rend.Page.__init__(self, history)
|
rend.Page.__init__(self, history)
|
||||||
self.history = history
|
self.history = history
|
||||||
|
|
||||||
def renderHTTP(self, ctx):
|
def render_JSON(self, req):
|
||||||
req = inevow.IRequest(ctx)
|
|
||||||
t = get_arg(req, "t")
|
|
||||||
if t == "json":
|
|
||||||
return self.json(req)
|
|
||||||
return rend.Page.renderHTTP(self, ctx)
|
|
||||||
|
|
||||||
def json(self, req):
|
|
||||||
# modern browsers now render this instead of forcing downloads
|
# modern browsers now render this instead of forcing downloads
|
||||||
req.setHeader("content-type", "application/json")
|
req.setHeader("content-type", "application/json")
|
||||||
data = {}
|
data = {}
|
||||||
@ -1128,20 +1130,13 @@ class Status(rend.Page):
|
|||||||
return RetrieveStatusPage(s)
|
return RetrieveStatusPage(s)
|
||||||
|
|
||||||
|
|
||||||
class HelperStatus(rend.Page):
|
class HelperStatus(MultiFormatPage):
|
||||||
docFactory = getxmlfile("helper.xhtml")
|
docFactory = getxmlfile("helper.xhtml")
|
||||||
|
|
||||||
def __init__(self, helper):
|
def __init__(self, helper):
|
||||||
rend.Page.__init__(self, helper)
|
rend.Page.__init__(self, helper)
|
||||||
self.helper = helper
|
self.helper = helper
|
||||||
|
|
||||||
def renderHTTP(self, ctx):
|
|
||||||
req = inevow.IRequest(ctx)
|
|
||||||
t = get_arg(req, "t")
|
|
||||||
if t == "json":
|
|
||||||
return self.render_JSON(req)
|
|
||||||
return rend.Page.renderHTTP(self, ctx)
|
|
||||||
|
|
||||||
def data_helper_stats(self, ctx, data):
|
def data_helper_stats(self, ctx, data):
|
||||||
return self.helper.get_stats()
|
return self.helper.get_stats()
|
||||||
|
|
||||||
@ -1179,21 +1174,17 @@ class HelperStatus(rend.Page):
|
|||||||
return str(data["chk_upload_helper.encoded_bytes"])
|
return str(data["chk_upload_helper.encoded_bytes"])
|
||||||
|
|
||||||
|
|
||||||
class Statistics(rend.Page):
|
class Statistics(MultiFormatPage):
|
||||||
docFactory = getxmlfile("statistics.xhtml")
|
docFactory = getxmlfile("statistics.xhtml")
|
||||||
|
|
||||||
def __init__(self, provider):
|
def __init__(self, provider):
|
||||||
rend.Page.__init__(self, provider)
|
rend.Page.__init__(self, provider)
|
||||||
self.provider = provider
|
self.provider = provider
|
||||||
|
|
||||||
def renderHTTP(self, ctx):
|
def render_JSON(self, req):
|
||||||
req = inevow.IRequest(ctx)
|
stats = self.provider.get_stats()
|
||||||
t = get_arg(req, "t")
|
req.setHeader("content-type", "text/plain")
|
||||||
if t == "json":
|
return json.dumps(stats, indent=1) + "\n"
|
||||||
stats = self.provider.get_stats()
|
|
||||||
req.setHeader("content-type", "text/plain")
|
|
||||||
return json.dumps(stats, indent=1) + "\n"
|
|
||||||
return rend.Page.renderHTTP(self, ctx)
|
|
||||||
|
|
||||||
def data_get_stats(self, ctx, data):
|
def data_get_stats(self, ctx, data):
|
||||||
return self.provider.get_stats()
|
return self.provider.get_stats()
|
||||||
|
Loading…
Reference in New Issue
Block a user