commit: 4e4991ca9eec1165147d3826d65354658feecb9c
Author: Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Wed Feb 19 07:48:57 2014 +0000
Commit: Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
CommitDate: Mon Jun 16 15:36:55 2014 +0000
URL:
http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=4e4991ca
Initial rough-in of a websync module.
This module is capable of both a bash or python webrsync version selectable
from an
environemnt variable "TESTIT". Later it can be converted to a portage/emerge
setting
when the python version has been coded.
---
pym/portage/sync/modules/websync/__init__.py | 50 ++++++++
pym/portage/sync/modules/websync/websync.py | 167 +++++++++++++++++++++++++++
2 files changed, 217 insertions(+)
diff --git a/pym/portage/sync/modules/websync/__init__.py
b/pym/portage/sync/modules/websync/__init__.py
new file mode 100644
index 0000000..22abf8c
--- /dev/null
+++ b/pym/portage/sync/modules/websync/__init__.py
@@ -0,0 +1,50 @@
+# Copyright 2014 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+"""WebRSync plug-in module for portage.
+Performs a http download of a portage snapshot and verifies and
+ unpacks it to the repo location.
+"""
+
+import os
+
+DEFAULT_CLASS = "WebRsync"
+AVAILABLE_CLASSES = [ "WebRsync", "PyWebsync"]
+options = {"1": "WebRsync", "2": "PyWebsync"}
+
+
+config_class = DEFAULT_CLASS
+try:
+ test_param = os.environ["TESTIT"]
+ if test_param in options:
+ config_class = options[test_param]
+except KeyError:
+ pass
+
+
+module_spec = {
+ 'name': 'webrsync',
+ 'description': __doc__,
+ 'provides':{
+ 'module1': {
+ 'name': "websync",
+ 'class': config_class,
+ 'description': __doc__,
+ 'functions': ['sync', 'new', 'exists'],
+ 'func_desc': {
+ 'sync': 'Performs a git pull on the repository',
+ 'new': 'Creates the new repository at the
specified location',
+ 'exists': 'Returns a boolean of whether the
specified dir ' +
+ 'exists and is a valid Git repository',
+ },
+ 'func_parameters': {
+ 'kwargs': {
+ 'type': dict,
+ 'description': 'Standard python
**kwargs parameter format' +
+ 'Please refer to the sync
modules specs at ' +
+
'"https://wiki.gentoo.org:Project:Portage" for details',
+ },
+ },
+ },
+ }
+}
diff --git a/pym/portage/sync/modules/websync/websync.py
b/pym/portage/sync/modules/websync/websync.py
new file mode 100644
index 0000000..5954a31
--- /dev/null
+++ b/pym/portage/sync/modules/websync/websync.py
@@ -0,0 +1,167 @@
+
+'''WebRsync module for portage'''
+
+class WebRsync(object):
+ '''WebRSync sync class'''
+
+ short_desc = "Perform sync operations on webrsync based repositories"
+
+ def name():
+ return "WebRSync"
+ name = staticmethod(name)
+
+
+ def can_progressbar(self, func):
+ return False
+
+
+ def __init__(self):
+ self.options = None
+ self.settings = None
+ self.logger = None
+ self.repo = None
+ self.xterm_titles = None
+
+ self.has_git = True
+ if portage.process.find_binary("emerge-webrsync") is None:
+ msg = ["Command not found: git",
+ "Type \"emerge %s\" to enable git support." %
portage.const.GIT_PACKAGE_ATOM]
+ for l in msg:
+ writemsg_level("!!! %s\n" % l,
+ level=logging.ERROR, noiselevel=-1)
+ self.has_git = False
+
+
+ def _kwargs(self, kwargs):
+ '''Sets internal variables from kwargs'''
+ self.options = kwargs.get('options', {})
+ self.settings = self.options.get('settings', None)
+ self.logger = self.options.get('logger', None)
+ self.repo = self.options.get('repo', None)
+ self.xterm_titles = self.options.get('xterm_titles', False)
+
+
+ def exists(self, **kwargs):
+ '''Tests whether the repo actually exists'''
+ if kwargs:
+ self._kwargs(kwargs)
+ elif not self.repo:
+ return False
+ spawn_kwargs = self.options.get('spawn_kwargs', None)
+
+ if not os.path.exists(self.repo.location):
+ return False
+ return True
+
+
+ def sync(self, **kwargs):
+ '''Sync the repository'''
+ if kwargs:
+ self._kwargs(kwargs)
+
+ if not self.has_git:
+ return (1, False)
+
+ if not self.exists():
+ return self.new()
+ return self._sync()
+
+
+ def new(self, **kwargs):
+ '''Do the initial download and install of the repository'''
+ pass
+
+ def _sync(self):
+ ''' Update existing repository
+ '''
+ pass
+
+ def post_sync(self, portdb, location, emerge_config):
+ '''repo.sync_type == "websync":
+ # NOTE: Do this after reloading the config, in case
+ # it did not exist prior to sync, so that the config
+ # and portdb properly account for its existence.
+ '''
+ pass
+
+
+class PyWebRsync(object):
+ '''WebRSync sync class'''
+
+ short_desc = "Perform sync operations on webrsync based repositories"
+
+ def name():
+ return "WebRSync"
+ name = staticmethod(name)
+
+
+ def can_progressbar(self, func):
+ return False
+
+
+ def __init__(self):
+ self.options = None
+ self.settings = None
+ self.logger = None
+ self.repo = None
+ self.xterm_titles = None
+
+ #if portage.process.find_binary("gpg") is None:
+ #msg = ["Command not found: gpg",
+ #"Type \"emerge %s\" to enable blah support." %
'emerge-webrsync']
+ #for l in msg:
+ #writemsg_level("!!! %s\n" % l,
+ # level=logging.ERROR, noiselevel=-1)
+
+
+ def _kwargs(self, kwargs):
+ '''Sets internal variables from kwargs'''
+ self.options = kwargs.get('options', {})
+ self.settings = self.options.get('settings', None)
+ self.logger = self.options.get('logger', None)
+ self.repo = self.options.get('repo', None)
+ self.xterm_titles = self.options.get('xterm_titles', False)
+
+
+ def exists(self, **kwargs):
+ '''Tests whether the repo actually exists'''
+ if kwargs:
+ self._kwargs(kwargs)
+ elif not self.repo:
+ return False
+ spawn_kwargs = self.options.get('spawn_kwargs', None)
+
+ if not os.path.exists(self.repo.location):
+ return False
+ return True
+
+
+ def sync(self, **kwargs):
+ '''Sync/Clone the repository'''
+ if kwargs:
+ self._kwargs(kwargs)
+
+ if not self.has_git:
+ return (1, False)
+
+ if not self.exists():
+ return self.new()
+ return self._sync()
+
+
+ def new(self, **kwargs):
+ '''Do the initial download and install of the repository'''
+ pass
+
+ def _sync(self):
+ ''' Update existing repository
+ '''
+ pass
+
+ def post_sync(self, portdb, location, emerge_config):
+ '''repo.sync_type == "websync":
+ # NOTE: Do this after reloading the config, in case
+ # it did not exist prior to sync, so that the config
+ # and portdb properly account for its existence.
+ '''
+ pass