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