Gentoo Archives: gentoo-commits

From: Brian Dolbec <brian.dolbec@×××××.com>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/portage:plugin-sync commit in: pym/portage/sync/modules/websync/
Date: Fri, 02 May 2014 23:13:37
Message-Id: 1398843526.dd5d1b8227d6e29ca80964890fb264146347ae14.dol-sen@gentoo
1 commit: dd5d1b8227d6e29ca80964890fb264146347ae14
2 Author: Brian Dolbec <dolsen <AT> gentoo <DOT> org>
3 AuthorDate: Wed Feb 19 07:48:57 2014 +0000
4 Commit: Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
5 CommitDate: Wed Apr 30 07:38:46 2014 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=dd5d1b82
7
8 Initial rough-in of a websync module.
9
10 This module is capable of both a bash or python webrsync version selectable from an
11 environemnt variable "TESTIT". Later it can be converted to a portage/emerge setting
12 when the python version has been coded.
13
14 ---
15 pym/portage/sync/modules/websync/__init__.py | 50 ++++++++
16 pym/portage/sync/modules/websync/websync.py | 167 +++++++++++++++++++++++++++
17 2 files changed, 217 insertions(+)
18
19 diff --git a/pym/portage/sync/modules/websync/__init__.py b/pym/portage/sync/modules/websync/__init__.py
20 new file mode 100644
21 index 0000000..22abf8c
22 --- /dev/null
23 +++ b/pym/portage/sync/modules/websync/__init__.py
24 @@ -0,0 +1,50 @@
25 +# Copyright 2014 Gentoo Foundation
26 +# Distributed under the terms of the GNU General Public License v2
27 +
28 +"""WebRSync plug-in module for portage.
29 +Performs a http download of a portage snapshot and verifies and
30 + unpacks it to the repo location.
31 +"""
32 +
33 +import os
34 +
35 +DEFAULT_CLASS = "WebRsync"
36 +AVAILABLE_CLASSES = [ "WebRsync", "PyWebsync"]
37 +options = {"1": "WebRsync", "2": "PyWebsync"}
38 +
39 +
40 +config_class = DEFAULT_CLASS
41 +try:
42 + test_param = os.environ["TESTIT"]
43 + if test_param in options:
44 + config_class = options[test_param]
45 +except KeyError:
46 + pass
47 +
48 +
49 +module_spec = {
50 + 'name': 'webrsync',
51 + 'description': __doc__,
52 + 'provides':{
53 + 'module1': {
54 + 'name': "websync",
55 + 'class': config_class,
56 + 'description': __doc__,
57 + 'functions': ['sync', 'new', 'exists'],
58 + 'func_desc': {
59 + 'sync': 'Performs a git pull on the repository',
60 + 'new': 'Creates the new repository at the specified location',
61 + 'exists': 'Returns a boolean of whether the specified dir ' +
62 + 'exists and is a valid Git repository',
63 + },
64 + 'func_parameters': {
65 + 'kwargs': {
66 + 'type': dict,
67 + 'description': 'Standard python **kwargs parameter format' +
68 + 'Please refer to the sync modules specs at ' +
69 + '"https://wiki.gentoo.org:Project:Portage" for details',
70 + },
71 + },
72 + },
73 + }
74 +}
75
76 diff --git a/pym/portage/sync/modules/websync/websync.py b/pym/portage/sync/modules/websync/websync.py
77 new file mode 100644
78 index 0000000..5954a31
79 --- /dev/null
80 +++ b/pym/portage/sync/modules/websync/websync.py
81 @@ -0,0 +1,167 @@
82 +
83 +'''WebRsync module for portage'''
84 +
85 +class WebRsync(object):
86 + '''WebRSync sync class'''
87 +
88 + short_desc = "Perform sync operations on webrsync based repositories"
89 +
90 + def name():
91 + return "WebRSync"
92 + name = staticmethod(name)
93 +
94 +
95 + def can_progressbar(self, func):
96 + return False
97 +
98 +
99 + def __init__(self):
100 + self.options = None
101 + self.settings = None
102 + self.logger = None
103 + self.repo = None
104 + self.xterm_titles = None
105 +
106 + self.has_git = True
107 + if portage.process.find_binary("emerge-webrsync") is None:
108 + msg = ["Command not found: git",
109 + "Type \"emerge %s\" to enable git support." % portage.const.GIT_PACKAGE_ATOM]
110 + for l in msg:
111 + writemsg_level("!!! %s\n" % l,
112 + level=logging.ERROR, noiselevel=-1)
113 + self.has_git = False
114 +
115 +
116 + def _kwargs(self, kwargs):
117 + '''Sets internal variables from kwargs'''
118 + self.options = kwargs.get('options', {})
119 + self.settings = self.options.get('settings', None)
120 + self.logger = self.options.get('logger', None)
121 + self.repo = self.options.get('repo', None)
122 + self.xterm_titles = self.options.get('xterm_titles', False)
123 +
124 +
125 + def exists(self, **kwargs):
126 + '''Tests whether the repo actually exists'''
127 + if kwargs:
128 + self._kwargs(kwargs)
129 + elif not self.repo:
130 + return False
131 + spawn_kwargs = self.options.get('spawn_kwargs', None)
132 +
133 + if not os.path.exists(self.repo.location):
134 + return False
135 + return True
136 +
137 +
138 + def sync(self, **kwargs):
139 + '''Sync the repository'''
140 + if kwargs:
141 + self._kwargs(kwargs)
142 +
143 + if not self.has_git:
144 + return (1, False)
145 +
146 + if not self.exists():
147 + return self.new()
148 + return self._sync()
149 +
150 +
151 + def new(self, **kwargs):
152 + '''Do the initial download and install of the repository'''
153 + pass
154 +
155 + def _sync(self):
156 + ''' Update existing repository
157 + '''
158 + pass
159 +
160 + def post_sync(self, portdb, location, emerge_config):
161 + '''repo.sync_type == "websync":
162 + # NOTE: Do this after reloading the config, in case
163 + # it did not exist prior to sync, so that the config
164 + # and portdb properly account for its existence.
165 + '''
166 + pass
167 +
168 +
169 +class PyWebRsync(object):
170 + '''WebRSync sync class'''
171 +
172 + short_desc = "Perform sync operations on webrsync based repositories"
173 +
174 + def name():
175 + return "WebRSync"
176 + name = staticmethod(name)
177 +
178 +
179 + def can_progressbar(self, func):
180 + return False
181 +
182 +
183 + def __init__(self):
184 + self.options = None
185 + self.settings = None
186 + self.logger = None
187 + self.repo = None
188 + self.xterm_titles = None
189 +
190 + #if portage.process.find_binary("gpg") is None:
191 + #msg = ["Command not found: gpg",
192 + #"Type \"emerge %s\" to enable blah support." % 'emerge-webrsync']
193 + #for l in msg:
194 + #writemsg_level("!!! %s\n" % l,
195 + # level=logging.ERROR, noiselevel=-1)
196 +
197 +
198 + def _kwargs(self, kwargs):
199 + '''Sets internal variables from kwargs'''
200 + self.options = kwargs.get('options', {})
201 + self.settings = self.options.get('settings', None)
202 + self.logger = self.options.get('logger', None)
203 + self.repo = self.options.get('repo', None)
204 + self.xterm_titles = self.options.get('xterm_titles', False)
205 +
206 +
207 + def exists(self, **kwargs):
208 + '''Tests whether the repo actually exists'''
209 + if kwargs:
210 + self._kwargs(kwargs)
211 + elif not self.repo:
212 + return False
213 + spawn_kwargs = self.options.get('spawn_kwargs', None)
214 +
215 + if not os.path.exists(self.repo.location):
216 + return False
217 + return True
218 +
219 +
220 + def sync(self, **kwargs):
221 + '''Sync/Clone the repository'''
222 + if kwargs:
223 + self._kwargs(kwargs)
224 +
225 + if not self.has_git:
226 + return (1, False)
227 +
228 + if not self.exists():
229 + return self.new()
230 + return self._sync()
231 +
232 +
233 + def new(self, **kwargs):
234 + '''Do the initial download and install of the repository'''
235 + pass
236 +
237 + def _sync(self):
238 + ''' Update existing repository
239 + '''
240 + pass
241 +
242 + def post_sync(self, portdb, location, emerge_config):
243 + '''repo.sync_type == "websync":
244 + # NOTE: Do this after reloading the config, in case
245 + # it did not exist prior to sync, so that the config
246 + # and portdb properly account for its existence.
247 + '''
248 + pass