blob: 654ebf4f7174cf9341d6fc18d094c6de368747a6 [file] [edit]
#!/usr/bin/env python3
# Copyright 2026 The Pigweed Authors
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
"""Resource script to check disk usage of a path and write JSON output."""
from __future__ import annotations
import argparse
import json
import shutil
def main() -> None:
parser = argparse.ArgumentParser(description='Check disk usage.')
parser.add_argument('path', help='Directory path to check.')
parser.add_argument('output', help='JSON output file path.')
args = parser.parse_args()
usage = shutil.disk_usage(args.path)
data = {
'total': usage.total,
'used': usage.used,
'free': usage.free,
}
with open(args.output, 'w') as f:
json.dump(data, f)
if __name__ == '__main__':
main()