From cc9a4f4324ba40527351ee21898a716b733334ad Mon Sep 17 00:00:00 2001 From: Michael Schwarz Date: Sat, 30 Aug 2014 11:58:34 +0200 Subject: [PATCH 1/3] Fixed TypeError when running ponysay --onelist. Traceback (most recent call last): File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/runpy.py", line 170, in _run_module_as_main "__main__", mod_spec) File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/runpy.py", line 85, in _run_code exec(code, run_globals) File "venv/bin/ponysay/__main__.py", line 154, in File "venv/bin/ponysay/ponysay.py", line 248, in run File "venv/bin/ponysay/ponysay.py", line 765, in onelist File "venv/bin/ponysay/lists.py", line 210, in onelist File "venv/bin/ponysay/lists.py", line 210, in File "venv/bin/ponysay/lists.py", line 104, in _get_file_list TypeError: listdir: illegal type for path parameter This bug was introduced in this commit: list.py: Extracted duplicate code for listing files in a directory into a utility function. I fixed the problem by removing the requirement for lists.onelist() to accept None for directory lists that should not be searched. --- src/lists.py | 13 ++++++------- src/ponysay.py | 6 +++--- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/lists.py b/src/lists.py index 298a45ad..dd7b7fa7 100755 --- a/src/lists.py +++ b/src/lists.py @@ -198,20 +198,19 @@ def linklist(ponydirs = None, quoters = [], ucsiser = None): _print_columnised(list(ponies)) -def onelist(standarddirs, extradirs = None, ucsiser = None): +def onelist(standarddirs, extradirs, ucsiser): ''' Lists the available ponies on one column without anything bold or otherwise formated - @param standard:itr? Include standard ponies - @param extra:itr? Include extra ponies - @param ucsiser:(list)?→void Function used to UCS:ise names + @param standard:itr Include standard ponies + @param extra:itr Include extra ponies + @param ucsiser:(list)→void Function used to UCS:ise names ''' ## Get all pony files - ponies = [j for i in [standarddirs, extradirs] for j in _get_file_list(i, '.pony')] + ponies = [name for dir_list in [standarddirs, extradirs] for dir in dir_list for name in _get_file_list(dir, '.pony')] ## UCS:ise and sort - if ucsiser is not None: - ucsiser(ponies) + ucsiser(ponies) ponies.sort() ## Print each one on a seperate line, but skip duplicates diff --git a/src/ponysay.py b/src/ponysay.py index f9560f5b..cea7a668 100755 --- a/src/ponysay.py +++ b/src/ponysay.py @@ -760,9 +760,9 @@ class Ponysay(): @param standard:bool Include standard ponies @param extra:bool Include extra ponies ''' - lists.onelist(self.ponydirs if standard else None, - self.extraponydirs if extra else None, - lambda x : self.__ucsise(x)) + lists.onelist(self.ponydirs if standard else [], + self.extraponydirs if extra else [], + self.__ucsise) def quoters(self, standard = True, extra = False): From 5125dd6400ca89a64f536be824a1de905f8a0920 Mon Sep 17 00:00:00 2001 From: Michael Schwarz Date: Sat, 30 Aug 2014 12:21:44 +0200 Subject: [PATCH 2/3] Fixed TypeError when running ponysay --altlist. Traceback (most recent call last): File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/runpy.py", line 170, in _run_module_as_main "__main__", mod_spec) File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/runpy.py", line 85, in _run_code exec(code, run_globals) File "./venv/bin/ponysay/__main__.py", line 154, in File "./venv/bin/ponysay/ponysay.py", line 252, in run File "./venv/bin/ponysay/ponysay.py", line 753, in linklist File "./venv/bin/ponysay/lists.py", line 143, in linklist File "./venv/bin/ponysay/lists.py", line 104, in _get_file_list TypeError: listdir: illegal type for path parameter This bug was introduced in this commit: list.py: Extracted duplicate code for listing files in a directory into a utility function. --- src/lists.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lists.py b/src/lists.py index dd7b7fa7..b3e8a56e 100755 --- a/src/lists.py +++ b/src/lists.py @@ -140,7 +140,7 @@ def linklist(ponydirs = None, quoters = [], ucsiser = None): for ponydir in ponydirs: # Loop ponydirs ## Get all pony files in the directory - ponies = _get_file_list(ponydirs, '.pony') + ponies = _get_file_list(ponydir, '.pony') ## If there are no ponies in the directory skip to next directory, otherwise, print the directories name if len(ponies) == 0: From 8861e0bb0e3a966f0e2b6ef753c0e85827f1eb25 Mon Sep 17 00:00:00 2001 From: Michael Schwarz Date: Sat, 30 Aug 2014 12:44:00 +0200 Subject: [PATCH 3/3] lists.onelist(): Instead of passing multiple, possibly empty lists, build the list of directories to search before calling the method. --- src/lists.py | 7 +++---- src/ponysay.py | 7 ++++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/lists.py b/src/lists.py index b3e8a56e..d06579b0 100755 --- a/src/lists.py +++ b/src/lists.py @@ -198,16 +198,15 @@ def linklist(ponydirs = None, quoters = [], ucsiser = None): _print_columnised(list(ponies)) -def onelist(standarddirs, extradirs, ucsiser): +def onelist(pony_dirs, ucsiser): ''' Lists the available ponies on one column without anything bold or otherwise formated - @param standard:itr Include standard ponies - @param extra:itr Include extra ponies + @param pony_dirs:itr List of directories to search for ponies @param ucsiser:(list)→void Function used to UCS:ise names ''' ## Get all pony files - ponies = [name for dir_list in [standarddirs, extradirs] for dir in dir_list for name in _get_file_list(dir, '.pony')] + ponies = [name for dir in pony_dirs for name in _get_file_list(dir, '.pony')] ## UCS:ise and sort ucsiser(ponies) diff --git a/src/ponysay.py b/src/ponysay.py index cea7a668..dd0768dc 100755 --- a/src/ponysay.py +++ b/src/ponysay.py @@ -760,9 +760,10 @@ class Ponysay(): @param standard:bool Include standard ponies @param extra:bool Include extra ponies ''' - lists.onelist(self.ponydirs if standard else [], - self.extraponydirs if extra else [], - self.__ucsise) + + pony_dirs = (self.ponydirs if standard else []) + (self.extraponydirs if extra else []) + + lists.onelist(pony_dirs, self.__ucsise) def quoters(self, standard = True, extra = False):