Skip to content

Commit

Permalink
print: Change printing list format in tree
Browse files Browse the repository at this point in the history
Signed-off-by: iipeace <iipeace5@gmail.com>
  • Loading branch information
iipeace committed Aug 11, 2024
1 parent 9a29e15 commit 428ee00
Showing 1 changed file with 35 additions and 12 deletions.
47 changes: 35 additions & 12 deletions guider/guider.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
__credits__ = "Peace Lee"
__license__ = "GPLv2"
__version__ = "3.9.8"
__revision__ = "240810"
__revision__ = "240811"
__maintainer__ = "Peace Lee"
__email__ = "iipeace5@gmail.com"
__repository__ = "https://github.com/iipeace/guider"
Expand Down Expand Up @@ -6498,6 +6498,11 @@ def printAllAttrs(objList, name, rep=None, nameFilter=[]):
printTree = "PRINTTREE" in SysMgr.environList
treeList = {}

# get shotcuts and filters #
convColor = UtilMgr.convColor
incFilter = SysMgr.environList.get("INCFILTER", [])
exFilter = SysMgr.environList.get("EXFILTER", [])

def _applyTreeItem(treeList, items, val):
if not isinstance(treeList, dict):
return
Expand All @@ -6512,21 +6517,38 @@ def _applyTreeItem(treeList, items, val):
elif "size" in val:
treeList[name] = val["size"]

def _printTreeItems(data, indent=0):
for key, value in data.items():
def _printTreeItems(data, indent=1):
for key, value in sorted(
data.items(),
key=lambda x: (1, x[0])
if isinstance(x[1], (int, long))
else (0, x[0]),
):
if key:
if isinstance(value, (int, long)):
size = " (%s)" % UtilMgr.convSize2Unit(value)
if incFilter and not UtilMgr.isValidStr(key, incFilter):
isValid = False
elif exFilter and UtilMgr.isValidStr(key, exFilter):
isValid = False
else:
key = "[%s]" % key
isValid = True

if not isValid:
pass
elif isinstance(value, (int, long)):
size = " (%s)" % convColor(
UtilMgr.convSize2Unit(value), "CYAN"
)
else:
key = "[%s]" % convColor(key, "GREEN")
size = ""

SysMgr.printPipe(
" " * indent
+ ("|-" if indent else "")
+ str(key)
+ size
)
if isValid:
SysMgr.printPipe(
("| " * indent if indent > 1 else "")
+ ("|-" if indent else "")
+ str(key)
+ size
)

if isinstance(value, dict):
_printTreeItems(value, indent + 1)
Expand Down Expand Up @@ -40746,6 +40768,7 @@ def _getDesc(s, t=0):

- Print target files in compressed data in tree structure
# {0:1} {1:1} {3:1} -q PRINTTREE
# {0:1} {1:1} {3:1} -q PRINTTREE, INCFILTER:"*test*", EXFILTER:"*zip"

- Print specific target files in compressed data and save them to files
# {0:1} {1:1} {3:1} -g "*.so" -q EXTRACT
Expand Down

0 comments on commit 428ee00

Please sign in to comment.