Gentoo Archives: gentoo-commits

From: Chris Reffett <creffett@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/portage:plugin-sync commit in: pym/portage/sync/modules/cvs/
Date: Tue, 11 Feb 2014 17:28:49
Message-Id: 1392139647.d7ed98d9e4cd3bea7f65c7ac5d84d082ab906b26.creffett@gentoo
1 commit: d7ed98d9e4cd3bea7f65c7ac5d84d082ab906b26
2 Author: Chris Reffett <creffett <AT> gentoo <DOT> org>
3 AuthorDate: Tue Feb 11 17:27:27 2014 +0000
4 Commit: Chris Reffett <creffett <AT> gentoo <DOT> org>
5 CommitDate: Tue Feb 11 17:27:27 2014 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=d7ed98d9
7
8 Bring CVS module up to current module spec
9
10 Add exists(), new(), _sync() as in the git and rsync classes. Clean up
11 output style to use logger and writemsg_level instead of straight print
12 statements
13
14 ---
15 pym/portage/sync/modules/cvs/__init__.py | 21 ++++--
16 pym/portage/sync/modules/cvs/cvs.py | 119 ++++++++++++++++++++++---------
17 2 files changed, 101 insertions(+), 39 deletions(-)
18
19 diff --git a/pym/portage/sync/modules/cvs/__init__.py b/pym/portage/sync/modules/cvs/__init__.py
20 index a24eea9..7e786c0 100644
21 --- a/pym/portage/sync/modules/cvs/__init__.py
22 +++ b/pym/portage/sync/modules/cvs/__init__.py
23 @@ -2,7 +2,7 @@
24 # Distributed under the terms of the GNU General Public License v2
25
26 """CVS plug-in module for portage.
27 - Performs a git pull on the repo
28 +Performs a cvs up on repositories
29 """
30
31
32 @@ -14,8 +14,21 @@ module_spec = {
33 'name': "cvs",
34 'class': "CVSSync",
35 'description': __doc__,
36 - 'functions': ['sync',],
37 - 'func_desc': {'sync': 'Performs a cvs up on the repo'}
38 - }
39 + 'functions': ['sync', 'new', 'exists'],
40 + 'func_desc': {
41 + 'sync': 'Performs a cvs up on the repository',
42 + 'new': 'Creates the new repository at the specified location',
43 + 'exists': 'Returns a boolean of whether the specified dir ' +
44 + 'exists and is a valid CVS repository',
45 + },
46 + 'func_parameters': {
47 + 'kwargs': {
48 + 'type': dict,
49 + 'description': 'Standard python **kwargs parameter format' +
50 + 'Please refer to the sync modules specs at ' +
51 + '"https://wiki.gentoo.org:Project:Portage" for details',
52 + },
53 + },
54 }
55 }
56 +}
57
58 diff --git a/pym/portage/sync/modules/cvs/cvs.py b/pym/portage/sync/modules/cvs/cvs.py
59 index cd376b6..c71f8e5 100644
60 --- a/pym/portage/sync/modules/cvs/cvs.py
61 +++ b/pym/portage/sync/modules/cvs/cvs.py
62 @@ -13,7 +13,7 @@ from portage.util import writemsg_level
63 class CVSSync(object):
64 '''CVS sync module'''
65
66 - short_desc = "Perform sync operations on rsync based repositories"
67 + short_desc = "Perform sync operations on CVS repositories"
68
69 def name():
70 return "CVSSync"
71 @@ -26,52 +26,101 @@ class CVSSync(object):
72
73 def __init__(self):
74 self.settings = None
75 + self.options = None
76 + self.logger = None
77 + self.xterm_titles = None
78 + self.has_cvs = True
79 + if portage.process.find_binary("cvs") is None:
80 + msg = "Command not found: cvs"
81 + "Type \"emerge %s\" to enable CVS support." % portage.const.CVS_PACKAGE_ATOM
82 + for l in msg:
83 + writemsg_level("!!! %s\n" % l,
84 + level=logging.ERROR, noiselevel=-1)
85 + self.has_cvs = False
86 +
87 + def _kwargs(self, **kwargs):
88 + self.options = kwargs.get('options', {})
89 + self.repo = self.options.get('repo', None)
90 + self.logger = self.options.get('logger', None)
91 + self.xterm_titles = self.options.get('xterm_titles', None)
92 +
93 +
94 + def exists(self, **kwargs):
95 + if kwargs:
96 + self._kwargs(kwargs)
97 + elif not self.repo:
98 + return False
99 + spawn_kwargs = self.options.get('spawn_kwargs', None)
100 +
101 + if not os.path.exists(os.path.join(repo.location, "CVS")):
102 + return False
103 + return True
104
105
106 def sync(self, **kwargs):
107 - '''repo.sync_type == "cvs":'''
108 + if kwargs:
109 + self._kwargs(kwargs)
110
111 - if not os.path.exists("/usr/bin/cvs"):
112 - print("!!! /usr/bin/cvs does not exist, so CVS support is disabled.")
113 - print("!!! Type \"emerge %s\" to enable CVS support." % portage.const.CVS_PACKAGE_ATOM)
114 - return os.EX_UNAVAILABLE, False
115 + if not self.has_cvs:
116 + return (1, False)
117
118 + if not self.exists():
119 + return self.new()
120 + return self.sync()
121 +
122 +
123 + def new(self, **kwargs):
124 if kwargs:
125 - options = kwargs.get('options', {})
126 - repo = options.get('repo', None)
127 - spawn_kwargs = options.get('spawn_kwargs', None)
128 + self._kwargs(kwargs)
129 + #initial checkout
130 + msg = ">>> Starting initial cvs checkout with %s..." % self.repo.sync_uri
131 + self.logger(self.xterm_titles, msg)
132 + writemsg_level(msg + "\n")
133 + try:
134 + os.rmdir(self.repo.location)
135 + except OSError as e:
136 + if e.errno != errno.ENOENT:
137 + msg = "!!! existing '%s' directory; exiting." % self.repo.location
138 + self.logger(self.xterm_titles, msg)
139 + writemsg_level(msg + "\n", noiselevel=-1, level=logging.ERROR)
140 + return (1, False)
141 + del e
142 + if portage.process.spawn_bash(
143 + "cd %s; exec cvs -z0 -d %s co -P -d %s %s" %
144 + (portage._shell_quote(os.path.dirname(self.repo.location)), portage._shell_quote(cvs_root),
145 + portage._shell_quote(os.path.basename(self.repo.location)),
146 + portage._shell_quote(self.repo.sync_cvs_self.repo)),
147 + **portage._native_kwargs(spawn_kwargs)) != os.EX_OK:
148 + msg = "!!! cvs checkout error; exiting."
149 + self.logger(self.xterm_titles, msg)
150 + writemsg_level(msg + "\n", noiselevel=-1, level=logging.ERROR)
151 + return (1, False)
152 + return (0, False)
153 +
154 + def _sync(self):
155 + """
156 + Internal function to sync an existing CVS repository
157 +
158 + @return: tuple of return code (0=success), whether the cache
159 + needs to be updated
160 + @rtype: (int, bool)
161 + """
162 +
163 + spawn_kwargs = options.get('spawn_kwargs', None)
164 + cvs_root = self.repo.sync_uri
165
166 - cvs_root = repo.sync_uri
167 if cvs_root.startswith("cvs://"):
168 cvs_root = cvs_root[6:]
169 - if not os.path.exists(os.path.join(repo.location, "CVS")):
170 - #initial checkout
171 - print(">>> Starting initial cvs checkout with "+repo.sync_uri+"...")
172 - try:
173 - os.rmdir(repo.location)
174 - except OSError as e:
175 - if e.errno != errno.ENOENT:
176 - sys.stderr.write(
177 - "!!! existing '%s' directory; exiting.\n" % repo.location)
178 - exitcode = 1
179 - return (exitcode, False)
180 - del e
181 - if portage.process.spawn_bash(
182 - "cd %s; exec cvs -z0 -d %s co -P -d %s %s" %
183 - (portage._shell_quote(os.path.dirname(repo.location)), portage._shell_quote(cvs_root),
184 - portage._shell_quote(os.path.basename(repo.location)), portage._shell_quote(repo.sync_cvs_repo)),
185 - **portage._native_kwargs(spawn_kwargs)) != os.EX_OK:
186 - print("!!! cvs checkout error; exiting.")
187 - exitcode = 1
188 - else:
189 #cvs update
190 - print(">>> Starting cvs update with "+repo.sync_uri+"...")
191 + msg = ">>> Starting cvs update with %s..." % self.repo.sync_uri
192 + self.logger(self.xterm_titles, msg)
193 + writemsg_level(msg + "\n")
194 exitcode = portage.process.spawn_bash(
195 "cd %s; exec cvs -z0 -q update -dP" % \
196 - (portage._shell_quote(repo.location),),
197 + (portage._shell_quote(self.repo.location),),
198 **portage._native_kwargs(spawn_kwargs))
199 if exitcode != os.EX_OK:
200 - writemsg_level("!!! cvs update error; exiting.\n",
201 - noiselevel=-1, level=logging.ERROR)
202 + msg = "!!! cvs update error; exiting."
203 + self.logger(self.xterm_titles, msg)
204 + writemsg_level(msg + "\n", noiselevel=-1, level=logging.ERROR)
205 return (exitcode, False)
206 -