diff --git a/README.md b/README.md index 2a657f7..a441e38 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,4 @@ -# nerd_tree +# Nerd tree -A bad version of the unix-like tree command and a visual version of find command that shows the results found in a visual tree \ No newline at end of file +An ugly version of the unix-like tree command and a visual version of find command that shows the results found in a visual tree. +Branch is unstable and under development diff --git a/src/__pycache__/tree_repr.cpython-39.pyc b/src/__pycache__/tree_repr.cpython-39.pyc new file mode 100644 index 0000000..a2293d0 Binary files /dev/null and b/src/__pycache__/tree_repr.cpython-39.pyc differ diff --git a/src/tree_repr.py b/src/tree_repr.py index 17b89fa..d6c323a 100644 --- a/src/tree_repr.py +++ b/src/tree_repr.py @@ -39,6 +39,8 @@ def nerd_tree_sort_dirfirst(startpath): files = [] dirs = [] + + for item in os.listdir(startpath): if os.path.isdir(startpath + item): dirs.append(item) @@ -60,46 +62,6 @@ def nerd_tree_sort(startpath, dirfirst=True): return os.listdir(startpath) -def OLDnerd_tree(startpath, prec_seps=[]): - if not startpath.endswith('/'): - tosplit = startpath - startpath = startpath + '/' - else: - tosplit = startpath[:-1] - - rootnode = tosplit.split('/')[-1] - - items = nerd_tree_sort(startpath, dirfirst=True) - - ## rootnode is always a dir -> colorize - nerd_tree_txt = 'd_' + rootnode - - for n, item in enumerate(items): - if item in ITEMS_TO_EXCLUDE: - continue - - islast = (n==len(items) -1) - - sep = CHILD_CONNECTOR - if islast: - sep = LAST_CHILD_CONNECTOR - - if not islast: - psep_char = VERTICAL_CONNECTOR - else: - psep_char = '' - - if os.path.isdir(startpath+item): - seps = prec_seps[:] - seps.append((psep_char, '')) - treeline = produce_treeline(prec_seps, (sep, ' ')) + ' ' + nerd_tree(startpath+item, prec_seps=seps) - else: - treeline = produce_treeline(prec_seps, (sep, item)) - - nerd_tree_txt += '\n' + treeline - - return nerd_tree_txt - def nerd_tree_from_struct(rootnode, prec_seps=[]): ''' rootnode is a dict @@ -176,7 +138,12 @@ def nerd_tree_struct(startpath, path=[]): } # using listdir - items = nerd_tree_sort(startpath, dirfirst=True) + try: + items = nerd_tree_sort(startpath, dirfirst=True) + except Exception as ss: + print(f'Path: {startpath} not readable because {ss}') + items = [] + d.setdefault('not_readable', 1) for item in items: if item in ITEMS_TO_EXCLUDE: