commit: 4d712142d792cf5803428f9ec5f2a618c89b4135 Author: Devan Franchini <twitch153 <AT> gentoo <DOT> org> AuthorDate: Wed May 14 22:08:45 2014 +0000 Commit: Devan Franchini <twitch153 <AT> gentoo <DOT> org> CommitDate: Wed May 14 22:08:45 2014 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/layman.git;a=commit;h=4d712142
layman/cli.py: Adds byte array support. When checking the selection of which servers to sync/add there is a check to see if 'ALL' is specified. In py2 with argparser this works, but with py3 and argparser, this doesn't work because the 'ALL' string will come in as a bytearray. This commit fixes that by checking the python version and assigned a varaible to be checked instead of a simple string like 'ALL'. It will now come in as either 'ALL' or b'ALL', py version dependent. A small fix is also made to docstring to make the print function py3 compatibile. --- layman/cli.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/layman/cli.py b/layman/cli.py index cccddc6..460114a 100644 --- a/layman/cli.py +++ b/layman/cli.py @@ -30,7 +30,10 @@ from layman.utils import (decode_selection, encoder, get_encoding, from layman.constants import (NOT_OFFICIAL_MSG, NOT_SUPPORTED_MSG, FAILURE, SUCCEED) - +if sys.hexversion >= 0x30200f0: + ALL_KEYWORD = b'ALL' +else: + ALL_KEYWORD = 'ALL' class ListPrinter(object): def __init__(self, config): @@ -103,7 +106,7 @@ class ListPrinter(object): def short_list(self, overlay): ''' - >>> print short_list(overlay) + >>> print(short_list(overlay)) wrobel [Subversion] (https://o.g.o/svn/dev/wrobel ) ''' name = pad(overlay['name'], 25) @@ -184,7 +187,6 @@ class Main(object): a=act.intersection(k) self.output.debug('Actions = %s' % str(a), 4) for action in self.actions: - self.output.debug('Checking for action %s' % action[0], 4) if action[0] in list(self.config.keys()): @@ -234,13 +236,14 @@ class Main(object): ''' self.output.info("Adding overlay,...", 2) selection = decode_selection(self.config['add']) - if 'ALL' in selection: + if ALL_KEYWORD in selection: + selection = str(selection) selection = self.api.get_available() self.output.debug('Adding selected overlays', 6) result = self.api.add_repos(selection, update_news=True) if result: - self.output.info('Successfully added overlay(s) '+\ - ', '.join(selection) +'.', 2) + selection = b', '.join(selection) + self.output.info('Successfully added overlay(s) '+ selection.decode('UTF-8') +'.', 2) # blank newline -- no " *" self.output.notice('') return result @@ -253,7 +256,7 @@ class Main(object): self.output.info("Syncing selected overlays,...", 2) # Note api.sync() defaults to printing results selection = decode_selection(self.config['sync']) - if self.config['sync_all'] or 'ALL' in selection: + if self.config['sync_all'] or ALL_KEYWORD in selection: selection = self.api.get_installed() self.output.debug('Updating selected overlays', 6) result = self.api.sync(selection, update_news=True) @@ -267,7 +270,7 @@ class Main(object): ''' self.output.info('Deleting selected overlays,...', 2) selection = decode_selection(self.config['delete']) - if 'ALL' in selection: + if ALL_KEYWORD in selection: selection = self.api.get_installed() result = self.api.delete_repos(selection) if result: @@ -282,7 +285,7 @@ class Main(object): ''' Print information about the specified overlays. ''' selection = decode_selection(self.config['info']) - if 'ALL' in selection: + if ALL_KEYWORD in selection: selection = self.api.get_available() list_printer = ListPrinter(self.config)