from twisted.protocols.basic import LineOnlyReceiver
from allmydata.scripts.common import get_alias, DEFAULT_ALIAS, escape_path, \
UnknownAliasError
-from allmydata.scripts.common_http import do_http
+from allmydata.scripts.common_http import do_http, format_http_error
+from allmydata.util.stringutils import quote_output, quote_path
class Checker:
pass
try:
rootcap, path = get_alias(options.aliases, where, DEFAULT_ALIAS)
except UnknownAliasError, e:
- print >>stderr, "error: %s" % e.args[0]
+ e.display(stderr)
return 1
if path == '/':
path = ''
resp = do_http("POST", url)
if resp.status != 200:
- print >>stderr, "ERROR", resp.status, resp.reason, resp.read()
+ print >>stderr, format_http_error("ERROR", resp)
return 1
jdata = resp.read()
if options.get("raw"):
def lineReceived(self, line):
if self.in_error:
- print >>self.stderr, line
+ print >>self.stderr, quote_output(line, quotemarks=False)
return
if line.startswith("ERROR:"):
self.in_error = True
self.streamer.rc = 1
- print >>self.stderr, line
+ print >>self.stderr, quote_output(line, quotemarks=False)
return
d = simplejson.loads(line)
if not path:
path = ["<root>"]
summary = cr.get("summary", "Healthy (LIT)")
- try:
- print >>stdout, "%s: %s" % ("/".join(path), summary)
- except UnicodeEncodeError:
- print >>stdout, "%s: %s" % ("/".join([p.encode("utf-8")
- for p in path]),
- summary)
+ print >>stdout, "%s: %s" % (quote_path(path), summary)
+
# always print out corrupt shares
for shareloc in cr["results"].get("list-corrupt-shares", []):
(serverid, storage_index, sharenum) = shareloc
def lineReceived(self, line):
if self.in_error:
- print >>self.stderr, line
+ print >>self.stderr, quote_output(line, quotemarks=False)
return
if line.startswith("ERROR:"):
self.in_error = True
self.streamer.rc = 1
- print >>self.stderr, line
+ print >>self.stderr, quote_output(line, quotemarks=False)
return
d = simplejson.loads(line)
summary = "healthy"
else:
summary = "not healthy"
- try:
- print >>stdout, "%s: %s" % ("/".join(path), summary)
- except UnicodeEncodeError:
- print >>stdout, "%s: %s" % ("/".join([p.encode("utf-8")
- for p in path]),
- summary)
+ print >>stdout, "%s: %s" % (quote_path(path), summary)
+
# always print out corrupt shares
prr = crr.get("pre-repair-results", {})
for shareloc in prr.get("results", {}).get("list-corrupt-shares", []):
try:
rootcap, path = get_alias(options.aliases, where, DEFAULT_ALIAS)
except UnknownAliasError, e:
- print >>stderr, "error: %s" % e.args[0]
+ e.display(stderr)
return 1
if path == '/':
path = ''
url += "&add-lease=true"
resp = do_http("POST", url)
if resp.status not in (200, 302):
- print >>stderr, "ERROR", resp.status, resp.reason, resp.read()
+ print >>stderr, format_http_error("ERROR", resp)
return 1
# use Twisted to split this into lines