commit:     f7e3f7afe051096798eebd485bf669e6569e48ac
Author:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Sun Mar 30 03:36:00 2014 +0000
Commit:     Brian Dolbec <brian.dolbec <AT> gmail <DOT> 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,
                },
        }
 }

Reply via email to