public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] proj/portage:plugin-sync commit in: pym/portage/sync/, pym/portage/sync/modules/websync/, ...
@ 2014-03-14 16:23 Brian Dolbec
  0 siblings, 0 replies; 6+ messages in thread
From: Brian Dolbec @ 2014-03-14 16:23 UTC (permalink / raw
  To: gentoo-commits

commit:     dfbaf158aa8e856db18818a26c7d182d90ca1080
Author:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Fri Mar 14 15:29:51 2014 +0000
Commit:     Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
CommitDate: Fri Mar 14 16:18:10 2014 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=dfbaf158

Sync modules: Use @staticmethod on name()'s.

---
 pym/portage/sync/modules/cvs/cvs.py         | 2 +-
 pym/portage/sync/modules/git/git.py         | 2 +-
 pym/portage/sync/modules/rsync/rsync.py     | 2 +-
 pym/portage/sync/modules/websync/websync.py | 2 +-
 pym/portage/sync/syncbase.py                | 2 +-
 5 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/pym/portage/sync/modules/cvs/cvs.py b/pym/portage/sync/modules/cvs/cvs.py
index c71f8e5..e169dbb 100644
--- a/pym/portage/sync/modules/cvs/cvs.py
+++ b/pym/portage/sync/modules/cvs/cvs.py
@@ -15,9 +15,9 @@ class CVSSync(object):
 
 	short_desc = "Perform sync operations on CVS repositories"
 
+	@staticmethod
 	def name():
 		return "CVSSync"
-	name = staticmethod(name)
 
 
 	def can_progressbar(self, func):

diff --git a/pym/portage/sync/modules/git/git.py b/pym/portage/sync/modules/git/git.py
index a820786..6806ef3 100644
--- a/pym/portage/sync/modules/git/git.py
+++ b/pym/portage/sync/modules/git/git.py
@@ -18,9 +18,9 @@ class GitSync(object):
 
 	short_desc = "Perform sync operations on git based repositories"
 
+	@staticmethod
 	def name():
 		return "GitSync"
-	name = staticmethod(name)
 
 
 	def can_progressbar(self, func):

diff --git a/pym/portage/sync/modules/rsync/rsync.py b/pym/portage/sync/modules/rsync/rsync.py
index 7495706..7122db8 100644
--- a/pym/portage/sync/modules/rsync/rsync.py
+++ b/pym/portage/sync/modules/rsync/rsync.py
@@ -28,9 +28,9 @@ class RsyncSync(object):
 
 	short_desc = "Perform sync operations on rsync based repositories"
 
+	@staticmethod
 	def name():
 		return "RsyncSync"
-	name = staticmethod(name)
 
 
 	def can_progressbar(self, func):

diff --git a/pym/portage/sync/modules/websync/websync.py b/pym/portage/sync/modules/websync/websync.py
index 7c31567..b0f4ed9 100644
--- a/pym/portage/sync/modules/websync/websync.py
+++ b/pym/portage/sync/modules/websync/websync.py
@@ -8,9 +8,9 @@ class WebRsync(SyncBase):
 
 	short_desc = "Perform sync operations on webrsync based repositories"
 
+	@staticmethod
 	def name():
 		return "WebRSync"
-	name = staticmethod(name)
 
 
 	def __init__(self):

diff --git a/pym/portage/sync/syncbase.py b/pym/portage/sync/syncbase.py
index d4f2ee7..9a840d6 100644
--- a/pym/portage/sync/syncbase.py
+++ b/pym/portage/sync/syncbase.py
@@ -6,9 +6,9 @@ class SyncBase(object):
 
 	short_desc = "Perform sync operations on repositories"
 
+	@staticmethod
 	def name():
 		return "BlankSync"
-	name = staticmethod(name)
 
 
 	def can_progressbar(self, func):


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [gentoo-commits] proj/portage:plugin-sync commit in: pym/portage/sync/, pym/portage/sync/modules/websync/, ...
@ 2014-04-22  2:36 Brian Dolbec
  0 siblings, 0 replies; 6+ messages in thread
From: Brian Dolbec @ 2014-04-22  2:36 UTC (permalink / raw
  To: gentoo-commits

commit:     a9fc210a533ecef6a1132a167435c13c245a1b75
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: Sun Mar 30 03:36:00 2014 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=a9fc210a

Code the new validate_config system

---
 pym/portage/sync/__init__.py                 | 18 +++++-
 pym/portage/sync/config_checks.py            | 85 ++++++++++++++++++++++------
 pym/portage/sync/controller.py               |  7 ++-
 pym/portage/sync/modules/cvs/__init__.py     | 19 +++++++
 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, 119 insertions(+), 22 deletions(-)

diff --git a/pym/portage/sync/__init__.py b/pym/portage/sync/__init__.py
index 65498ec..c097893 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,12 @@ 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):
+		return False
 
+	if repo.sync_tpye:
+		validated = module_controller.modules[repo.sync_type]['validate_config']
+		return validated(repo, logger)
+	return True

diff --git a/pym/portage/sync/config_checks.py b/pym/portage/sync/config_checks.py
index 8180d90..66d69da 100644
--- a/pym/portage/sync/config_checks.py
+++ b/pym/portage/sync/config_checks.py
@@ -1,26 +1,75 @@
+# 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.
+'''
 
-class CheckSyncEntries(object):
+import logging
 
-	def check_repo(repo):
-		if repo.sync_type is not None and repo.sync_uri is None:
-			writemsg_level("!!! %s\n" % _("Repository '%s' has sync-type attribute, but is missing sync-uri attribute") %
-				sname, level=logging.ERROR, noiselevel=-1)
-			continue
 
-		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") %
-				sname, level=logging.ERROR, noiselevel=-1)
-			continue
+def check_type(repo, logger):
+	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
 
-		if repo.sync_type not in portage.sync.module_names + [None]:
-			writemsg_level("!!! %s\n" % _("Repository '%s' has sync-type attribute set to unsupported value: '%s'") %
-				(sname, repo.sync_type), level=logging.ERROR, noiselevel=-1)
-			continue
 
-		if repo.sync_type == "cvs" and repo.sync_cvs_repo is None:
-			writemsg_level("!!! %s\n" % _("Repository '%s' has sync-type=cvs, but is missing sync-cvs-repo attribute") %
-				sname, level=logging.ERROR, noiselevel=-1)
-			continue
+class CheckSyncConfig(object):
+	'''Base repos.conf settings checks class'''
 
+	def __init__(self, logger=None):
+		'''Class init function
+
+		@param logger: optional logging instance,
+			defaults to logging module
+		'''
+		self.logger = logger or logging
+
+
+	def __call__(self, repo, logger=None):
+		'''Class call method
+
+		@param repo: RepoConfig instance
+		@param logger: optional logging instance'''
+		if logger:
+			self.logger = logger
+		self.repo = repo
+		self.repo_checks()
+		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")
+				% repo.name, level=self.logger.ERROR, noiselevel=-1)
+		if 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 e53d173..0c341e1 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
@@ -88,10 +88,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..9549aad 100644
--- a/pym/portage/sync/modules/cvs/__init__.py
+++ b/pym/portage/sync/modules/cvs/__init__.py
@@ -6,6 +6,9 @@ Performs a cvs up on repositories
 """
 
 
+from portage.sync.config_checks import CheckSyncConfig
+
+
 module_spec = {
 	'name': 'cvs',
 	'description': __doc__,
@@ -29,6 +32,22 @@ module_spec = {
 						'"https://wiki.gentoo.org:Project:Portage" for details',
 				},
 			},
+			'validate_config': CheckCVSConfig,
 		}
 	}
 }
+
+
+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_type == "cvs" and 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)
+

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 22abf8c..52356b7 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"}
@@ -45,6 +48,7 @@ module_spec = {
 						'"https://wiki.gentoo.org:Project:Portage" for details',
 				},
 			},
+			'validate_config': CheckSyncConfig,
 		},
 	}
 }


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [gentoo-commits] proj/portage:plugin-sync commit in: pym/portage/sync/, pym/portage/sync/modules/websync/, ...
@ 2014-05-02 23:13 Brian Dolbec
  0 siblings, 0 replies; 6+ messages in thread
From: Brian Dolbec @ 2014-05-02 23:13 UTC (permalink / raw
  To: gentoo-commits

commit:     bff56b63af5536b88ae88caa62bc865aceeaa891
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: Fri May  2 23:09:16 2014 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=bff56b63

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 a71cb96..70ec27b 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 22abf8c..52356b7 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"}
@@ -45,6 +48,7 @@ module_spec = {
 						'"https://wiki.gentoo.org:Project:Portage" for details',
 				},
 			},
+			'validate_config': CheckSyncConfig,
 		},
 	}
 }


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [gentoo-commits] proj/portage:plugin-sync commit in: pym/portage/sync/, pym/portage/sync/modules/websync/, ...
@ 2014-06-16 15:46 Brian Dolbec
  0 siblings, 0 replies; 6+ messages in thread
From: Brian Dolbec @ 2014-06-16 15:46 UTC (permalink / raw
  To: gentoo-commits

commit:     178c9daa04a41370033180718dcc3ba72ad93620
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: Mon Jun 16 15:36:56 2014 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=178c9daa

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 22abf8c..52356b7 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"}
@@ -45,6 +48,7 @@ module_spec = {
 						'"https://wiki.gentoo.org:Project:Portage" for details',
 				},
 			},
+			'validate_config': CheckSyncConfig,
 		},
 	}
 }


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [gentoo-commits] proj/portage:plugin-sync commit in: pym/portage/sync/, pym/portage/sync/modules/websync/, ...
@ 2014-06-16 22:45 Brian Dolbec
  0 siblings, 0 replies; 6+ messages in thread
From: Brian Dolbec @ 2014-06-16 22:45 UTC (permalink / raw
  To: gentoo-commits

commit:     8cde4153ac60167c706aee582f576fb465150aad
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: Mon Jun 16 22:43:11 2014 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=8cde4153

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,
 		},
 	}
 }


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [gentoo-commits] proj/portage:plugin-sync commit in: pym/portage/sync/, pym/portage/sync/modules/websync/, ...
@ 2014-09-03 23:36 Brian Dolbec
  0 siblings, 0 replies; 6+ messages in thread
From: Brian Dolbec @ 2014-09-03 23:36 UTC (permalink / raw
  To: gentoo-commits

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,
 		},
 	}
 }


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-09-03 23:36 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-06-16 22:45 [gentoo-commits] proj/portage:plugin-sync commit in: pym/portage/sync/, pym/portage/sync/modules/websync/, Brian Dolbec
  -- strict thread matches above, loose matches on Subject: below --
2014-09-03 23:36 Brian Dolbec
2014-06-16 15:46 Brian Dolbec
2014-05-02 23:13 Brian Dolbec
2014-04-22  2:36 Brian Dolbec
2014-03-14 16:23 Brian Dolbec

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox