summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornico <nico@magicbroccoli.de>2018-11-09 20:52:31 +0100
committernico <nico@magicbroccoli.de>2018-11-09 20:52:31 +0100
commitb6b84108ed24939a78ed4f6240b830860967136f (patch)
tree0bd70386842d0eac90a34955a3f0b14acfddac32
parent86d058237b336516d2e5009072a4365b5bf7380b (diff)
quality of life improvement to servercontact
+ added opt_arg abbreviation
-rw-r--r--classes/servercontact.py24
1 files changed, 22 insertions, 2 deletions
diff --git a/classes/servercontact.py b/classes/servercontact.py
index 749a2c3..031ef67 100644
--- a/classes/servercontact.py
+++ b/classes/servercontact.py
@@ -19,7 +19,27 @@ class ServerContact:
self.contact = None
self.target, self.opt_arg = None, None
+ def opt_arg_abbreviation(self):
+ """
+ optional argument abbreviation function
+ if the provided string > 2 characters the most likely key will be chosen
+ :return: completes the opt_arg to the most likely one
+ """
+ # if opt_argument is smaller then 2 pass to prohibit multiple answers
+ if len(self.opt_arg) < 2:
+ pass
+
+ abbr = str(self.opt_arg)
+ possible_abbr = ["abuse-addresses", "admin-addresses", "feedback-addresses", "sales-addresses",
+ "security-addresses", "support-addresses"]
+
+ # searches the best match in the list of possible_abbr and completes the opt_arg to that
+ self.opt_arg = [s for s in possible_abbr if s.startswith(abbr)][0]
+
def process(self):
+ # optional argument abbreviation
+ self.opt_arg_abbreviation()
+
# get etree from base xml
iq = Et.fromstring(str(self.contact))
@@ -70,7 +90,7 @@ class ServerContact:
text = "contact addresses for %s are\n" % self.target
# if opt_arg is present and member of possible_vars change text line
- if opt_arg in self.possible_vars:
+ if self.opt_arg in self.possible_vars:
text = "%s for %s are\n" % (self.opt_arg, self.target)
for key in result.keys():
@@ -80,7 +100,7 @@ class ServerContact:
text = "%s has no contact addresses configured." % self.target
# if opt_arg is present and member of possible_vars but the key is empty change text line
- if opt_arg in self.possible_vars:
+ if self.opt_arg in self.possible_vars:
text = "%s for %s are not defined." % (self.opt_arg, self.target)
return text