From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 1A98B1381FA for ; Sun, 1 Jun 2014 15:25:46 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id A39BDE09C2; Sun, 1 Jun 2014 15:25:45 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id EAEFCE09C0 for ; Sun, 1 Jun 2014 15:25:44 +0000 (UTC) Received: from spoonbill.gentoo.org (spoonbill.gentoo.org [81.93.255.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id BECA833FE9F for ; Sun, 1 Jun 2014 15:25:43 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by spoonbill.gentoo.org (Postfix) with ESMTP id 41FD8182D4 for ; Sun, 1 Jun 2014 15:25:42 +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: <1401477959.2427bfa1c92a2c5d8450b7a7c08120fa9aee73be.dol-sen@gentoo> Subject: [gentoo-commits] proj/gentoo-keys:master commit in: gkeys/ X-VCS-Repository: proj/gentoo-keys X-VCS-Files: gkeys/actions.py gkeys/config.py X-VCS-Directories: gkeys/ X-VCS-Committer: dol-sen X-VCS-Committer-Name: Brian Dolbec X-VCS-Revision: 2427bfa1c92a2c5d8450b7a7c08120fa9aee73be X-VCS-Branch: master Date: Sun, 1 Jun 2014 15:25:42 +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: 9ea5bba2-6879-416d-82de-1b9be59f9cdd X-Archives-Hash: 9da6f90e79936566721409157b9b0699 commit: 2427bfa1c92a2c5d8450b7a7c08120fa9aee73be Author: Pavlos Ratis gentoo org> AuthorDate: Fri May 30 19:25:59 2014 +0000 Commit: Brian Dolbec gmail com> CommitDate: Fri May 30 19:25:59 2014 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoo-keys.git;a=commit;h=2427bfa1 implement fetchseed action and use sslfetch to download seeds --- gkeys/actions.py | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++---- gkeys/config.py | 3 +++ 2 files changed, 72 insertions(+), 4 deletions(-) diff --git a/gkeys/actions.py b/gkeys/actions.py index 1ecf4d3..5c4d934 100644 --- a/gkeys/actions.py +++ b/gkeys/actions.py @@ -13,14 +13,15 @@ from __future__ import print_function import os +import re - -from gkeys.seedhandler import SeedHandler +from gkeys.config import SEED_TYPES from gkeys.lib import GkeysGPG from gkeys.seed import Seeds +from gkeys.seedhandler import SeedHandler +from sslfetch.connections import Connector - -Available_Actions = ['listseed', 'addseed', 'removeseed', 'moveseed', +Available_Actions = ['listseed', 'addseed', 'removeseed', 'moveseed', 'fetchseed', 'listseedfiles', 'listkey', 'addkey', 'removekey', 'movekey', 'installed'] @@ -53,6 +54,62 @@ class Actions(object): return seeds + def fetch_seeds(self, seeds): + # setup the ssl-fetch ouptut map + connector_output = { + 'info': self.logger.info, + 'error': self.logger.error, + 'kwargs-info': {}, + 'kwargs-error': {}, + } + urls = [] + messages = [] + urls.append(self.config.get_key('developers.seeds')) + urls.append(self.config.get_key('release.seeds')) + if not re.search('^(http|https)://', urls[0]) and not re.search('^(http|https)://', urls[1]): + urls = [] + urls.append(self.config['seedurls']['developers.seeds']) + urls.append(self.config['seedurls']['release.seeds']) + fetcher = Connector(connector_output, None, "Gentoo Keys") + for url in zip(urls, SEED_TYPES): + timestamp_path = self.config['%s-timestamp' % url[1]] + success, seeds, timestamp = fetcher.fetch_content(url[0], timestamp_path) + if not timestamp: + messages += ["%s seed file is already up to date." % url[1]] + else: + with open(timestamp_path, 'w+') as timestampfile: + timestampfile.write(str(timestamp)) + timestampfile.write("\n") + if success and timestamp: + self.logger.debug("MAIN: _action_fetchseed; got results.") + filename = self.config['%s-seedfile' % url[1]] + '.new' + with open(filename, 'w') as seedfile: + seedfile.write(seeds) + filename = self.config['%s-seedfile' % url[1]] + old = filename + '.old' + try: + self.logger.info("Backing up existing file...") + if os.path.exists(old): + self.logger.debug( + "MAIN: _action_fetch_seeds; Removing 'old' seed file: %s" + % old) + os.unlink(old) + if os.path.exists(filename): + self.logger.debug( + "MAIN: _action_fetch_seeds; Renaming current seed file to: " + "%s" % old) + os.rename(filename, old) + self.logger.debug("MAIN: _action_fetch_seeds; Renaming '.new' seed file to %s" + % filename) + os.rename(filename + '.new', filename) + messages += ["Successfully fetched %s seed files." % url[1]] + except IOError: + raise + else: + messages += ["Failed to fetch %s seed file." % url[1]] + return messages + + def listseed(self, args): '''Action listseed method''' handler = SeedHandler(self.logger) @@ -69,6 +126,14 @@ class Actions(object): return None + def fetchseed(self, args): + '''Action fetchseed method''' + handler = SeedHandler(self.logger) + messages = self.fetch_seeds(args.seeds) + self.logger.debug("ACTIONS: fetchseed; args: %s" % str(args)) + return messages + + def addseed(self, args): '''Action addseed method''' handler = SeedHandler(self.logger) diff --git a/gkeys/config.py b/gkeys/config.py index 6941368..161315e 100644 --- a/gkeys/config.py +++ b/gkeys/config.py @@ -38,6 +38,7 @@ EPREFIX = "@GENTOO_PORTAGE_EPREFIX@" if "GENTOO_PORTAGE_EPREFIX" in EPREFIX: EPREFIX = '' +SEED_TYPES = ['dev', 'release'] class GKeysConfig(GPGConfig): @@ -72,6 +73,8 @@ class GKeysConfig(GPGConfig): self.defaults['seedsdir'] = '%(keysdir)s/seeds' self.defaults['release-seedfile'] = '%(seedsdir)s/release.seeds' self.defaults['dev-seedfile'] = '%(seedsdir)s/developer.seeds' + self.defaults['dev-timestamp'] = '%(keysdir)s/.developer_seeds_timestamp' + self.defaults['release-timestamp'] = '%(keysdir)s/.release_seeds_timestamp' self.defaults['keyserver'] = 'pool.sks-keyservers.net' self.defaults['seedurls'] = { 'release.seeds': 'https://dev.gentoo.org/~dolsen/gkey-seeds/release.seeds',