Gentoo Archives: gentoo-commits

From: Brian Dolbec <brian.dolbec@×××××.com>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/layman:master commit in: layman/
Date: Wed, 27 Apr 2011 11:00:27
Message-Id: 50833d06b407b6028d6b6ec66e938bc26cc23141.dol-sen@gentoo
1 commit: 50833d06b407b6028d6b6ec66e938bc26cc23141
2 Author: Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
3 AuthorDate: Fri Mar 18 04:17:23 2011 +0000
4 Commit: Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
5 CommitDate: Sun Mar 27 02:39:13 2011 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/layman.git;a=commit;h=50833d06
7
8 remove no longer used action.py
9
10 ---
11 layman/action.py | 570 ------------------------------------------------------
12 1 files changed, 0 insertions(+), 570 deletions(-)
13
14 diff --git a/layman/action.py b/layman/action.py
15 deleted file mode 100644
16 index 7199054..0000000
17 --- a/layman/action.py
18 +++ /dev/null
19 @@ -1,570 +0,0 @@
20 -#!/usr/bin/python
21 -# -*- coding: utf-8 -*-
22 -#################################################################################
23 -# LAYMAN ACTIONS
24 -#################################################################################
25 -# File: action.py
26 -#
27 -# Handles layman actions.
28 -#
29 -# Copyright:
30 -# (c) 2005 - 2008 Gunnar Wrobel
31 -# Distributed under the terms of the GNU General Public License v2
32 -#
33 -# Author(s):
34 -# Gunnar Wrobel <wrobel@g.o>
35 -#
36 -''' Provides the different actions that can be performed by layman.'''
37 -
38 -__version__ = "$Id: action.py 312 2007-04-09 19:45:49Z wrobel $"
39 -
40 -#===============================================================================
41 -#
42 -# Dependencies
43 -#
44 -#-------------------------------------------------------------------------------
45 -
46 -import os, sys
47 -
48 -from layman.dbbase import UnknownOverlayException
49 -from layman.db import DB, RemoteDB
50 -from layman.utils import path, delete_empty_directory
51 -from layman.debug import OUT
52 -
53 -#===============================================================================
54 -#
55 -# Class Fetch
56 -#
57 -#-------------------------------------------------------------------------------
58 -
59 -class Fetch:
60 - ''' Fetches the overlay listing.
61 -
62 - >>> import os
63 - >>> here = os.path.dirname(os.path.realpath(__file__))
64 - >>> cache = os.tmpnam()
65 - >>> config = {'overlays' :
66 - ... 'file://' + here + '/tests/testfiles/global-overlays.xml',
67 - ... 'cache' : cache,
68 - ... 'nocheck' : True,
69 - ... 'proxy' : None,
70 - ... 'quietness':3,
71 - ... 'svn_command':'/usr/bin/svn',
72 - ... 'rsync_command':'/usr/bin/rsync'}
73 - >>> a = Fetch(config)
74 - >>> a.run()
75 - 0
76 - >>> b = open(a.db.path(config['overlays']))
77 - >>> b.readlines()[24]
78 - ' A collection of ebuilds from Gunnar Wrobel [wrobel@g.o].\\n'
79 -
80 - >>> b.close()
81 - >>> os.unlink(a.db.path(config['overlays']))
82 -
83 - >>> a.db.overlays.keys()
84 - [u'wrobel', u'wrobel-stable']
85 - '''
86 -
87 - def __init__(self, config):
88 - self.db = RemoteDB(config, ignore_init_read_errors=True)
89 -
90 - def run(self):
91 - '''Fetch the overlay listing.'''
92 - try:
93 - self.db.cache()
94 - except Exception, error:
95 - OUT.die('Failed to fetch overlay list!\nError was: '
96 - + str(error))
97 -
98 - return 0
99 -
100 -#===============================================================================
101 -#
102 -# Class Sync
103 -#
104 -#-------------------------------------------------------------------------------
105 -
106 -class Sync:
107 - ''' Syncs the selected overlays.'''
108 -
109 - def __init__(self, config):
110 -
111 - self.db = DB(config)
112 -
113 - self.rdb = RemoteDB(config)
114 -
115 - self.quiet = int(config['quietness']) < 3
116 -
117 - self.selection = config['sync']
118 -
119 - if config['sync_all'] or 'ALL' in self.selection:
120 - self.selection = self.db.overlays.keys()
121 -
122 - enc = sys.getfilesystemencoding()
123 - if enc:
124 - self.selection = [i.decode(enc) for i in self.selection]
125 -
126 - def run(self):
127 - '''Synchronize the overlays.'''
128 -
129 - OUT.debug('Updating selected overlays', 6)
130 -
131 - fatals = []
132 - warnings = []
133 - success = []
134 - for i in self.selection:
135 - try:
136 - odb = self.db.select(i)
137 - except UnknownOverlayException, error:
138 - fatals.append(str(error))
139 - continue
140 -
141 - try:
142 - ordb = self.rdb.select(i)
143 - except UnknownOverlayException:
144 - warnings.append(\
145 - 'Overlay "%s" could not be found in the remote lists.\n'
146 - 'Please check if it has been renamed and re-add if necessary.' % i)
147 - else:
148 - current_src = odb.sources[0].src
149 - available_srcs = set(e.src for e in ordb.sources)
150 - if ordb and odb and not current_src in available_srcs:
151 - if len(available_srcs) == 1:
152 - plural = ''
153 - candidates = ' %s' % tuple(available_srcs)[0]
154 - else:
155 - plural = 's'
156 - candidates = '\n'.join((' %d. %s' % (i + 1, v)) for i, v in enumerate(available_srcs))
157 -
158 - warnings.append(
159 - 'The source of the overlay "%(repo_name)s" seems to have changed.\n'
160 - 'You currently sync from\n'
161 - '\n'
162 - ' %(current_src)s\n'
163 - '\n'
164 - 'while the remote lists report\n'
165 - '\n'
166 - '%(candidates)s\n'
167 - '\n'
168 - 'as correct location%(plural)s.\n'
169 - 'Please consider removing and re-adding the overlay.' % {
170 - 'repo_name':i,
171 - 'current_src':current_src,
172 - 'candidates':candidates,
173 - 'plural':plural,
174 - })
175 -
176 - try:
177 - self.db.sync(i, self.quiet)
178 - success.append('Successfully synchronized overlay "' + i + '".')
179 - except Exception, error:
180 - fatals.append(
181 - 'Failed to sync overlay "' + i + '".\nError was: '
182 - + str(error))
183 -
184 - if success:
185 - OUT.info('\nSuccess:\n------\n', 3)
186 - for i in success:
187 - OUT.info(i, 3)
188 -
189 - if warnings:
190 - OUT.warn('\nWarnings:\n------\n', 2)
191 - for i in warnings:
192 - OUT.warn(i + '\n', 2)
193 -
194 - if fatals:
195 - OUT.error('\nErrors:\n------\n')
196 - for i in fatals:
197 - OUT.error(i + '\n')
198 - return 1
199 -
200 - return 0
201 -
202 -#===============================================================================
203 -#
204 -# Class Add
205 -#
206 -#-------------------------------------------------------------------------------
207 -
208 -class Add:
209 - ''' Adds the selected overlays.'''
210 -
211 - def __init__(self, config):
212 -
213 - self.config = config
214 -
215 - self.db = DB(config)
216 -
217 - self.rdb = RemoteDB(config)
218 -
219 - self.quiet = int(config['quietness']) < 3
220 -
221 - self.selection = config['add']
222 -
223 - enc = sys.getfilesystemencoding()
224 - if enc:
225 - self.selection = [i.decode(enc) for i in self.selection]
226 -
227 - if 'ALL' in self.selection:
228 - self.selection = self.rdb.overlays.keys()
229 -
230 - def run(self):
231 - '''Add the overlay.'''
232 -
233 - OUT.debug('Adding selected overlays', 6)
234 -
235 - result = 0
236 -
237 - for i in self.selection:
238 - try:
239 - overlay = self.rdb.select(i)
240 - except UnknownOverlayException, error:
241 - OUT.warn(str(error), 2)
242 - result = 1
243 - else:
244 - OUT.debug('Selected overlay', 7)
245 - try:
246 - self.db.add(overlay, self.quiet)
247 - OUT.info('Successfully added overlay "' + i + '".', 2)
248 - except Exception, error:
249 - OUT.warn('Failed to add overlay "' + i + '".\nError was: '
250 - + str(error), 2)
251 - result = 1
252 -
253 - return result
254 -
255 -#===============================================================================
256 -#
257 -# Class Delete
258 -#
259 -#-------------------------------------------------------------------------------
260 -
261 -class Delete:
262 - ''' Deletes the selected overlays.'''
263 -
264 - def __init__(self, config):
265 -
266 - self.db = DB(config)
267 -
268 - self.selection = config['delete']
269 -
270 - enc = sys.getfilesystemencoding()
271 - if enc:
272 - self.selection = [i.decode(enc) for i in self.selection]
273 -
274 - if 'ALL' in self.selection:
275 - self.selection = self.db.overlays.keys()
276 -
277 - def run(self):
278 - '''Delete the overlay.'''
279 -
280 - OUT.debug('Deleting selected overlays', 6)
281 -
282 - result = 0
283 -
284 - for i in self.selection:
285 - try:
286 - overlay = self.db.select(i)
287 - except UnknownOverlayException, error:
288 - OUT.warn(str(error), 2)
289 -
290 - mdir = path([self.db.config['storage'], i])
291 - delete_empty_directory(mdir)
292 -
293 - result = 1
294 - else:
295 - OUT.debug('Selected overlay', 7)
296 - try:
297 - self.db.delete(overlay)
298 - OUT.info('Successfully deleted overlay "' + i + '".', 2)
299 - except Exception, error:
300 - OUT.warn('Failed to delete overlay "' + i + '".\nError was: '
301 - + str(error), 2)
302 - result = 1
303 -
304 - return result
305 -
306 -#===============================================================================
307 -#
308 -# Class Info
309 -#
310 -#-------------------------------------------------------------------------------
311 -
312 -class Info:
313 - ''' Print information about the specified overlays.
314 -
315 - >>> import os
316 - >>> here = os.path.dirname(os.path.realpath(__file__))
317 - >>> cache = os.tmpnam()
318 - >>> config = {'overlays' :
319 - ... 'file://' + here + '/tests/testfiles/global-overlays.xml',
320 - ... 'cache' : cache,
321 - ... 'proxy' : None,
322 - ... 'info' : ['wrobel'],
323 - ... 'nocheck' : False,
324 - ... 'verbose': False,
325 - ... 'quietness':3,
326 - ... 'svn_command':'/usr/bin/svn',
327 - ... 'rsync_command':'/usr/bin/rsync'}
328 - >>> a = Info(config)
329 - >>> a.rdb.cache()
330 - >>> OUT.color_off()
331 - >>> a.run()
332 - * wrobel
333 - * ~~~~~~
334 - * Source : https://overlays.gentoo.org/svn/dev/wrobel
335 - * Contact : nobody@g.o
336 - * Type : Subversion; Priority: 10
337 - * Quality : experimental
338 - *
339 - * Description:
340 - * Test
341 - *
342 - 0
343 - '''
344 -
345 - def __init__(self, config):
346 -
347 - OUT.debug('Creating RemoteDB handler', 6)
348 -
349 - self.rdb = RemoteDB(config)
350 - self.config = config
351 -
352 - self.selection = config['info']
353 -
354 - enc = sys.getfilesystemencoding()
355 - if enc:
356 - self.selection = [i.decode(enc) for i in self.selection]
357 -
358 - if 'ALL' in self.selection:
359 - self.selection = self.rdb.overlays.keys()
360 -
361 - def run(self):
362 - ''' Print information about the selected overlays.'''
363 -
364 - result = 0
365 -
366 - for i in self.selection:
367 - try:
368 - overlay = self.rdb.select(i)
369 - except UnknownOverlayException, error:
370 - OUT.warn(str(error), 2)
371 - result = 1
372 - else:
373 - # Is the overlay supported?
374 - OUT.info(overlay.__str__(), 1)
375 - if not overlay.is_official():
376 - OUT.warn('*** This is no official gentoo overlay ***\n', 1)
377 - if not overlay.is_supported():
378 - OUT.error('*** You are lacking the necessary tools to install t'
379 - 'his overlay ***\n')
380 -
381 - return result
382 -
383 -#===============================================================================
384 -#
385 -# Class List
386 -#
387 -#-------------------------------------------------------------------------------
388 -
389 -class List(object):
390 - def __init__(self, config, db):
391 - self.config = config
392 - self.db = db
393 -
394 - def _run(self, complain):
395 - for summary, supported, official \
396 - in self.db.list(None, self.config['verbose'], self.config['width']):
397 - # Is the overlay supported?
398 - if supported:
399 - # Is this an official overlay?
400 - if official:
401 - OUT.info(summary, 1)
402 - # Unofficial overlays will only be listed if we are not
403 - # checking or listing verbose
404 - elif complain:
405 - # Give a reason why this is marked yellow if it is a verbose
406 - # listing
407 - if self.config['verbose']:
408 - OUT.warn('*** This is no official gentoo overlay ***\n', 1)
409 - OUT.warn(summary, 1)
410 - # Unsupported overlays will only be listed if we are not checking
411 - # or listing verbose
412 - elif complain:
413 - # Give a reason why this is marked red if it is a verbose
414 - # listing
415 - if self.config['verbose']:
416 - OUT.error('*** You are lacking the necessary tools '
417 - 'to install this overlay ***\n')
418 - OUT.error(summary)
419 -
420 -
421 -#===============================================================================
422 -#
423 -# Class ListRemote
424 -#
425 -#-------------------------------------------------------------------------------
426 -
427 -class ListRemote(List):
428 - ''' Lists the available overlays.
429 -
430 - >>> import os
431 - >>> here = os.path.dirname(os.path.realpath(__file__))
432 - >>> cache = os.tmpnam()
433 - >>> config = {'overlays' :
434 - ... 'file://' + here + '/tests/testfiles/global-overlays.xml',
435 - ... 'cache' : cache,
436 - ... 'proxy' : None,
437 - ... 'nocheck' : False,
438 - ... 'verbose': False,
439 - ... 'quietness':3,
440 - ... 'width':80,
441 - ... 'svn_command':'/usr/bin/svn',
442 - ... 'rsync_command':'/usr/bin/rsync'}
443 - >>> a = ListRemote(config)
444 - >>> a.db.cache()
445 - >>> OUT.color_off()
446 - >>> a.run()
447 - * wrobel [Subversion] (https://o.g.o/svn/dev/wrobel )
448 - 0
449 - >>> a.config['verbose'] = True
450 - >>> a.run()
451 - * wrobel
452 - * ~~~~~~
453 - * Source : https://overlays.gentoo.org/svn/dev/wrobel
454 - * Contact : nobody@g.o
455 - * Type : Subversion; Priority: 10
456 - * Quality : experimental
457 - *
458 - * Description:
459 - * Test
460 - *
461 - * *** This is no official gentoo overlay ***
462 - *
463 - * wrobel-stable
464 - * ~~~~~~~~~~~~~
465 - * Source : rsync://gunnarwrobel.de/wrobel-stable
466 - * Contact : nobody@g.o
467 - * Type : Rsync; Priority: 50
468 - * Quality : experimental
469 - *
470 - * Description:
471 - * A collection of ebuilds from Gunnar Wrobel [wrobel@g.o].
472 - *
473 - 0
474 - '''
475 -
476 - def __init__(self, config):
477 - OUT.debug('Creating RemoteDB handler', 6)
478 - super(ListRemote, self).__init__(config, RemoteDB(config))
479 -
480 - def run(self):
481 - ''' List the available overlays.'''
482 -
483 - OUT.debug('Printing remote overlays.', 8)
484 -
485 - _complain = self.config['nocheck'] or self.config['verbose']
486 - self._run(complain=_complain)
487 -
488 - return 0
489 -
490 -#===============================================================================
491 -#
492 -# Class ListLocal
493 -#
494 -#-------------------------------------------------------------------------------
495 -
496 -class ListLocal(List):
497 - ''' Lists the local overlays.'''
498 -
499 - def __init__(self, config):
500 - OUT.debug('Creating DB handler', 6)
501 - super(ListLocal, self).__init__(config, DB(config))
502 -
503 - def run(self):
504 - '''List the overlays.'''
505 -
506 - OUT.debug('Printing local overlays.', 8)
507 -
508 - self._run(complain=True)
509 -
510 - return 0
511 -
512 -#===============================================================================
513 -#
514 -# MAIN
515 -#
516 -#-------------------------------------------------------------------------------
517 -
518 -def main(config):
519 - '''Dispatches to the actions the user selected. '''
520 -
521 - # Given in order of precedence
522 - actions = [('fetch', Fetch),
523 - ('add', Add),
524 - ('sync', Sync),
525 - ('info', Info),
526 - ('sync_all', Sync),
527 - ('delete', Delete),
528 - ('list', ListRemote),
529 - ('list_local', ListLocal),]
530 -
531 - if True: # A hack to save diff with indentation changes only
532 -
533 - # Make fetching the overlay list a default action
534 - if not 'nofetch' in config.keys():
535 - # Actions that implicitely call the fetch operation before
536 - fetch_actions = ['sync', 'sync_all', 'list']
537 - for i in fetch_actions:
538 - if i in config.keys():
539 - # Implicitely call fetch, break loop
540 - Fetch(config).run()
541 - break
542 -
543 - result = 0
544 -
545 - # Set the umask
546 - umask = config['umask']
547 - try:
548 - new_umask = int(umask, 8)
549 - old_umask = os.umask(new_umask)
550 - except Exception, error:
551 - OUT.die('Failed setting to umask "' + umask + '"!\nError was: '
552 - + str(error))
553 -
554 - for i in actions:
555 -
556 - OUT.debug('Checking for action', 7)
557 -
558 - if i[0] in config.keys():
559 - try:
560 - result += i[1](config).run()
561 - except Exception, error:
562 - OUT.error(str(error))
563 - result = -1 # So it cannot remain 0, i.e. success
564 - break
565 -
566 - # Reset umask
567 - os.umask(old_umask)
568 -
569 - if not result:
570 - sys.exit(0)
571 - else:
572 - sys.exit(1)
573 -
574 -#===============================================================================
575 -#
576 -# Testing
577 -#
578 -#-------------------------------------------------------------------------------
579 -
580 -if __name__ == '__main__':
581 - import doctest
582 -
583 - # Ignore warnings here. We are just testing
584 - from warnings import filterwarnings, resetwarnings
585 - filterwarnings('ignore')
586 -
587 - doctest.testmod(sys.modules[__name__])
588 -
589 - resetwarnings()