"""Inventar aller Laufwerke (Drives) der gesicherten SharePoint-Sites per Delta-Abfrage. Liest graph/sharepoint/*.json aus dem Zielordner und schreibt graph/drives_inventory.json. Nur GET.""" import glob, json, os, sys sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) import m365_auth as auth SELECT = "id,name,size,parentReference,file,folder,webUrl,lastModifiedDateTime,createdBy,lastModifiedBy" def main(argv=None): p = auth.make_parser("Inventory of all drives of the exported SharePoint sites") args = p.parse_args(argv) out = {} # Der graph_export schreibt die Sites nach /graph/sharepoint/ for f in glob.glob(os.path.join(args.out, "graph", "sharepoint", "*.json")): j = json.load(open(f)) for dr in (j["drives"] if isinstance(j["drives"], list) else []): items, url = [], f"/drives/{dr['id']}/root/delta?$select={SELECT}" while url: r = auth.g("GET", url) if r.status_code != 200: items = {"error": r.status_code}; break jj = r.json(); items += jj.get("value", []); url = jj.get("@odata.nextLink") out[dr["id"]] = {"name": dr.get("name"), "webUrl": dr.get("webUrl"), "items": items} os.makedirs(os.path.join(args.out, "graph"), exist_ok=True) auth.write_json(os.path.join(args.out, "graph", "drives_inventory.json"), out) print(len(out), sum(len(v["items"]) for v in out.values() if isinstance(v["items"], list))) return 0 if __name__ == "__main__": sys.exit(main())