|
| 1 | +import argparse |
| 2 | +import logging |
| 3 | + |
| 4 | +from dvc.cli import completion |
| 5 | +from dvc.cli.command import CmdBaseNoRepo |
| 6 | +from dvc.cli.utils import DictAction, append_doc_link |
| 7 | +from dvc.ui import ui |
| 8 | + |
| 9 | +logger = logging.getLogger(__name__) |
| 10 | + |
| 11 | + |
| 12 | +class CmdDU(CmdBaseNoRepo): |
| 13 | + def run(self): |
| 14 | + from dvc.repo import Repo |
| 15 | + from dvc.utils.humanize import naturalsize |
| 16 | + |
| 17 | + entries = Repo.du( |
| 18 | + self.args.url, |
| 19 | + self.args.path, |
| 20 | + rev=self.args.rev, |
| 21 | + summarize=self.args.summarize, |
| 22 | + config=self.args.config, |
| 23 | + remote=self.args.remote, |
| 24 | + remote_config=self.args.remote_config, |
| 25 | + ) |
| 26 | + ui.table([(naturalsize(size), path) for path, size in entries]) |
| 27 | + return 0 |
| 28 | + |
| 29 | + |
| 30 | +def add_parser(subparsers, parent_parser): |
| 31 | + DU_HELP = "Show disk usage." |
| 32 | + du_parser = subparsers.add_parser( |
| 33 | + "du", |
| 34 | + parents=[parent_parser], |
| 35 | + description=append_doc_link(DU_HELP, "du"), |
| 36 | + help=DU_HELP, |
| 37 | + formatter_class=argparse.RawTextHelpFormatter, |
| 38 | + ) |
| 39 | + du_parser.add_argument("url", help="Location of DVC repository") |
| 40 | + du_parser.add_argument( |
| 41 | + "--rev", |
| 42 | + nargs="?", |
| 43 | + help="Git revision (e.g. SHA, branch, tag)", |
| 44 | + metavar="<commit>", |
| 45 | + ) |
| 46 | + du_parser.add_argument( |
| 47 | + "-s", |
| 48 | + "--summarize", |
| 49 | + action="store_true", |
| 50 | + help="Show total disk usage.", |
| 51 | + ) |
| 52 | + du_parser.add_argument( |
| 53 | + "--config", |
| 54 | + type=str, |
| 55 | + help=( |
| 56 | + "Path to a config file that will be merged with the config " |
| 57 | + "in the target repository." |
| 58 | + ), |
| 59 | + ) |
| 60 | + du_parser.add_argument( |
| 61 | + "--remote", |
| 62 | + type=str, |
| 63 | + help="Remote name to set as a default in the target repository.", |
| 64 | + ) |
| 65 | + du_parser.add_argument( |
| 66 | + "--remote-config", |
| 67 | + type=str, |
| 68 | + nargs="*", |
| 69 | + action=DictAction, |
| 70 | + help=( |
| 71 | + "Remote config options to merge with a remote's config (default or one " |
| 72 | + "specified by '--remote') in the target repository." |
| 73 | + ), |
| 74 | + ) |
| 75 | + du_parser.add_argument( |
| 76 | + "path", |
| 77 | + nargs="?", |
| 78 | + help="Path to directory within the repository", |
| 79 | + ).complete = completion.DIR |
| 80 | + du_parser.set_defaults(func=CmdDU) |
0 commit comments