mirror of
https://github.com/certbot/certbot.git
synced 2026-08-02 16:12:09 +02:00
Merge branch 'display-refactor' into zope.interface-display
This commit is contained in:
@@ -206,8 +206,7 @@ class Client(object):
|
|||||||
acme.revocation_request(cert_der, key), "revocation")
|
acme.revocation_request(cert_der, key), "revocation")
|
||||||
|
|
||||||
display.generic_notification(
|
display.generic_notification(
|
||||||
"You have successfully revoked the certificate for "
|
"You have successfully revoked the certificate for %s" % cert["cn"])
|
||||||
"%s" % cert["cn"], width=70, height=9)
|
|
||||||
|
|
||||||
remove_cert_key(cert)
|
remove_cert_key(cert)
|
||||||
self.list_certs_keys()
|
self.list_certs_keys()
|
||||||
|
|||||||
@@ -7,24 +7,13 @@ WIDTH = 72
|
|||||||
HEIGHT = 20
|
HEIGHT = 20
|
||||||
|
|
||||||
|
|
||||||
class SingletonD(object):
|
class Display(object):
|
||||||
_instance = None
|
|
||||||
|
|
||||||
def __new__(cls, *args, **kwargs):
|
|
||||||
if not cls._instance:
|
|
||||||
cls._instance = super(SingletonD, cls).__new__(
|
|
||||||
cls, *args, **kwargs)
|
|
||||||
return cls._instance
|
|
||||||
|
|
||||||
|
|
||||||
class Display(SingletonD):
|
|
||||||
"""Generic display."""
|
"""Generic display."""
|
||||||
|
|
||||||
def generic_notification(self, message, width=WIDTH, height=HEIGHT):
|
def generic_notification(self, message):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
def generic_menu(self, message, choices, input_text="",
|
def generic_menu(self, message, choices, input_text=""):
|
||||||
width=WIDTH, height=HEIGHT):
|
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
def generic_input(self, message):
|
def generic_input(self, message):
|
||||||
@@ -51,23 +40,24 @@ class Display(SingletonD):
|
|||||||
|
|
||||||
class NcursesDisplay(Display):
|
class NcursesDisplay(Display):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, width=WIDTH, height=HEIGHT):
|
||||||
self.dialog = dialog.Dialog()
|
self.dialog = dialog.Dialog()
|
||||||
|
self.width = width
|
||||||
|
self.height = height
|
||||||
|
|
||||||
def generic_notification(self, message, w=WIDTH, h=HEIGHT):
|
def generic_notification(self, message):
|
||||||
self.dialog.msgbox(message, width=w, height=h)
|
self.dialog.msgbox(message, width=self.width, height=self.height)
|
||||||
|
|
||||||
def generic_menu(self, message, choices, input_text="", width=WIDTH,
|
def generic_menu(self, message, choices, input_text=""):
|
||||||
height=HEIGHT):
|
|
||||||
# Can accept either tuples or just the actual choices
|
# Can accept either tuples or just the actual choices
|
||||||
if choices and isinstance(choices[0], tuple):
|
if choices and isinstance(choices[0], tuple):
|
||||||
code, selection = self.dialog.menu(
|
code, selection = self.dialog.menu(
|
||||||
message, choices=choices, width=WIDTH, height=HEIGHT)
|
message, choices=choices, width=self.width, height=self.height)
|
||||||
return code, str(selection)
|
return code, str(selection)
|
||||||
else:
|
else:
|
||||||
choices = list(enumerate(choices, 1))
|
choices = list(enumerate(choices, 1))
|
||||||
code, tag = self.dialog.menu(
|
code, tag = self.dialog.menu(
|
||||||
message, choices=choices, width=WIDTH, height=HEIGHT)
|
message, choices=choices, width=self.width, height=self.height)
|
||||||
|
|
||||||
return code(int(tag) - 1)
|
return code(int(tag) - 1)
|
||||||
|
|
||||||
@@ -76,7 +66,7 @@ class NcursesDisplay(Display):
|
|||||||
|
|
||||||
def generic_yesno(self, message, yes="Yes", no="No"):
|
def generic_yesno(self, message, yes="Yes", no="No"):
|
||||||
return self.dialog.DIALOG_OK == self.dialog.yesno(
|
return self.dialog.DIALOG_OK == self.dialog.yesno(
|
||||||
message, HEIGHT, WIDTH, yes_label=yes, no_label=no)
|
message, self.height, self.width, yes_label=yes, no_label=no)
|
||||||
|
|
||||||
def filter_names(self, names):
|
def filter_names(self, names):
|
||||||
choices = [(n, "", 0) for n in names]
|
choices = [(n, "", 0) for n in names]
|
||||||
@@ -88,12 +78,12 @@ class NcursesDisplay(Display):
|
|||||||
def success_installation(self, domains):
|
def success_installation(self, domains):
|
||||||
self.dialog.msgbox(
|
self.dialog.msgbox(
|
||||||
"\nCongratulations! You have successfully enabled "
|
"\nCongratulations! You have successfully enabled "
|
||||||
+ gen_https_names(domains) + "!", width=WIDTH)
|
+ gen_https_names(domains) + "!", width=self.width)
|
||||||
|
|
||||||
def display_certs(self, certs):
|
def display_certs(self, certs):
|
||||||
list_choices = [
|
list_choices = [
|
||||||
(str(i+1), "%s | %s | %s" %
|
(str(i+1), "%s | %s | %s" %
|
||||||
(str(c["cn"].ljust(WIDTH - 39)),
|
(str(c["cn"].ljust(self.width - 39)),
|
||||||
c["not_before"].strftime("%m-%d-%y"),
|
c["not_before"].strftime("%m-%d-%y"),
|
||||||
"Installed" if c["installed"] else ""))
|
"Installed" if c["installed"] else ""))
|
||||||
for i, c in enumerate(certs)]
|
for i, c in enumerate(certs)]
|
||||||
@@ -102,7 +92,7 @@ class NcursesDisplay(Display):
|
|||||||
"Which certificates would you like to revoke?",
|
"Which certificates would you like to revoke?",
|
||||||
choices=list_choices, help_button=True,
|
choices=list_choices, help_button=True,
|
||||||
help_label="More Info", ok_label="Revoke",
|
help_label="More Info", ok_label="Revoke",
|
||||||
width=WIDTH, height=HEIGHT)
|
width=self.width, height=self.height)
|
||||||
if not tag:
|
if not tag:
|
||||||
tag = -1
|
tag = -1
|
||||||
return code, (int(tag) - 1)
|
return code, (int(tag) - 1)
|
||||||
@@ -113,13 +103,13 @@ class NcursesDisplay(Display):
|
|||||||
text += cert_info_frame(cert)
|
text += cert_info_frame(cert)
|
||||||
text += "This action cannot be reversed!"
|
text += "This action cannot be reversed!"
|
||||||
return self.dialog.DIALOG_OK == self.dialog.yesno(
|
return self.dialog.DIALOG_OK == self.dialog.yesno(
|
||||||
text, width=WIDTH, height=HEIGHT)
|
text, width=self.width, height=self.height)
|
||||||
|
|
||||||
def more_info_cert(self, cert):
|
def more_info_cert(self, cert):
|
||||||
text = "Certificate Information:\n"
|
text = "Certificate Information:\n"
|
||||||
text += cert_info_frame(cert)
|
text += cert_info_frame(cert)
|
||||||
print text
|
print text
|
||||||
self.dialog.msgbox(text, width=WIDTH, height=HEIGHT)
|
self.dialog.msgbox(text, width=self.width, height=self.height)
|
||||||
|
|
||||||
|
|
||||||
class FileDisplay(Display):
|
class FileDisplay(Display):
|
||||||
@@ -127,15 +117,14 @@ class FileDisplay(Display):
|
|||||||
def __init__(self, outfile):
|
def __init__(self, outfile):
|
||||||
self.outfile = outfile
|
self.outfile = outfile
|
||||||
|
|
||||||
def generic_notification(self, message, width=WIDTH, height=HEIGHT):
|
def generic_notification(self, message):
|
||||||
side_frame = '-' * (79)
|
side_frame = '-' * (79)
|
||||||
wm = textwrap.fill(message, 80)
|
wm = textwrap.fill(message, 80)
|
||||||
text = "\n%s\n%s\n%s\n" % (side_frame, wm, side_frame)
|
text = "\n%s\n%s\n%s\n" % (side_frame, wm, side_frame)
|
||||||
self.outfile.write(text)
|
self.outfile.write(text)
|
||||||
raw_input("Press Enter to Continue")
|
raw_input("Press Enter to Continue")
|
||||||
|
|
||||||
def generic_menu(self, message, choices, input_text="",
|
def generic_menu(self, message, choices, input_text=""):
|
||||||
width=WIDTH, height=HEIGHT):
|
|
||||||
# Can take either tuples or single items in choices list
|
# Can take either tuples or single items in choices list
|
||||||
if choices and isinstance(choices[0], tuple):
|
if choices and isinstance(choices[0], tuple):
|
||||||
choices = ["%s - %s" % (c[0], c[1]) for c in choices]
|
choices = ["%s - %s" % (c[0], c[1]) for c in choices]
|
||||||
@@ -243,12 +232,12 @@ def set_display(display_inst):
|
|||||||
display = display_inst
|
display = display_inst
|
||||||
|
|
||||||
|
|
||||||
def generic_notification(message, width=WIDTH, height=HEIGHT):
|
def generic_notification(message):
|
||||||
display.generic_notification(message, width, height)
|
display.generic_notification(message)
|
||||||
|
|
||||||
|
|
||||||
def generic_menu(message, choices, input_text="", width=WIDTH, height=HEIGHT):
|
def generic_menu(message, choices, input_text=""):
|
||||||
return display.generic_menu(message, choices, input_text, width, height)
|
return display.generic_menu(message, choices, input_text)
|
||||||
|
|
||||||
|
|
||||||
def generic_input(message):
|
def generic_input(message):
|
||||||
|
|||||||
Reference in New Issue
Block a user