Created
November 9, 2022 15:12
-
-
Save dundee/97c4a609e9c2d4f7e4bb298bdde4df3a to your computer and use it in GitHub Desktop.
Python script for adding absolute paths to Gdu report
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
""" | |
Usage: gdu -f- | python3 abspath.py | |
""" | |
import json | |
import sys | |
def processDir(data, path): | |
path = (path + '/' if path else '') + data[0]['name'] | |
for item in data[1:]: | |
if isinstance(item, list): | |
processDir(item, path) | |
else: | |
item['path'] = path + '/' + item['name'] | |
def main(): | |
data = json.load(sys.stdin) | |
processDir(data[3], '') | |
json.dump(data, sys.stdout, indent=2) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment