summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Étienne Deparis 2020-01-28 13:32:06 +0100
committerGravatar Étienne Deparis 2020-01-28 13:32:06 +0100
commit52f6cbe8230713495b982988131a5e2d98ee86f0 (patch)
tree3174f0c703d1bd5f6f0357609d2c40a04c0b531b
parent0975d07ef23f01ff907a0fc36975d44fd4f24867 (diff)
downloadeshelf-52f6cbe8230713495b982988131a5e2d98ee86f0.tar.gz
eshelf-52f6cbe8230713495b982988131a5e2d98ee86f0.tar.xz
eshelf-52f6cbe8230713495b982988131a5e2d98ee86f0.zip
Improve file listing display
-rw-r--r--eshelf/utils.py36
1 files changed, 22 insertions, 14 deletions
diff --git a/eshelf/utils.py b/eshelf/utils.py
index 82edbb7..b348443 100644
--- a/eshelf/utils.py
+++ b/eshelf/utils.py
@@ -1,21 +1,29 @@
import os
+LIST_DECORATOR = '├──'
+LIST_FINAL_DECORATOR = '└──'
+LIST_CONTINUATION_DECORATOR = '│ '
+
+
def print_file_tree(current_dir, padding=None):
if padding is None:
padding = ''
- decorator = '├──'
- decorator_prefix = padding + '│ '
+ decorator = LIST_DECORATOR
+ decorator_prefix = padding + LIST_CONTINUATION_DECORATOR
- curfilelist = os.listdir(current_dir)
- curfilelistlen = len(curfilelist) - 1
- curpointer = 0
- for curfile in curfilelist:
- if curfile == '.eshelf.conf':
- continue
- if curpointer == curfilelistlen:
- decorator = '└──'
+ raw_file_list = os.listdir(current_dir)
+ file_list = list(filter(
+ lambda x: x != '.eshelf.conf',
+ raw_file_list,
+ ))
+ list_len = len(file_list)
+ curpointer = 1
+
+ for curfile in file_list:
+ if curpointer == list_len:
+ decorator = LIST_FINAL_DECORATOR
decorator_prefix = padding + ' '
curpointer += 1
print('{0}{1} {2}'.format(padding, decorator, curfile))
@@ -28,12 +36,12 @@ def print_listing(title, lines):
if len(lines) == 0:
return
print(title)
- decorator = '├──'
- curfilelistlen = len(lines) - 1
- curpointer = 0
+ decorator = LIST_DECORATOR
+ curfilelistlen = len(lines)
+ curpointer = 1
for line in lines:
if curpointer == curfilelistlen:
- decorator = '└──'
+ decorator = LIST_FINAL_DECORATOR
curpointer += 1
print('{0} {1}'.format(decorator, line))