#!/usr/bin/python import os import json if __name__ == "__main__": # Iterate over all block devices, but ignore them if they are in the # skippable set skippable = ("sr", "loop", "ram") devices = (device for device in os.listdir("/sys/class/block") if not any(ignore in device for ignore in skippable)) data = [{"{#DEVICENAME}": device} for device in devices] print(json.dumps({"data": data}, indent=4))