From: "Brian Dolbec" <dolsen@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/gentoo-keys:gsoc-2016 commit in: gkeys/gkeys/
Date: Fri, 23 Dec 2016 08:37:13 +0000 (UTC) [thread overview]
Message-ID: <1472326992.693f78919985b86620bc76ba80926edeeae0b91b.dolsen@gentoo> (raw)
commit: 693f78919985b86620bc76ba80926edeeae0b91b
Author: aeroniero33 <justthisthing <AT> gmail <DOT> com>
AuthorDate: Sat Aug 27 14:22:28 2016 +0000
Commit: Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Sat Aug 27 19:43:12 2016 +0000
URL: https://gitweb.gentoo.org/proj/gentoo-keys.git/commit/?id=693f7891
Added some util methods in keyhandler
The methods are:
is_expiring that checks if a key is expiring or has recently expired
set_template that reads the template file and returns it as a string
generate_template that substitutes the key prints in the template
find_email that extracts the correct email address from the key uid
gkeys/gkeys/keyhandler.py | 42 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 42 insertions(+)
diff --git a/gkeys/gkeys/keyhandler.py b/gkeys/gkeys/keyhandler.py
index 9043fcd..0a02c22 100644
--- a/gkeys/gkeys/keyhandler.py
+++ b/gkeys/gkeys/keyhandler.py
@@ -11,6 +11,9 @@
"""
import os
import sys
+import re
+
+from string import Template
from snakeoil.demandload import demandload
@@ -108,3 +111,42 @@ class KeyHandler(object):
self.logger.debug(_unicode("KeyHandler: key_search; keys = %s") % str(keys))
return keys
+
+ @staticmethod
+ def is_expiring(keys, days_limit=30):
+ '''Check if any of the keys is within the days_limit'''
+ is_exp = False
+ for key in keys:
+ for specs in keys[key]:
+ if specs.days > days_limit*(-1) and specs.days < days_limit:
+ is_exp = True
+ break
+ return is_exp
+
+ @staticmethod
+ def set_template(template_path):
+ '''Read the template file and returns the template message'''
+ with open(template_path, 'r') as file_contents:
+ content = file_contents.read()
+ message_template = Template(content)
+ return message_template
+
+ @staticmethod
+ def generate_template(message_template, keyprints, specprint):
+ '''Substitute the print variables in the template'''
+ message = message_template.substitute(key_print=keyprints, spec_print=specprint)
+ return message
+
+ @staticmethod
+ def find_email(uids, prefered_address=None):
+ '''Find the email address from the uid by prioritizing the prefered address'''
+ if type(prefered_address) is not str:
+ uids = [uids[0]]
+ for uid in uids:
+ match = re.findall(r'[\w\.-]+@[\w\.-]+', uid)
+ uid = ''
+ if match:
+ uid = match[0]
+ if prefered_address and uid.endswith(prefered_address):
+ return uid
+ return uid
next reply other threads:[~2016-12-23 8:37 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-12-23 8:37 Brian Dolbec [this message]
-- strict thread matches above, loose matches on Subject: below --
2016-12-24 9:41 [gentoo-commits] proj/gentoo-keys:gsoc-2016 commit in: gkeys/gkeys/ Brian Dolbec
2016-12-24 9:41 Brian Dolbec
2016-12-24 9:41 Brian Dolbec
2016-12-24 9:41 Brian Dolbec
2016-12-24 9:41 Brian Dolbec
2016-12-24 9:41 Brian Dolbec
2016-12-24 9:41 Brian Dolbec
2016-12-24 9:41 Brian Dolbec
2016-12-24 9:41 Brian Dolbec
2016-12-24 9:13 Brian Dolbec
2016-12-24 9:13 Brian Dolbec
2016-12-24 9:13 Brian Dolbec
2016-12-24 9:13 Brian Dolbec
2016-12-24 9:13 Brian Dolbec
2016-12-24 9:13 Brian Dolbec
2016-12-24 9:13 Brian Dolbec
2016-12-24 9:13 Brian Dolbec
2016-12-24 9:13 Brian Dolbec
2016-12-24 9:13 Brian Dolbec
2016-12-24 9:13 Brian Dolbec
2016-12-24 9:13 Brian Dolbec
2016-12-24 9:13 Brian Dolbec
2016-12-24 9:13 Brian Dolbec
2016-12-24 9:13 Brian Dolbec
2016-12-24 9:13 Brian Dolbec
2016-12-24 9:13 Brian Dolbec
2016-12-24 4:52 [gentoo-commits] proj/gentoo-keys:master " Brian Dolbec
2016-12-24 9:13 ` [gentoo-commits] proj/gentoo-keys:gsoc-2016 " Brian Dolbec
2016-12-23 8:37 Brian Dolbec
2016-12-23 8:37 Brian Dolbec
2016-12-23 8:37 Brian Dolbec
2016-12-23 8:37 Brian Dolbec
2016-12-23 8:37 Brian Dolbec
2016-12-23 8:37 Brian Dolbec
2016-12-23 8:37 Brian Dolbec
2016-12-23 8:37 Brian Dolbec
2016-12-23 8:37 Brian Dolbec
2016-12-23 8:37 Brian Dolbec
2016-12-23 8:37 Brian Dolbec
2016-12-23 8:37 Brian Dolbec
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1472326992.693f78919985b86620bc76ba80926edeeae0b91b.dolsen@gentoo \
--to=dolsen@gentoo.org \
--cc=gentoo-commits@lists.gentoo.org \
--cc=gentoo-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox