From c8d258ef16d97e51ecdba271658068ddf00b8a5f Mon Sep 17 00:00:00 2001 From: Gunnar Wrobel Date: Tue, 11 Sep 2007 09:34:48 +0000 Subject: Layman v1.1 --- ChangeLog | 57 +++++++++++++++++++ doc/layman.8.xml | 38 +++++++++++-- layman/action.py | 76 ++++++++++++++++++++++++++ layman/config.py | 19 ++++++- layman/db.py | 16 +++--- layman/debug.py | 20 ++++--- layman/overlay.py | 5 +- layman/overlays/overlay.py | 44 +++++++++------ layman/overlays/rsync.py | 2 +- layman/overlays/tar.py | 6 +- layman/tests/testfiles/overlays_bug_184449.xml | 19 +++++++ layman/version.py | 2 +- 12 files changed, 258 insertions(+), 46 deletions(-) create mode 100644 layman/tests/testfiles/overlays_bug_184449.xml diff --git a/ChangeLog b/ChangeLog index ec01be0..e6df33a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,60 @@ +2007-09-11 Gunnar Wrobel + + * layman/config.py (Config.__init__): + * doc/layman.8.xml: + + Add "nocolor" option (#183364) + http://bugs.gentoo.org/show_bug.cgi?id=183364 + + * layman/db.py: + * layman/debug.py: + + Fixes for unicode bug #184449 + http://bugs.gentoo.org/show_bug.cgi?id=184449 + + * layman/overlays/rsync.py (RsyncOverlay.sync): + + Fix bug #177045 + http://bugs.gentoo.org/show_bug.cgi?id=177045 + + * doc/layman.8.xml: + + Improve the man page concerning the --overlays flag (#180107) + http://bugs.gentoo.org/show_bug.cgi?id=180107 + + * layman/db.py (DB.add): + * layman/overlays/overlay.py (Overlay.set_priority): + + Correctly handle the priority setting (#185142) + http://bugs.gentoo.org/show_bug.cgi?id=185142 + + * layman/config.py (Config.__init__): + + Finally fix the default for "nocheck" + + * layman/version.py: + + Update to version 1.1. + + * layman/config.py (Config.__init__): + * layman/action.py (Info.run): + * doc/layman.8.xml: + + Add the new "--info" option (bug #188000) + http://bugs.gentoo.org/show_bug.cgi?id=188000 + + * doc/layman.8.xml: + + Description of the verbose switch (partial fix + for #188004). + http://bugs.gentoo.org/show_bug.cgi?id=188004 + + * layman/config.py (Config.__init__): + + Add the output options into the list of documented + cli switches (partial fix for #188004). + http://bugs.gentoo.org/show_bug.cgi?id=188004 + 2007-01-09 Gunnar Wrobel * layman/version.py: diff --git a/doc/layman.8.xml b/doc/layman.8.xml index c966786..ecd2ec7 100644 --- a/doc/layman.8.xml +++ b/doc/layman.8.xml @@ -419,6 +419,14 @@ + + overlay + overlay + + Display all available information about the specified overlay. + + + @@ -468,10 +476,13 @@ Specifies the location of additional overlay lists. You can use this flag several times and the - specified urls will get appended to the list of urls you - specified in your config file. You may also specify - local file urls by prepending the path with - file:// + specified urls will get temporarily appended to the list + of urls you specified in your config file. You may also + specify local file urls by prepending the path with + file://. This option will only append the URL for this + specific layman run - edit your config file to add a URL + permanently. So this is useful for testing purposes. + @@ -513,6 +524,25 @@ + + + + + Makes layman more verbose and + you will receive a description of the overlays you can + download. + + + + + + + + Remove color codes from the layman + output. + + + LEVEL LEVEL diff --git a/layman/action.py b/layman/action.py index b2c67ce..b8259a5 100644 --- a/layman/action.py +++ b/layman/action.py @@ -92,6 +92,9 @@ class Sync: self.selection = config['sync'] + enc = sys.getfilesystemencoding() + self.selection = [i.decode(enc) for i in self.selection] + if config['sync_all'] or 'ALL' in self.selection: self.selection = self.db.overlays.keys() @@ -153,6 +156,9 @@ class Add: self.selection = config['add'] + enc = sys.getfilesystemencoding() + self.selection = [i.decode(enc) for i in self.selection] + if 'ALL' in self.selection: self.selection = self.rdb.overlays.keys() @@ -197,6 +203,9 @@ class Delete: self.selection = config['delete'] + enc = sys.getfilesystemencoding() + self.selection = [i.decode(enc) for i in self.selection] + if 'ALL' in self.selection: self.selection = self.db.overlays.keys() @@ -226,6 +235,72 @@ class Delete: return result +#=============================================================================== +# +# Class Info +# +#------------------------------------------------------------------------------- + +class Info: + ''' Print information about the specified overlays. + + >>> import os + >>> here = os.path.dirname(os.path.realpath(__file__)) + >>> cache = os.tmpnam() + >>> config = {'overlays' : + ... 'file://' + here + '/tests/testfiles/global-overlays.xml', + ... 'cache' : cache, + ... 'proxy' : None, + ... 'info' : ['wrobel'], + ... 'nocheck' : False, + ... 'verbose': False, + ... 'quietness':3} + >>> a = Info(config) + >>> a.rdb.cache() + >>> OUT.color_off() + >>> a.run() + * wrobel + * ~~~~~~ + * Source : https://overlays.gentoo.org/svn/dev/wrobel + * Contact : nobody@gentoo.org + * Type : Subversion; Priority: 10 + * + * Description: + * Test + * + 0 + ''' + + def __init__(self, config): + + OUT.debug('Creating RemoteDB handler', 6) + + self.rdb = RemoteDB(config) + self.config = config + + self.selection = config['info'] + + enc = sys.getfilesystemencoding() + self.selection = [i.decode(enc) for i in self.selection] + + if 'ALL' in self.selection: + self.selection = self.rdb.overlays.keys() + + def run(self): + ''' Print information about the selected overlays.''' + + for i in self.selection: + overlay = self.rdb.select(i) + # Is the overlay supported? + OUT.info(overlay.__str__(), 1) + if not overlay.is_official(): + OUT.warn('*** This is no official gentoo overlay ***\n', 1) + if not overlay.is_supported(): + OUT.error('*** You are lacking the necessary tools to install t' + 'his overlay ***\n') + + return 0 + #=============================================================================== # # Class List @@ -370,6 +445,7 @@ class Actions: actions = [('fetch', Fetch), ('add', Add), ('sync', Sync), + ('info', Info), ('sync_all', Sync), ('delete', Delete), ('list', List), diff --git a/layman/config.py b/layman/config.py index 287f223..d13806f 100644 --- a/layman/config.py +++ b/layman/config.py @@ -61,7 +61,7 @@ class Config(object): 'cache' : '%(storage)s/cache', 'local_list': '%(storage)s/overlays.xml', 'make_conf' : '%(storage)s/make.conf', - 'nocheck' : 'no', + 'nocheck' : 'yes', 'proxy' : '', 'overlays' : 'http://www.gentoo.org/proj/en/overlays/layman-global.' @@ -98,6 +98,12 @@ class Config(object): help = 'Update the specified overlay. Use "ALL" as para' 'meter to synchronize all overlays') + group.add_option('-i', + '--info', + action = 'append', + help = 'Display information about the specified overlay' + '.') + group.add_option('-S', '--sync-all', action = 'store_true', @@ -164,7 +170,8 @@ class Config(object): group.add_option('-v', '--verbose', action = 'store_true', - help = 'Increase amount of output.') + help = 'Increase the amount of output and describe the ' + 'overlays.') group.add_option('-q', '--quiet', @@ -176,6 +183,11 @@ class Config(object): 'xample if your overlay resides in subversion and the S' 'SL certificate of the server needs acceptance.') + group.add_option('-N', + '--nocolor', + action = 'store_true', + help = 'Remove color codes from the layman output.') + group.add_option('-Q', '--quietness', action = 'store', @@ -206,6 +218,9 @@ class Config(object): # handle debugging OUT.cli_handle(self.options) + if self.options.__dict__['nocolor']: + OUT.color_off() + # Fetch only an alternate config setting from the options if not self.options.__dict__['config'] is None: self.defaults['config'] = self.options.__dict__['config'] diff --git a/layman/db.py b/layman/db.py index ae32114..5019dfb 100644 --- a/layman/db.py +++ b/layman/db.py @@ -24,7 +24,7 @@ __version__ = "$Id: db.py 309 2007-04-09 16:23:38Z wrobel $" # #------------------------------------------------------------------------------- -import os, os.path, urllib2, re, md5 +import os, codecs, os.path, urllib2, re, md5 from layman.utils import path from layman.overlay import Overlays @@ -109,7 +109,7 @@ class DB(Overlays): result = overlay.add(self.config['storage']) if result == 0: if 'priority' in self.config.keys(): - overlay.priority = int(self.config['priority']) + overlay.set_priority(self.config['priority']) self.overlays[overlay.name] = overlay self.write(self.path) make_conf = MakeConf(self.config, self.overlays) @@ -398,7 +398,7 @@ class MakeConf: >>> [i.name for i in b.overlays] [u'wrobel', u'wrobel-stable'] >>> b.extra - ['/usr/portage/local/ebuilds/testing', '/usr/portage/local/ebuilds/stable', '/usr/portage/local/kolab2', '/usr/portage/local/gentoo-webapps-overlay/experimental', '/usr/portage/local/gentoo-webapps-overlay/production-ready'] + [u'/usr/portage/local/ebuilds/testing', u'/usr/portage/local/ebuilds/stable', u'/usr/portage/local/kolab2', u'/usr/portage/local/gentoo-webapps-overlay/experimental', u'/usr/portage/local/gentoo-webapps-overlay/production-ready'] >>> os.unlink(write) ''' @@ -426,7 +426,7 @@ class MakeConf: >>> [i.name for i in b.overlays] [] >>> b.extra - ['/usr/portage/local/ebuilds/testing', '/usr/portage/local/ebuilds/stable', '/usr/portage/local/kolab2', '/usr/portage/local/gentoo-webapps-overlay/experimental', '/usr/portage/local/gentoo-webapps-overlay/production-ready'] + [u'/usr/portage/local/ebuilds/testing', u'/usr/portage/local/ebuilds/stable', u'/usr/portage/local/kolab2', u'/usr/portage/local/gentoo-webapps-overlay/experimental', u'/usr/portage/local/gentoo-webapps-overlay/production-ready'] >>> os.unlink(write) ''' @@ -451,7 +451,7 @@ class MakeConf: >>> [i.name for i in a.overlays] [u'wrobel-stable'] >>> a.extra - ['/usr/portage/local/ebuilds/testing', '/usr/portage/local/ebuilds/stable', '/usr/portage/local/kolab2', '/usr/portage/local/gentoo-webapps-overlay/experimental', '/usr/portage/local/gentoo-webapps-overlay/production-ready'] + [u'/usr/portage/local/ebuilds/testing', u'/usr/portage/local/ebuilds/stable', u'/usr/portage/local/kolab2', u'/usr/portage/local/gentoo-webapps-overlay/experimental', u'/usr/portage/local/gentoo-webapps-overlay/production-ready'] ''' if os.path.isfile(self.path): self.content() @@ -510,7 +510,7 @@ class MakeConf: >>> [i.name for i in b.overlays] [u'wrobel-stable'] >>> b.extra - ['/usr/portage/local/ebuilds/testing', '/usr/portage/local/ebuilds/stable', '/usr/portage/local/kolab2', '/usr/portage/local/gentoo-webapps-overlay/experimental', '/usr/portage/local/gentoo-webapps-overlay/production-ready'] + [u'/usr/portage/local/ebuilds/testing', u'/usr/portage/local/ebuilds/stable', u'/usr/portage/local/kolab2', u'/usr/portage/local/gentoo-webapps-overlay/experimental', u'/usr/portage/local/gentoo-webapps-overlay/production-ready'] >>> os.unlink(write) ''' @@ -542,7 +542,7 @@ class MakeConf: 'le.') try: - make_conf = open(self.path, 'w') + make_conf = codecs.open(self.path, 'w', 'utf-8') make_conf.write(content) @@ -557,7 +557,7 @@ class MakeConf: Returns the content of the /etc/make.conf file. ''' try: - make_conf = open(self.path) + make_conf = codecs.open(self.path, 'r', 'utf-8') self.data = make_conf.read() diff --git a/layman/debug.py b/layman/debug.py index 925f49c..04682dc 100644 --- a/layman/debug.py +++ b/layman/debug.py @@ -13,7 +13,7 @@ __version__ = "$Id: debug.py 153 2006-06-05 06:03:16Z wrobel $" ## ################################################################################# -import sys, inspect +import sys, inspect, types from optparse import OptionGroup @@ -298,7 +298,8 @@ class Message: def info (self, info, level = 4): - info = str(info) + if type(info) not in types.StringTypes: + info = str(info) if level > self.info_lev: return @@ -308,7 +309,8 @@ class Message: def status (self, message, status, info = 'ignored'): - message = str(message) + if type(message) not in types.StringTypes: + message = str(message) lines = message.split('\n') @@ -335,7 +337,8 @@ class Message: def warn (self, warn, level = 4): - warn = str(warn) + if type(warn) not in types.StringTypes: + warn = str(warn) if level > self.warn_lev: return @@ -345,7 +348,8 @@ class Message: def error (self, error): - error = str(error) + if type(error) not in types.StringTypes: + error = str(error) for i in error.split('\n'): print >> self.error_out, self.maybe_color('red', '* ') + i @@ -353,7 +357,8 @@ class Message: def die (self, error): - error = str(error) + if type(error) not in types.StringTypes: + error = str(error) for i in error.split('\n'): self.error(self.maybe_color('red', 'Fatal error: ') + i) @@ -415,7 +420,8 @@ class Message: not str(callerobject.__class__.__name__) in self.debug_obj): return - message = str(message) + if type(message) not in types.StringTypes: + message = str(message) def breaklines(x): ''' diff --git a/layman/overlay.py b/layman/overlay.py index 38e9364..ffbf32f 100644 --- a/layman/overlay.py +++ b/layman/overlay.py @@ -24,7 +24,7 @@ __version__ = "$Id: overlay.py 273 2006-12-30 15:54:50Z wrobel $" # #------------------------------------------------------------------------------- -import os, os.path, xml.dom.minidom +import sys, codecs, os, os.path, xml.dom.minidom from layman.overlays.bzr import BzrOverlay from layman.overlays.darcs import DarcsOverlay @@ -161,7 +161,7 @@ class Overlays: try: - out_file = open(path, 'w') + out_file = codecs.open(path, 'w', 'utf-8') doc.writexml(out_file, '', ' ', '\n') @@ -178,7 +178,6 @@ class Overlays: >>> a.select('wrobel-stable').data['&src'] u'rsync://gunnarwrobel.de/wrobel-stable' ''' - if overlay in self.overlays.keys(): return self.overlays[overlay] diff --git a/layman/overlays/overlay.py b/layman/overlays/overlay.py index b7a006f..14aaa94 100644 --- a/layman/overlays/overlay.py +++ b/layman/overlays/overlay.py @@ -24,7 +24,7 @@ __version__ = "$Id: overlay.py 273 2006-12-30 15:54:50Z wrobel $" # #------------------------------------------------------------------------------- -import re, os, os.path, shutil, popen2 +import sys, types, re, os, os.path, shutil, popen2 from layman.utils import node_to_dict, dict_to_node, path @@ -112,6 +112,12 @@ class Overlay: else: self.priority = 50 + def set_priority(self, priority): + '''Set the priority of this overlay.''' + + self.data['&priority'] = str(priority) + self.priority = int(priority) + def to_minidom(self, document): '''Convert to xml.''' @@ -147,6 +153,10 @@ class Overlay: OUT.info('Running command "' + command + '"...', 2) + if hasattr(sys.stdout,'encoding'): + command = command.encode(sys.stdout.encoding or + sys.getfilesystemencoding()) + if not self.quiet: return os.system(command) else: @@ -178,29 +188,29 @@ class Overlay: ''' - result = '' + result = u'' - result += self.name + '\n' + (len(self.name) * '~') + result += self.name + u'\n' + (len(self.name) * u'~') - result += '\nSource : ' + self.src - result += '\nContact : ' + self.contact - result += '\nType : ' + self.type - result += '; Priority: ' + str(self.priority) + '\n' + result += u'\nSource : ' + self.src + result += u'\nContact : ' + self.contact + result += u'\nType : ' + self.type + result += u'; Priority: ' + str(self.priority) + u'\n' description = self.description - description = re.compile(' +').sub(' ', description) - description = re.compile('\n ').sub('\n', description) - result += '\nDescription:' - result += '\n '.join(('\n' + description).split('\n')) - result += '\n' + description = re.compile(u' +').sub(u' ', description) + description = re.compile(u'\n ').sub(u'\n', description) + result += u'\nDescription:' + result += u'\n '.join((u'\n' + description).split(u'\n')) + result += u'\n' if '1' in self.data.keys(): link = self.data['1']['@'].strip() - link = re.compile(' +').sub(' ', link) - link = re.compile('\n ').sub('\n', link) - result += '\nLink:\n' - result += '\n '.join(('\n' + link).split('\n')) - result += '\n' + link = re.compile(u' +').sub(u' ', link) + link = re.compile(u'\n ').sub(u'\n', link) + result += u'\nLink:\n' + result += u'\n '.join((u'\n' + link).split(u'\n')) + result += u'\n' return result diff --git a/layman/overlays/rsync.py b/layman/overlays/rsync.py index e2483ad..18d563f 100644 --- a/layman/overlays/rsync.py +++ b/layman/overlays/rsync.py @@ -58,7 +58,7 @@ class RsyncOverlay(Overlay): self.supported() - return self.cmd(self.base + '"' + self.src + '/*" "' + + return self.cmd(self.base + '"' + self.src + '/" "' + path([base, self.name]) + '"') def supported(self): diff --git a/layman/overlays/tar.py b/layman/overlays/tar.py index 24a9b91..ce89450 100644 --- a/layman/overlays/tar.py +++ b/layman/overlays/tar.py @@ -63,7 +63,7 @@ class TarOverlay(Overlay): type = 'Tar' - binary = '/bin/tar' + binary = u'/bin/tar' def __init__(self, xml, ignore = 0, quiet = False): @@ -138,8 +138,8 @@ class TarOverlay(Overlay): os.makedirs(target) - result = self.cmd(self.binary + ' -v -x ' + opt + ' -f "' + pkg - + '" -C "' + target + '"') + result = self.cmd(self.binary + u' -v -x ' + opt + u' -f "' + pkg + + u'" -C "' + target + u'"') if self.subpath: source = target + '/' + self.subpath diff --git a/layman/tests/testfiles/overlays_bug_184449.xml b/layman/tests/testfiles/overlays_bug_184449.xml new file mode 100644 index 0000000..c8dff2d --- /dev/null +++ b/layman/tests/testfiles/overlays_bug_184449.xml @@ -0,0 +1,19 @@ + + + + + + + Test ä + + + + + + diff --git a/layman/version.py b/layman/version.py index 943522b..c740a18 100644 --- a/layman/version.py +++ b/layman/version.py @@ -18,7 +18,7 @@ __version__ = "$Id: version.py 309 2007-04-09 16:23:38Z wrobel $" -VERSION = '1.0.99' +VERSION = '1.1' if __name__ == '__main__': print VERSION -- cgit v1.2.3-1-g7c22