mirror of
https://github.com/certbot/certbot.git
synced 2026-01-26 07:41:33 +03:00
Merge branch 'master' of github.com:research/chocolate
This commit is contained in:
@@ -2,9 +2,6 @@
|
||||
|
||||
# functions common to the various kinds of daemon
|
||||
|
||||
# TODO: define a log function that sends a pubsub message to the
|
||||
# logger daemon
|
||||
|
||||
import time, binascii
|
||||
from Crypto import Random
|
||||
|
||||
@@ -27,3 +24,9 @@ def random():
|
||||
def random_raw():
|
||||
"""Return 32 random bytes."""
|
||||
return Random.get_random_bytes(32)
|
||||
|
||||
def log(msg, session = None):
|
||||
if session:
|
||||
r.publish("logs", "%s: %s" % (short(session), msg))
|
||||
else:
|
||||
r.publish("logs", "%s" % session)
|
||||
|
||||
@@ -42,22 +42,23 @@ def issue(session):
|
||||
# session nonetheless died for some reason unrelated to failing
|
||||
# challenges before the cert could be issued. Normally, this
|
||||
# should never happen.
|
||||
if debug: print "removing expired (issue-state!?) session", short(session)
|
||||
log("removing expired (issue-state!?) session", session)
|
||||
r.lrem("pending-requests", session)
|
||||
return
|
||||
if r.hget(session, "state") != "issue":
|
||||
return
|
||||
csr = r.hget(session, "csr")
|
||||
names = r.lrange("%s:names" % session, 0, -1)
|
||||
log("attempting to issue certificate for names: %s" % join(names), session)
|
||||
with issue_lock:
|
||||
cert = CSR.issue(csr, names)
|
||||
r.hset(session, "cert", cert)
|
||||
if cert: # once issuing cert succeeded
|
||||
if debug: print "%s: issued certificate for names: %s" % (short(session), ", ".join(names))
|
||||
log("issued certificate for names: %s" % join(names), session)
|
||||
r.hset(session, "state", "done")
|
||||
# r.lpush("pending-done", session)
|
||||
else: # should not be reached in deployed version
|
||||
if debug: print "issuing for", short(session), "failed"
|
||||
log("issuing cert failed!?", session)
|
||||
r.lpush("pending-issue", session)
|
||||
|
||||
while True:
|
||||
|
||||
@@ -51,19 +51,49 @@ class FileLogger(Logger):
|
||||
import dialog
|
||||
class NcursesLogger(Logger):
|
||||
|
||||
def __init__(self, firstmessage="", height=18, width=70):
|
||||
self.content = firstmessage
|
||||
def __init__(self, firstmessage="", height=16, width=66):
|
||||
self.lines = []
|
||||
self.all_content = ""
|
||||
self.d = dialog.Dialog()
|
||||
self.height = height
|
||||
self.width = width
|
||||
self.show()
|
||||
self.add(firstmessage)
|
||||
|
||||
'''
|
||||
Only show the last (self.height) lines;
|
||||
note that lines can wrap at self.width, so
|
||||
a single line could actually be multiple lines
|
||||
'''
|
||||
def add(self, s):
|
||||
self.content += s
|
||||
self.all_content += s
|
||||
|
||||
for line in s.splitlines():
|
||||
# check for lines that would wrap
|
||||
cur_out = line
|
||||
while len(cur_out) > self.width:
|
||||
|
||||
# find first space before self.width chars into cur_out
|
||||
last_space_pos = cur_out.rfind(' ', 0, self.width)
|
||||
|
||||
if (last_space_pos == -1):
|
||||
# no spaces, just cut them off at whatever
|
||||
self.lines.append(cur_out[0:self.width])
|
||||
cur_out = cur_out[self.width:]
|
||||
else:
|
||||
# cut off at last space
|
||||
self.lines.append(cur_out[0:last_space_pos])
|
||||
cur_out = cur_out[last_space_pos+1:]
|
||||
if cur_out != '':
|
||||
self.lines.append(cur_out)
|
||||
|
||||
|
||||
# show last 16 lines
|
||||
self.content = '\n'.join(self.lines[-self.height:])
|
||||
self.show()
|
||||
|
||||
def show(self):
|
||||
self.d.infobox(self.content, self.height, self.width)
|
||||
# add the padding around the box
|
||||
self.d.infobox(self.content, self.height+2, self.width+4)
|
||||
|
||||
def log(self, level, data):
|
||||
self.add(data + "\n")
|
||||
@@ -117,9 +147,16 @@ if __name__ == "__main__":
|
||||
logger.setLogLevel(logger.TRACE)
|
||||
|
||||
# Log a message:
|
||||
logger.log(logger.INFO, "logger!")
|
||||
#logger.log(logger.INFO, "logger!")
|
||||
|
||||
time.sleep(0.01)
|
||||
logger.info("This is a long line, it's pretty long, butitalso hasbig wordsthat areprobably hardtobreak oninan easywayforthe ncurseslib, sowhatdoes itdo then?")
|
||||
logger.info("aa " + "a"*70 + "B")
|
||||
|
||||
for i in range(20):
|
||||
logger.info("iteration #%d/20" % i)
|
||||
time.sleep(0.3)
|
||||
|
||||
|
||||
# Alternatively, use
|
||||
logger.error("errrrr")
|
||||
|
||||
Reference in New Issue
Block a user