]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
web: fix output=JSON, add buttons for repair/json to the 'run deep-check' form
authorBrian Warner <warner@allmydata.com>
Wed, 10 Sep 2008 21:11:37 +0000 (14:11 -0700)
committerBrian Warner <warner@allmydata.com>
Wed, 10 Sep 2008 21:11:37 +0000 (14:11 -0700)
src/allmydata/web/checker_results.py
src/allmydata/web/directory.py

index efccb82b8f63c5da0c17336ada7f3f2340507d1f..80251c2c91373c740cc37e219e1af6090a41843d 100644 (file)
@@ -47,7 +47,8 @@ class ResultsBase:
                                    for serverid in d["servers-responding"]]
         sharemap = {}
         for (shareid, serverids) in d["sharemap"].items():
-            sharemap[shareid] = [base32.b2a(serverid) for serverid in serverids]
+            sharemap[shareid] = [idlib.nodeid_b2a(serverid)
+                                 for serverid in serverids]
         r["sharemap"] = sharemap
 
         r["count-wrong-shares"] = d["count-wrong-shares"]
@@ -62,12 +63,17 @@ class ResultsBase:
         assert isinstance(s, (list, tuple))
         return [html.escape(w) for w in s]
 
-class LiteralCheckerResults(rend.Page):
+    def want_json(self, ctx):
+        output = get_arg(inevow.IRequest(ctx), "output", "").lower()
+        if output.lower() == "json":
+            return True
+        return False
+
+class LiteralCheckerResults(rend.Page, ResultsBase):
     docFactory = getxmlfile("literal-checker-results.xhtml")
 
     def renderHTTP(self, ctx):
-        t = get_arg(inevow.IRequest(ctx), "output", "")
-        if t.lower() == "json":
+        if self.want_json(ctx):
             return self.json(ctx)
         return rend.Page.renderHTTP(self, ctx)
 
@@ -85,8 +91,7 @@ class CheckerResults(rend.Page, ResultsBase):
         self.r = ICheckerResults(results)
 
     def renderHTTP(self, ctx):
-        t = get_arg(inevow.IRequest(ctx), "output", "")
-        if t.lower() == "json":
+        if self.want_json(ctx):
             return self.json(ctx)
         return rend.Page.renderHTTP(self, ctx)
 
@@ -121,8 +126,7 @@ class CheckAndRepairResults(rend.Page, ResultsBase):
         self.r = ICheckAndRepairResults(results)
 
     def renderHTTP(self, ctx):
-        t = get_arg(inevow.IRequest(ctx), "output", None)
-        if t == "json":
+        if self.want_json(ctx):
             return self.json(ctx)
         return rend.Page.renderHTTP(self, ctx)
 
@@ -173,8 +177,7 @@ class DeepCheckResults(rend.Page, ResultsBase):
         self.r = results
 
     def renderHTTP(self, ctx):
-        t = get_arg(inevow.IRequest(ctx), "output", None)
-        if t == "json":
+        if self.want_json(ctx):
             return self.json(ctx)
         return rend.Page.renderHTTP(self, ctx)
 
@@ -187,8 +190,8 @@ class DeepCheckResults(rend.Page, ResultsBase):
         data["count-objects-healthy"] = c["count-objects-healthy"]
         data["count-objects-unhealthy"] = c["count-objects-unhealthy"]
         data["count-corrupt-shares"] = c["count-corrupt-shares"]
-        data["list-corrupt-shares"] = [ (idlib.b2a(serverid),
-                                         idlib.b2a(storage_index),
+        data["list-corrupt-shares"] = [ (idlib.nodeid_b2a(serverid),
+                                         base32.b2a(storage_index),
                                          shnum)
                                         for (serverid, storage_index, shnum)
                                         in self.r.get_corrupt_shares() ]
@@ -306,8 +309,7 @@ class DeepCheckAndRepairResults(rend.Page, ResultsBase):
         self.r = results
 
     def renderHTTP(self, ctx):
-        t = get_arg(inevow.IRequest(ctx), "output", None)
-        if t == "json":
+        if self.want_json(ctx):
             return self.json(ctx)
         return rend.Page.renderHTTP(self, ctx)
 
@@ -330,13 +332,13 @@ class DeepCheckAndRepairResults(rend.Page, ResultsBase):
         data["count-corrupt-shares-pre-repair"] = c["count-corrupt-shares-pre-repair"]
         data["count-corrupt-shares-post-repair"] = c["count-corrupt-shares-pre-repair"]
 
-        data["list-corrupt-shares"] = [ (idlib.b2a(serverid),
-                                         idlib.b2a(storage_index),
+        data["list-corrupt-shares"] = [ (idlib.nodeid_b2a(serverid),
+                                         base32.b2a(storage_index),
                                          shnum)
                                         for (serverid, storage_index, shnum)
                                         in self.r.get_corrupt_shares() ]
-        data["list-remaining-corrupt-shares"] = [ (idlib.b2a(serverid),
-                                                   idlib.b2a(storage_index),
+        data["list-remaining-corrupt-shares"] = [ (idlib.nodeid_b2a(serverid),
+                                                   base32.b2a(storage_index),
                                                    shnum)
                                                   for (serverid, storage_index, shnum)
                                                   in self.r.get_remaining_corrupt_shares() ]
index 5c45d960baa687cf5dbd848210959aa4386af220..c4624678d0f1bcbe6f750097eafe858166324ce5 100644 (file)
@@ -567,10 +567,17 @@ class DirectoryAsHTML(rend.Page):
             T.input(type="hidden", name="t", value="deep-check"),
             T.input(type="hidden", name="return_to", value="."),
             T.legend(class_="freeform-form-label")["Run a deep-check operation (EXPENSIVE)"],
-            T.input(type="submit", value="Deep-Check"),
-            " ",
+            T.div[
             "Verify every bit? (EVEN MORE EXPENSIVE):",
             T.input(type="checkbox", name="verify"),
+            ],
+            T.div["Repair any problems?: ",
+                  T.input(type="checkbox", name="repair")],
+            T.div["Emit results in JSON format?: ",
+                  T.input(type="checkbox", name="output", value="JSON")],
+
+            T.input(type="submit", value="Deep-Check"),
+
             ]]
         forms.append(T.div(class_="freeform-form")[deep_check])