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 D443E13877A for ; Wed, 3 Sep 2014 23:36:29 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 99417E08C4; Wed, 3 Sep 2014 23:36:27 +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 AE854E08C2 for ; Wed, 3 Sep 2014 23:36:26 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 6D81B33F7DF for ; Wed, 3 Sep 2014 23:36:25 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 1444C4A3A for ; Wed, 3 Sep 2014 23:36:24 +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: <1409787292.f7e3f7afe051096798eebd485bf669e6569e48ac.dol-sen@gentoo> Subject: [gentoo-commits] proj/portage:plugin-sync commit in: pym/portage/sync/, pym/portage/sync/modules/websync/, ... X-VCS-Repository: proj/portage X-VCS-Files: pym/portage/sync/__init__.py pym/portage/sync/config_checks.py pym/portage/sync/controller.py pym/portage/sync/modules/cvs/__init__.py pym/portage/sync/modules/git/__init__.py pym/portage/sync/modules/rsync/__init__.py pym/portage/sync/modules/websync/__init__.py X-VCS-Directories: pym/portage/sync/ pym/portage/sync/modules/websync/ pym/portage/sync/modules/git/ pym/portage/sync/modules/rsync/ pym/portage/sync/modules/cvs/ X-VCS-Committer: dol-sen X-VCS-Committer-Name: Brian Dolbec X-VCS-Revision: f7e3f7afe051096798eebd485bf669e6569e48ac X-VCS-Branch: plugin-sync Date: Wed, 3 Sep 2014 23:36:24 +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: a9d90624-2bad-4fc8-88f9-04e320f6f65b X-Archives-Hash: 6f18b5df3e764fc87c5dad9e6ad59dfe commit: f7e3f7afe051096798eebd485bf669e6569e48ac Author: Brian Dolbec gentoo org> AuthorDate: Sun Mar 30 03:36:00 2014 +0000 Commit: Brian Dolbec gmail com> CommitDate: Wed Sep 3 23:34:52 2014 +0000 URL: http://sources.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=f7e3f7af Code the new validate_config system --- pym/portage/sync/__init__.py | 19 +++++++- pym/portage/sync/config_checks.py | 68 ++++++++++++++++++++++++++++ pym/portage/sync/controller.py | 7 +-- pym/portage/sync/modules/cvs/__init__.py | 20 ++++++++ pym/portage/sync/modules/git/__init__.py | 4 ++ pym/portage/sync/modules/rsync/__init__.py | 4 ++ pym/portage/sync/modules/websync/__init__.py | 4 ++ 7 files changed, 122 insertions(+), 4 deletions(-) diff --git a/pym/portage/sync/__init__.py b/pym/portage/sync/__init__.py index 65498ec..6d2a732 100644 --- a/pym/portage/sync/__init__.py +++ b/pym/portage/sync/__init__.py @@ -1,10 +1,11 @@ -# Copyright 2010 Gentoo Foundation +# Copyright 2014 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 import os from portage.emaint.module import Modules from portage.sync.controller import SyncManager +from portage.sync.config_checks import check_type sync_manager = None @@ -20,6 +21,13 @@ module_names = module_controller.module_names[:] def get_syncer(settings=None, logger=None): + '''Initializes and returns the SyncManager instance + to be used for sync operations + + @param settings: emerge.settings instance + @param logger: emerge logger instance + @returns SyncManager instance + ''' global sync_manager if sync_manager and not settings and not logger: return sync_manager @@ -33,4 +41,13 @@ def get_syncer(settings=None, logger=None): return sync_manager +def validate_config(repo, logger): + '''Validate the repos.conf settings for the repo''' + if not check_type(repo, logger, module_names): + return False + #print(repo) + if repo.sync_type: + validated = module_controller.modules[repo.sync_type]['validate_config'] + return validated(repo, logger).repo_checks() + return True diff --git a/pym/portage/sync/config_checks.py b/pym/portage/sync/config_checks.py new file mode 100644 index 0000000..8ef1974 --- /dev/null +++ b/pym/portage/sync/config_checks.py @@ -0,0 +1,68 @@ +# Copyright 2014 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 + +''' +Base class for performing repos.conf sync variables checks. +This class contains common checks code and functions. + +For additional checks or other customizations, +subclass it adding and/or overriding classes as needed. +''' + +import logging + +from portage.localization import _ +from portage.util import writemsg_level + + +def check_type(repo, logger, module_names): + if repo.sync_uri is not None and repo.sync_type is None: + writemsg_level("!!! %s\n" % + _("Repository '%s' has sync-uri attribute, but is missing sync-type attribute") + % repo.name, level=logger.ERROR, noiselevel=-1) + return False + if repo.sync_type not in module_names + [None]: + writemsg_level("!!! %s\n" % + _("Repository '%s' has sync-type attribute set to unsupported value: '%s'") + % (repo.name, repo.sync_type), + level=logger.ERROR, noiselevel=-1) + return False + return True + + +class CheckSyncConfig(object): + '''Base repos.conf settings checks class''' + + def __init__(self, repo=None, logger=None): + '''Class init function + + @param logger: optional logging instance, + defaults to logging module + ''' + self.logger = logger or logging + self.repo = repo + self.checks = ['check_uri', 'check_auto_sync'] + + + def repo_checks(self): + '''Perform all checks available''' + for check in self.checks: + getattr(self, check)() + + + def check_uri(self): + '''Check the sync_uri setting''' + if self.repo.sync_uri is None: + writemsg_level("!!! %s\n" % _("Repository '%s' has sync-type attribute, but is missing sync-uri attribute") + % self.repo.name, level=self.logger.ERROR, noiselevel=-1) + + + def check_auto_sync(self): + '''Check the auto_sync setting''' + if self.repo.auto_sync is None: + writemsg_level("!!! %s\n" % _("Repository '%s' is missing auto_sync attribute") + % self.repo.name, level=self.logger.ERROR, noiselevel=-1) + elif self.repo.auto_sync.lower() not in ["yes", "true", "no", "false"]: + writemsg_level("!!! %s\n" % _("Repository '%s' auto_sync attribute must be one of: %s") + % (self.repo.name, '{yes, true, no, false}'), + level=self.logger.ERROR, noiselevel=-1) diff --git a/pym/portage/sync/controller.py b/pym/portage/sync/controller.py index 5d2a8f5..e0e6910 100644 --- a/pym/portage/sync/controller.py +++ b/pym/portage/sync/controller.py @@ -1,4 +1,4 @@ -# Copyright 1999-2014 Gentoo Foundation +# Copyright 2014 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 from __future__ import print_function @@ -87,10 +87,11 @@ class SyncManager(object): self.module_names = self.module_controller.module_names[:] - def get_modules(self, mod): + def get_module_descriptions(self, mod): desc = self.module_controller.get_func_descriptions(mod) if desc: - pass + return desc + return [] def sync(self, emerge_config=None, repo=None, callback=None): diff --git a/pym/portage/sync/modules/cvs/__init__.py b/pym/portage/sync/modules/cvs/__init__.py index 7e786c0..93e0e26 100644 --- a/pym/portage/sync/modules/cvs/__init__.py +++ b/pym/portage/sync/modules/cvs/__init__.py @@ -6,6 +6,25 @@ Performs a cvs up on repositories """ +from portage.localization import _ +from portage.sync.config_checks import CheckSyncConfig +from portage.util import writemsg_level + + +class CheckCVSConfig(CheckSyncConfig): + + def __init__(self, logger): + CheckSyncConfig.__init__(self, logger) + self.checks.append('check_cvs_repo') + + + def check_cvs_repo(self): + if self.repo.sync_cvs_repo is None: + writemsg_level("!!! %s\n" % + _("Repository '%s' has sync-type=cvs, but is missing sync-cvs-repo attribute") + % self.repo.name, level=self.logger.ERROR, noiselevel=-1) + + module_spec = { 'name': 'cvs', 'description': __doc__, @@ -29,6 +48,7 @@ module_spec = { '"https://wiki.gentoo.org:Project:Portage" for details', }, }, + 'validate_config': CheckCVSConfig, } } } diff --git a/pym/portage/sync/modules/git/__init__.py b/pym/portage/sync/modules/git/__init__.py index 4ceaa84..eca44e2 100644 --- a/pym/portage/sync/modules/git/__init__.py +++ b/pym/portage/sync/modules/git/__init__.py @@ -6,6 +6,9 @@ Performs a git pull on repositories """ +from portage.sync.config_checks import CheckSyncConfig + + module_spec = { 'name': 'git', 'description': __doc__, @@ -29,6 +32,7 @@ module_spec = { '"https://wiki.gentoo.org:Project:Portage" for details', }, }, + 'validate_config': CheckSyncConfig, } } } diff --git a/pym/portage/sync/modules/rsync/__init__.py b/pym/portage/sync/modules/rsync/__init__.py index a0239bf..e3729ac 100644 --- a/pym/portage/sync/modules/rsync/__init__.py +++ b/pym/portage/sync/modules/rsync/__init__.py @@ -6,6 +6,9 @@ """ +from portage.sync.config_checks import CheckSyncConfig + + module_spec = { 'name': 'rsync', 'description': __doc__, @@ -28,6 +31,7 @@ module_spec = { '"https://wiki.gentoo.org:Project:Portage" for details', }, }, + 'validate_config': CheckSyncConfig, } } } diff --git a/pym/portage/sync/modules/websync/__init__.py b/pym/portage/sync/modules/websync/__init__.py index 1e0c342..8786210 100644 --- a/pym/portage/sync/modules/websync/__init__.py +++ b/pym/portage/sync/modules/websync/__init__.py @@ -8,6 +8,9 @@ Performs a http download of a portage snapshot and verifies and import os +from portage.sync.config_checks import CheckSyncConfig + + DEFAULT_CLASS = "WebRsync" AVAILABLE_CLASSES = [ "WebRsync", "PyWebsync"] options = {"1": "WebRsync", "2": "PyWebsync"} @@ -47,6 +50,7 @@ module_spec = { '"https://wiki.gentoo.org:Project:Portage" for details', }, }, + 'validate_config': CheckSyncConfig, }, } }