From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id BC1D2139085 for ; Fri, 23 Dec 2016 08:37:40 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 6E67FE0E37; Fri, 23 Dec 2016 08:37:39 +0000 (UTC) Received: from smtp.gentoo.org (woodpecker.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 3B5E9E0E37 for ; Fri, 23 Dec 2016 08:37:29 +0000 (UTC) Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id B0B2634112A for ; Fri, 23 Dec 2016 08:37:17 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 55E7724EF for ; Fri, 23 Dec 2016 08:37:14 +0000 (UTC) From: "Brian Dolbec" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Brian Dolbec" Message-ID: <1482482176.e2676812145dea4cf8b0e7bb33238b92340045d2.dolsen@gentoo> Subject: [gentoo-commits] proj/gentoo-keys:gsoc-2016 commit in: gkeys/gkeys/ X-VCS-Repository: proj/gentoo-keys X-VCS-Files: gkeys/gkeys/actions.py gkeys/gkeys/base.py gkeys/gkeys/seedhandler.py X-VCS-Directories: gkeys/gkeys/ X-VCS-Committer: dolsen X-VCS-Committer-Name: Brian Dolbec X-VCS-Revision: e2676812145dea4cf8b0e7bb33238b92340045d2 X-VCS-Branch: gsoc-2016 Date: Fri, 23 Dec 2016 08:37:14 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: ef508dd2-fc59-4437-891e-07a155d2660e X-Archives-Hash: 2107518af52e899ccda1399aec219910 commit: e2676812145dea4cf8b0e7bb33238b92340045d2 Author: aeroniero33 gmail com> AuthorDate: Fri Jun 17 17:40:01 2016 +0000 Commit: Brian Dolbec gentoo org> CommitDate: Fri Dec 23 08:36:16 2016 +0000 URL: https://gitweb.gentoo.org/proj/gentoo-keys.git/commit/?id=e2676812 gkeys actions: Added automatic seeds,keys update capability Add more detailed update reporting including the keys removed, revoked/changed, added. Convert print() to proper self.output() Whitespace cleanup Commit message improvements gkeys/gkeys/actions.py | 20 +++++++------- gkeys/gkeys/base.py | 68 +++++++++++++++++++++++++++++++++++++++++++++- gkeys/gkeys/seedhandler.py | 9 +++++- 3 files changed, 85 insertions(+), 12 deletions(-) diff --git a/gkeys/gkeys/actions.py b/gkeys/gkeys/actions.py index 45f9a96..003a4e3 100644 --- a/gkeys/gkeys/actions.py +++ b/gkeys/gkeys/actions.py @@ -132,19 +132,19 @@ class Actions(ActionBase): self.output('', "Update succeeded.\n") messages = fetch_messages + [" Update operation:"] + [install_messages] success, new_gkeys = self.listseed(args) - added_gkeys, changed_gkeys = self.seedhandler.compare_seeds(old_gkeys, new_gkeys) - self.output('', "Updated revoked GKeys:") - if changed_gkeys: - for gkey in changed_gkeys: - self.output(['', changed_gkeys]) + added_gkeys, changed_gkeys, removed_gkeys = self.seedhandler.compare_seeds(old_gkeys, new_gkeys) + for gkey in changed_gkeys: + self.output([changed_gkeys], "Updated or revoked GKeys:") else: - self.output('', "No GKeys were revoked") - self.output('', "Added GKeys:") - if added_gkeys: - for gkey in added_gkeys: - self.output(['', added_gkeys]) + self.output('', "No GKeys were updated or revoked") + for gkey in added_gkeys: + self.output([added_gkeys], "Added GKeys:") else: self.output('', "No GKeys were added") + for gkey in removed_gkeys: + self.output([removed_gkeys], "Removed GKeys:") + else: + self.output('', "No GKeys were removed") return (success, messages) def addseed(self, args): diff --git a/gkeys/gkeys/base.py b/gkeys/gkeys/base.py index a0224c0..28dd0b2 100644 --- a/gkeys/gkeys/base.py +++ b/gkeys/gkeys/base.py @@ -17,10 +17,20 @@ from __future__ import print_function import argparse import os import sys +import copy from gkeys.fileops import ensure_dirs from gkeys.log import log_levels, set_logger +from gkeys.gkey import GKEY +if sys.version_info[0] >= 3: + from urllib.request import urlopen + py_input = input + _unicode = str +else: + from urllib2 import urlopen + py_input = raw_input + _unicode = unicode if sys.version_info[0] >= 3: unicode = str @@ -291,6 +301,10 @@ class CliBase(object): for opt in options: getattr(self, '_option_%s' % opt)(parser) + def warning_output(self, info): + ''' We don't want this message to be spammed 4 times everytime gkeys is run''' + if "Re-fetch cycle timeout of" not in info: + print(info) def setup(self, args, configs): '''Set up the args and configs passed in @@ -352,7 +366,59 @@ class CliBase(object): ''' # establish our actions instance self.actions = self.cli_config['Actions'](self.config, self.output_results, self.logger) - + # check for seed update + from sslfetch.connections import Connector + connector_output = { + 'info': self.logger.info, + 'debug': self.logger.debug, + 'error': self.logger.error, + 'exception': self.logger.exception, + 'warning': self.warning_output, + 'kwargs-info': {}, + 'kwargs-debug': {}, + 'kwargs-error': {}, + 'kwargs-exception': {}, + 'kwargs-warning': {}, + } + fetcher = Connector(connector_output, None, "Gentoo Keys") + successes = [] + up_to_date = True + categories = list(self.config.defaults['seeds']) + '''Attemp to download seed and seed.sig files for each available category''' + for category in categories: + filepath = self.config.defaults['seedsdir'] + "/" + category + ".seeds" + timestamp_path = filepath + ".timestamp" + url = self.config.defaults['seedurls'][category] + success, signedfile, timestamp = fetcher.fetch_file( + url, filepath, timestamp_path) + if timestamp != "": + up_to_date = False + successes.append(success) + url += ".sig" + filepath += ".sig" + success, signedfile, timestamp = fetcher.fetch_file( + url, filepath, timestamp_path) + if timestamp != "": + up_to_date = False + successes.append(success) + if False not in successes and not up_to_date: + print("Seeds need to be updated") + ack = None + while ack not in ("y", "yes", "n", "no"): + ack = py_input("Would you like to update the seeds now? (y/n) ").lower() + if ack in ("y", "yes"): + custom_args = copy.copy(args) + for attr in GKEY._fields: + if attr != "debug": + custom_args.attr = None + custom_args.category = None + custom_args.action = "update-seed" + print("Updating seeds") + self.run(custom_args) + elif False not in successes: + print("Seeds are up to date") + else: + print("Seed update check failed, check your internet connection.") # run the action func = getattr(self.actions, '%s' % self.cli_config['Action_Map'][args.action]['func']) diff --git a/gkeys/gkeys/seedhandler.py b/gkeys/gkeys/seedhandler.py index c7dad2e..90ce583 100644 --- a/gkeys/gkeys/seedhandler.py +++ b/gkeys/gkeys/seedhandler.py @@ -78,21 +78,28 @@ class SeedHandler(object): @param seeds2: set of seeds to be compared @return added_gkeys: list of keys that are included in seed2 but not seed1 @return changed_gkeys: list of keys that are included in seed1 and seed2 but have been altered + @return removed_gkeys: list of keys that are included in seed1 but not in seed2 ''' old_gkeys = seeds1[1] new_gkeys = seeds2[1] changed_gkeys = [] + old_changed_gkeys = [] + removed_gkeys = [] added_gkeys = [] if old_gkeys: for new_gkey in new_gkeys: for old_gkey in old_gkeys: if new_gkey.nick == old_gkey.nick and new_gkey != old_gkey: changed_gkeys.append(new_gkey) + old_changed_gkeys.append(old_gkey) if new_gkey not in old_gkeys and new_gkey not in changed_gkeys: added_gkeys.append(new_gkey) + for old_gkey in old_gkeys: + if old_gkey not in new_gkeys and old_gkey not in old_changed_gkeys: + removed_gkeys.append(old_gkey) else: added_gkeys = new_gkeys - return(added_gkeys, changed_gkeys) + return(added_gkeys, changed_gkeys, removed_gkeys) def load_seeds(self, seedfile=None, filepath=None, refresh=False): '''Load seed file