We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
dvc push -q is not completely quiet, shows file transfer tqdm progress bars
Hey guys, love what you've done with DVC.

Had a quick bug that's causing me a little issue. When I use 'dvc push -q' I'm still seeing tqdm progress bars. Wouldn't be a huge issue, but I'm probably pushing 100K 250kb files. This is a local remote, so the transfer speeds are quick. I know in some of my other scripts where I use tqdm, if the iteration time is very small, the tqdm overhead of writing to std::out actually starts to contribute to performance.

dvc version: 0.83.0
os: Windows 10

![image](https://user-images.githubusercontent.com/45394583/74362981-a1500d80-4d97-11ea-9df8-c56fbadea69b.png)



dvc push -q is not completely quiet, shows file transfer tqdm progress bars
Hey guys, love what you've done with DVC.

Had a quick bug that's causing me a little issue. When I use 'dvc push -q' I'm still seeing tqdm progress bars. Wouldn't be a huge issue, but I'm probably pushing 100K 250kb files. This is a local remote, so the transfer speeds are quick. I know in some of my other scripts where I use tqdm, if the iteration time is very small, the tqdm overhead of writing to std::out actually starts to contribute to performance.

dvc version: 0.83.0
os: Windows 10

![image](https://user-images.githubusercontent.com/45394583/74362981-a1500d80-4d97-11ea-9df8-c56fbadea69b.png)




--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `dvc/repo/add.py`
Content:
```
1 import logging
2 import os
3 
4 import colorama
5 
6 from . import locked
7 from ..exceptions import (
8     RecursiveAddingWhileUsingFilename,
9     OverlappingOutputPathsError,
10 )
11 from ..output.base import OutputDoesNotExistError
12 from ..progress import Tqdm
13 from ..repo.scm_context import scm_context
14 from ..stage import Stage
15 from ..utils import LARGE_DIR_SIZE
16 
17 logger = logging.getLogger(__name__)
18 
19 
20 @locked
21 @scm_context
22 def add(repo, targets, recursive=False, no_commit=False, fname=None):
23     if recursive and fname:
24         raise RecursiveAddingWhileUsingFilename()
25 
26     if isinstance(targets, str):
27         targets = [targets]
28 
29     stages_list = []
30     num_targets = len(targets)
31     with Tqdm(total=num_targets, desc="Add", unit="file", leave=True) as pbar:
32         if num_targets == 1:
33             # clear unneeded top-level progress bar for single target
34             pbar.bar_format = "Adding..."
35             pbar.refresh()
36         for target in targets:
37             sub_targets = _find_all_targets(repo, target, recursive)
38             pbar.total += len(sub_targets) - 1
39 
40             if os.path.isdir(target) and len(sub_targets) > LARGE_DIR_SIZE:
41                 logger.warning(
42                     "You are adding a large directory '{target}' recursively,"
43                     " consider tracking it as a whole instead.\n"
44                     "{purple}HINT:{nc} Remove the generated DVC-file and then"
45                     " run `{cyan}dvc add {target}{nc}`".format(
46                         purple=colorama.Fore.MAGENTA,
47                         cyan=colorama.Fore.CYAN,
48                         nc=colorama.Style.RESET_ALL,
49                         target=target,
50                     )
51                 )
52 
53             stages = _create_stages(repo, sub_targets, fname, pbar=pbar)
54 
55             try:
56                 repo.check_modified_graph(stages)
57             except OverlappingOutputPathsError as exc:
58                 msg = (
59                     "Cannot add '{out}', because it is overlapping with other "
60                     "DVC tracked output: '{parent}'.\n"
61                     "To include '{out}' in '{parent}', run "
62                     "'dvc commit {parent_stage}'"
63                 ).format(
64                     out=exc.overlapping_out.path_info,
65                     parent=exc.parent.path_info,
66                     parent_stage=exc.parent.stage.relpath,
67                 )
68                 raise OverlappingOutputPathsError(
69                     exc.parent, exc.overlapping_out, msg
70                 )
71 
72             with Tqdm(
73                 total=len(stages),
74                 desc="Processing",
75                 unit="file",
76                 disable=True if len(stages) == 1 else None,
77             ) as pbar_stages:
78                 for stage in stages:
79                     try:
80                         stage.save()
81                     except OutputDoesNotExistError:
82                         pbar.n -= 1
83                         raise
84 
85                     if not no_commit:
86                         stage.commit()
87 
88                     stage.dump()
89                     pbar_stages.update()
90 
91             stages_list += stages
92 
93         if num_targets == 1:  # restore bar format for stats
94             pbar.bar_format = pbar.BAR_FMT_DEFAULT
95 
96     return stages_list
97 
98 
99 def _find_all_targets(repo, target, recursive):
100     if os.path.isdir(target) and recursive:
101         return [
102             fname
103             for fname in Tqdm(
104                 repo.tree.walk_files(target),
105                 desc="Searching " + target,
106                 bar_format=Tqdm.BAR_FMT_NOTOTAL,
107                 unit="file",
108             )
109             if not repo.is_dvc_internal(fname)
110             if not Stage.is_stage_file(fname)
111             if not repo.scm.belongs_to_scm(fname)
112             if not repo.scm.is_tracked(fname)
113         ]
114     return [target]
115 
116 
117 def _create_stages(repo, targets, fname, pbar=None):
118     stages = []
119 
120     for out in Tqdm(
121         targets,
122         desc="Creating DVC-files",
123         disable=True if len(targets) < LARGE_DIR_SIZE else None,
124         unit="file",
125     ):
126         stage = Stage.create(
127             repo, outs=[out], accompany_outs=True, fname=fname
128         )
129 
130         if not stage:
131             if pbar is not None:
132                 pbar.total -= 1
133             continue
134 
135         stages.append(stage)
136         if pbar is not None:
137             pbar.update_desc(out)
138 
139     return stages
140
```

Path: `dvc/progress.py`
Content:
```
1 """Manages progress bars for DVC repo."""
2 
3 import logging
4 import sys
5 from threading import RLock
6 
7 from tqdm import tqdm
8 
9 from dvc.utils import env2bool
10 
11 logger = logging.getLogger(__name__)
12 tqdm.set_lock(RLock())
13 
14 
15 class Tqdm(tqdm):
16     """
17     maximum-compatibility tqdm-based progressbars
18     """
19 
20     BAR_FMT_DEFAULT = (
21         "{percentage:3.0f}% {desc}|{bar}|"
22         "{n_fmt}/{total_fmt}"
23         " [{elapsed}<{remaining}, {rate_fmt:>11}{postfix}]"
24     )
25     # nested bars should have fixed bar widths to align nicely
26     BAR_FMT_DEFAULT_NESTED = (
27         "{percentage:3.0f}%|{bar:10}|{desc:{ncols_desc}.{ncols_desc}}"
28         "{n_fmt}/{total_fmt}"
29         " [{elapsed}<{remaining}, {rate_fmt:>11}{postfix}]"
30     )
31     BAR_FMT_NOTOTAL = (
32         "{desc:{ncols_desc}.{ncols_desc}}{n_fmt}"
33         " [{elapsed}, {rate_fmt:>11}{postfix}]"
34     )
35     BYTES_DEFAULTS = dict(
36         unit="B", unit_scale=True, unit_divisor=1024, miniters=1
37     )
38 
39     def __init__(
40         self,
41         iterable=None,
42         disable=None,
43         level=logging.ERROR,
44         desc=None,
45         leave=False,
46         bar_format=None,
47         bytes=False,  # pylint: disable=W0622
48         file=None,
49         total=None,
50         **kwargs
51     ):
52         """
53         bytes   : shortcut for
54             `unit='B', unit_scale=True, unit_divisor=1024, miniters=1`
55         desc  : persists after `close()`
56         level  : effective logging level for determining `disable`;
57             used only if `disable` is unspecified
58         disable  : If (default: None), will be determined by logging level.
59             May be overridden to `True` due to non-TTY status.
60             Skip override by specifying env var `DVC_IGNORE_ISATTY`.
61         kwargs  : anything accepted by `tqdm.tqdm()`
62         """
63         kwargs = kwargs.copy()
64         if bytes:
65             kwargs = {**self.BYTES_DEFAULTS, **kwargs}
66         else:
67             kwargs.setdefault("unit_scale", total > 999 if total else True)
68         if file is None:
69             file = sys.stderr
70         self.desc_persist = desc
71         # auto-disable based on `logger.level`
72         if disable is None:
73             disable = logger.getEffectiveLevel() > level
74         # auto-disable based on TTY
75         if (
76             not disable
77             and not env2bool("DVC_IGNORE_ISATTY")
78             and hasattr(file, "isatty")
79         ):
80             disable = not file.isatty()
81         super().__init__(
82             iterable=iterable,
83             disable=disable,
84             leave=leave,
85             desc=desc,
86             bar_format="!",
87             lock_args=(False,),
88             total=total,
89             **kwargs
90         )
91         if bar_format is None:
92             if self.__len__():
93                 self.bar_format = (
94                     self.BAR_FMT_DEFAULT_NESTED
95                     if self.pos
96                     else self.BAR_FMT_DEFAULT
97                 )
98             else:
99                 self.bar_format = self.BAR_FMT_NOTOTAL
100         else:
101             self.bar_format = bar_format
102         self.refresh()
103 
104     def update_desc(self, desc, n=1):
105         """
106         Calls `set_description_str(desc)` and `update(n)`
107         """
108         self.set_description_str(desc, refresh=False)
109         self.update(n)
110 
111     def update_to(self, current, total=None):
112         if total:
113             self.total = total  # pylint: disable=W0613,W0201
114         self.update(current - self.n)
115 
116     def close(self):
117         if self.desc_persist is not None:
118             self.set_description_str(self.desc_persist, refresh=False)
119         # unknown/zero ETA
120         self.bar_format = self.bar_format.replace("<{remaining}", "")
121         # remove completed bar
122         self.bar_format = self.bar_format.replace("|{bar:10}|", " ")
123         super().close()
124 
125     @property
126     def format_dict(self):
127         """inject `ncols_desc` to fill the display width (`ncols`)"""
128         d = super().format_dict
129         ncols = d["ncols"] or 80
130         ncols_desc = ncols - len(self.format_meter(ncols_desc=1, **d)) + 1
131         ncols_desc = max(ncols_desc, 0)
132         if ncols_desc:
133             d["ncols_desc"] = ncols_desc
134         else:
135             # work-around for zero-width description
136             d["ncols_desc"] = 1
137             d["prefix"] = ""
138         return d
139
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/dvc/progress.py b/dvc/progress.py
--- a/dvc/progress.py
+++ b/dvc/progress.py
@@ -55,7 +55,8 @@
         desc  : persists after `close()`
         level  : effective logging level for determining `disable`;
             used only if `disable` is unspecified
-        disable  : If (default: None), will be determined by logging level.
+        disable  : If (default: None) or False,
+            will be determined by logging level.
             May be overridden to `True` due to non-TTY status.
             Skip override by specifying env var `DVC_IGNORE_ISATTY`.
         kwargs  : anything accepted by `tqdm.tqdm()`
@@ -69,7 +70,7 @@
             file = sys.stderr
         self.desc_persist = desc
         # auto-disable based on `logger.level`
-        if disable is None:
+        if not disable:
             disable = logger.getEffectiveLevel() > level
         # auto-disable based on TTY
         if (
diff --git a/dvc/repo/add.py b/dvc/repo/add.py
--- a/dvc/repo/add.py
+++ b/dvc/repo/add.py
@@ -55,7 +55,7 @@
                 total=len(stages),
                 desc="Processing",
                 unit="file",
-                disable=True if len(stages) == 1 else None,
+                disable=len(stages) == 1,
             ) as pbar_stages:
                 for stage in stages:
                     try:
@@ -102,7 +102,7 @@
     for out in Tqdm(
         targets,
         desc="Creating DVC-files",
-        disable=True if len(targets) < LARGE_DIR_SIZE else None,
+        disable=len(targets) < LARGE_DIR_SIZE,
         unit="file",
     ):
         stage = Stage.create(repo, outs=[out], add=True, fname=fname)

{"golden_diff": "diff --git a/dvc/progress.py b/dvc/progress.py\n--- a/dvc/progress.py\n+++ b/dvc/progress.py\n@@ -55,7 +55,8 @@\n         desc  : persists after `close()`\n         level  : effective logging level for determining `disable`;\n             used only if `disable` is unspecified\n-        disable  : If (default: None), will be determined by logging level.\n+        disable  : If (default: None) or False,\n+            will be determined by logging level.\n             May be overridden to `True` due to non-TTY status.\n             Skip override by specifying env var `DVC_IGNORE_ISATTY`.\n         kwargs  : anything accepted by `tqdm.tqdm()`\n@@ -69,7 +70,7 @@\n             file = sys.stderr\n         self.desc_persist = desc\n         # auto-disable based on `logger.level`\n-        if disable is None:\n+        if not disable:\n             disable = logger.getEffectiveLevel() > level\n         # auto-disable based on TTY\n         if (\ndiff --git a/dvc/repo/add.py b/dvc/repo/add.py\n--- a/dvc/repo/add.py\n+++ b/dvc/repo/add.py\n@@ -55,7 +55,7 @@\n                 total=len(stages),\n                 desc=\"Processing\",\n                 unit=\"file\",\n-                disable=True if len(stages) == 1 else None,\n+                disable=len(stages) == 1,\n             ) as pbar_stages:\n                 for stage in stages:\n                     try:\n@@ -102,7 +102,7 @@\n     for out in Tqdm(\n         targets,\n         desc=\"Creating DVC-files\",\n-        disable=True if len(targets) < LARGE_DIR_SIZE else None,\n+        disable=len(targets) < LARGE_DIR_SIZE,\n         unit=\"file\",\n     ):\n         stage = Stage.create(repo, outs=[out], add=True, fname=fname)\n", "issue": "dvc push -q is not completely quiet, shows file transfer tqdm progress bars\nHey guys, love what you've done with DVC.\r\n\r\nHad a quick bug that's causing me a little issue. When I use 'dvc push -q' I'm still seeing tqdm progress bars. Wouldn't be a huge issue, but I'm probably pushing 100K 250kb files. This is a local remote, so the transfer speeds are quick. I know in some of my other scripts where I use tqdm, if the iteration time is very small, the tqdm overhead of writing to std::out actually starts to contribute to performance.\r\n\r\ndvc version: 0.83.0\r\nos: Windows 10\r\n\r\n![image](https://user-images.githubusercontent.com/45394583/74362981-a1500d80-4d97-11ea-9df8-c56fbadea69b.png)\r\n\r\n\r\n\ndvc push -q is not completely quiet, shows file transfer tqdm progress bars\nHey guys, love what you've done with DVC.\r\n\r\nHad a quick bug that's causing me a little issue. When I use 'dvc push -q' I'm still seeing tqdm progress bars. Wouldn't be a huge issue, but I'm probably pushing 100K 250kb files. This is a local remote, so the transfer speeds are quick. I know in some of my other scripts where I use tqdm, if the iteration time is very small, the tqdm overhead of writing to std::out actually starts to contribute to performance.\r\n\r\ndvc version: 0.83.0\r\nos: Windows 10\r\n\r\n![image](https://user-images.githubusercontent.com/45394583/74362981-a1500d80-4d97-11ea-9df8-c56fbadea69b.png)\r\n\r\n\r\n\n", "before_files": [{"content": "import logging\nimport os\n\nimport colorama\n\nfrom . import locked\nfrom ..exceptions import (\n    RecursiveAddingWhileUsingFilename,\n    OverlappingOutputPathsError,\n)\nfrom ..output.base import OutputDoesNotExistError\nfrom ..progress import Tqdm\nfrom ..repo.scm_context import scm_context\nfrom ..stage import Stage\nfrom ..utils import LARGE_DIR_SIZE\n\nlogger = logging.getLogger(__name__)\n\n\n@locked\n@scm_context\ndef add(repo, targets, recursive=False, no_commit=False, fname=None):\n    if recursive and fname:\n        raise RecursiveAddingWhileUsingFilename()\n\n    if isinstance(targets, str):\n        targets = [targets]\n\n    stages_list = []\n    num_targets = len(targets)\n    with Tqdm(total=num_targets, desc=\"Add\", unit=\"file\", leave=True) as pbar:\n        if num_targets == 1:\n            # clear unneeded top-level progress bar for single target\n            pbar.bar_format = \"Adding...\"\n            pbar.refresh()\n        for target in targets:\n            sub_targets = _find_all_targets(repo, target, recursive)\n            pbar.total += len(sub_targets) - 1\n\n            if os.path.isdir(target) and len(sub_targets) > LARGE_DIR_SIZE:\n                logger.warning(\n                    \"You are adding a large directory '{target}' recursively,\"\n                    \" consider tracking it as a whole instead.\\n\"\n                    \"{purple}HINT:{nc} Remove the generated DVC-file and then\"\n                    \" run `{cyan}dvc add {target}{nc}`\".format(\n                        purple=colorama.Fore.MAGENTA,\n                        cyan=colorama.Fore.CYAN,\n                        nc=colorama.Style.RESET_ALL,\n                        target=target,\n                    )\n                )\n\n            stages = _create_stages(repo, sub_targets, fname, pbar=pbar)\n\n            try:\n                repo.check_modified_graph(stages)\n            except OverlappingOutputPathsError as exc:\n                msg = (\n                    \"Cannot add '{out}', because it is overlapping with other \"\n                    \"DVC tracked output: '{parent}'.\\n\"\n                    \"To include '{out}' in '{parent}', run \"\n                    \"'dvc commit {parent_stage}'\"\n                ).format(\n                    out=exc.overlapping_out.path_info,\n                    parent=exc.parent.path_info,\n                    parent_stage=exc.parent.stage.relpath,\n                )\n                raise OverlappingOutputPathsError(\n                    exc.parent, exc.overlapping_out, msg\n                )\n\n            with Tqdm(\n                total=len(stages),\n                desc=\"Processing\",\n                unit=\"file\",\n                disable=True if len(stages) == 1 else None,\n            ) as pbar_stages:\n                for stage in stages:\n                    try:\n                        stage.save()\n                    except OutputDoesNotExistError:\n                        pbar.n -= 1\n                        raise\n\n                    if not no_commit:\n                        stage.commit()\n\n                    stage.dump()\n                    pbar_stages.update()\n\n            stages_list += stages\n\n        if num_targets == 1:  # restore bar format for stats\n            pbar.bar_format = pbar.BAR_FMT_DEFAULT\n\n    return stages_list\n\n\ndef _find_all_targets(repo, target, recursive):\n    if os.path.isdir(target) and recursive:\n        return [\n            fname\n            for fname in Tqdm(\n                repo.tree.walk_files(target),\n                desc=\"Searching \" + target,\n                bar_format=Tqdm.BAR_FMT_NOTOTAL,\n                unit=\"file\",\n            )\n            if not repo.is_dvc_internal(fname)\n            if not Stage.is_stage_file(fname)\n            if not repo.scm.belongs_to_scm(fname)\n            if not repo.scm.is_tracked(fname)\n        ]\n    return [target]\n\n\ndef _create_stages(repo, targets, fname, pbar=None):\n    stages = []\n\n    for out in Tqdm(\n        targets,\n        desc=\"Creating DVC-files\",\n        disable=True if len(targets) < LARGE_DIR_SIZE else None,\n        unit=\"file\",\n    ):\n        stage = Stage.create(\n            repo, outs=[out], accompany_outs=True, fname=fname\n        )\n\n        if not stage:\n            if pbar is not None:\n                pbar.total -= 1\n            continue\n\n        stages.append(stage)\n        if pbar is not None:\n            pbar.update_desc(out)\n\n    return stages\n", "path": "dvc/repo/add.py"}, {"content": "\"\"\"Manages progress bars for DVC repo.\"\"\"\n\nimport logging\nimport sys\nfrom threading import RLock\n\nfrom tqdm import tqdm\n\nfrom dvc.utils import env2bool\n\nlogger = logging.getLogger(__name__)\ntqdm.set_lock(RLock())\n\n\nclass Tqdm(tqdm):\n    \"\"\"\n    maximum-compatibility tqdm-based progressbars\n    \"\"\"\n\n    BAR_FMT_DEFAULT = (\n        \"{percentage:3.0f}% {desc}|{bar}|\"\n        \"{n_fmt}/{total_fmt}\"\n        \" [{elapsed}<{remaining}, {rate_fmt:>11}{postfix}]\"\n    )\n    # nested bars should have fixed bar widths to align nicely\n    BAR_FMT_DEFAULT_NESTED = (\n        \"{percentage:3.0f}%|{bar:10}|{desc:{ncols_desc}.{ncols_desc}}\"\n        \"{n_fmt}/{total_fmt}\"\n        \" [{elapsed}<{remaining}, {rate_fmt:>11}{postfix}]\"\n    )\n    BAR_FMT_NOTOTAL = (\n        \"{desc:{ncols_desc}.{ncols_desc}}{n_fmt}\"\n        \" [{elapsed}, {rate_fmt:>11}{postfix}]\"\n    )\n    BYTES_DEFAULTS = dict(\n        unit=\"B\", unit_scale=True, unit_divisor=1024, miniters=1\n    )\n\n    def __init__(\n        self,\n        iterable=None,\n        disable=None,\n        level=logging.ERROR,\n        desc=None,\n        leave=False,\n        bar_format=None,\n        bytes=False,  # pylint: disable=W0622\n        file=None,\n        total=None,\n        **kwargs\n    ):\n        \"\"\"\n        bytes   : shortcut for\n            `unit='B', unit_scale=True, unit_divisor=1024, miniters=1`\n        desc  : persists after `close()`\n        level  : effective logging level for determining `disable`;\n            used only if `disable` is unspecified\n        disable  : If (default: None), will be determined by logging level.\n            May be overridden to `True` due to non-TTY status.\n            Skip override by specifying env var `DVC_IGNORE_ISATTY`.\n        kwargs  : anything accepted by `tqdm.tqdm()`\n        \"\"\"\n        kwargs = kwargs.copy()\n        if bytes:\n            kwargs = {**self.BYTES_DEFAULTS, **kwargs}\n        else:\n            kwargs.setdefault(\"unit_scale\", total > 999 if total else True)\n        if file is None:\n            file = sys.stderr\n        self.desc_persist = desc\n        # auto-disable based on `logger.level`\n        if disable is None:\n            disable = logger.getEffectiveLevel() > level\n        # auto-disable based on TTY\n        if (\n            not disable\n            and not env2bool(\"DVC_IGNORE_ISATTY\")\n            and hasattr(file, \"isatty\")\n        ):\n            disable = not file.isatty()\n        super().__init__(\n            iterable=iterable,\n            disable=disable,\n            leave=leave,\n            desc=desc,\n            bar_format=\"!\",\n            lock_args=(False,),\n            total=total,\n            **kwargs\n        )\n        if bar_format is None:\n            if self.__len__():\n                self.bar_format = (\n                    self.BAR_FMT_DEFAULT_NESTED\n                    if self.pos\n                    else self.BAR_FMT_DEFAULT\n                )\n            else:\n                self.bar_format = self.BAR_FMT_NOTOTAL\n        else:\n            self.bar_format = bar_format\n        self.refresh()\n\n    def update_desc(self, desc, n=1):\n        \"\"\"\n        Calls `set_description_str(desc)` and `update(n)`\n        \"\"\"\n        self.set_description_str(desc, refresh=False)\n        self.update(n)\n\n    def update_to(self, current, total=None):\n        if total:\n            self.total = total  # pylint: disable=W0613,W0201\n        self.update(current - self.n)\n\n    def close(self):\n        if self.desc_persist is not None:\n            self.set_description_str(self.desc_persist, refresh=False)\n        # unknown/zero ETA\n        self.bar_format = self.bar_format.replace(\"<{remaining}\", \"\")\n        # remove completed bar\n        self.bar_format = self.bar_format.replace(\"|{bar:10}|\", \" \")\n        super().close()\n\n    @property\n    def format_dict(self):\n        \"\"\"inject `ncols_desc` to fill the display width (`ncols`)\"\"\"\n        d = super().format_dict\n        ncols = d[\"ncols\"] or 80\n        ncols_desc = ncols - len(self.format_meter(ncols_desc=1, **d)) + 1\n        ncols_desc = max(ncols_desc, 0)\n        if ncols_desc:\n            d[\"ncols_desc\"] = ncols_desc\n        else:\n            # work-around for zero-width description\n            d[\"ncols_desc\"] = 1\n            d[\"prefix\"] = \"\"\n        return d\n", "path": "dvc/progress.py"}], "after_files": [{"content": "import logging\nimport os\n\nimport colorama\n\nfrom . import locked\nfrom ..exceptions import RecursiveAddingWhileUsingFilename\nfrom ..output.base import OutputDoesNotExistError\nfrom ..progress import Tqdm\nfrom ..repo.scm_context import scm_context\nfrom ..stage import Stage\nfrom ..utils import LARGE_DIR_SIZE\n\nlogger = logging.getLogger(__name__)\n\n\n@locked\n@scm_context\ndef add(repo, targets, recursive=False, no_commit=False, fname=None):\n    if recursive and fname:\n        raise RecursiveAddingWhileUsingFilename()\n\n    if isinstance(targets, str):\n        targets = [targets]\n\n    stages_list = []\n    num_targets = len(targets)\n    with Tqdm(total=num_targets, desc=\"Add\", unit=\"file\", leave=True) as pbar:\n        if num_targets == 1:\n            # clear unneeded top-level progress bar for single target\n            pbar.bar_format = \"Adding...\"\n            pbar.refresh()\n        for target in targets:\n            sub_targets = _find_all_targets(repo, target, recursive)\n            pbar.total += len(sub_targets) - 1\n\n            if os.path.isdir(target) and len(sub_targets) > LARGE_DIR_SIZE:\n                logger.warning(\n                    \"You are adding a large directory '{target}' recursively,\"\n                    \" consider tracking it as a whole instead.\\n\"\n                    \"{purple}HINT:{nc} Remove the generated DVC-file and then\"\n                    \" run `{cyan}dvc add {target}{nc}`\".format(\n                        purple=colorama.Fore.MAGENTA,\n                        cyan=colorama.Fore.CYAN,\n                        nc=colorama.Style.RESET_ALL,\n                        target=target,\n                    )\n                )\n\n            stages = _create_stages(repo, sub_targets, fname, pbar=pbar)\n\n            repo.check_modified_graph(stages)\n\n            with Tqdm(\n                total=len(stages),\n                desc=\"Processing\",\n                unit=\"file\",\n                disable=len(stages) == 1,\n            ) as pbar_stages:\n                for stage in stages:\n                    try:\n                        stage.save()\n                    except OutputDoesNotExistError:\n                        pbar.n -= 1\n                        raise\n\n                    if not no_commit:\n                        stage.commit()\n\n                    stage.dump()\n                    pbar_stages.update()\n\n            stages_list += stages\n\n        if num_targets == 1:  # restore bar format for stats\n            pbar.bar_format = pbar.BAR_FMT_DEFAULT\n\n    return stages_list\n\n\ndef _find_all_targets(repo, target, recursive):\n    if os.path.isdir(target) and recursive:\n        return [\n            fname\n            for fname in Tqdm(\n                repo.tree.walk_files(target),\n                desc=\"Searching \" + target,\n                bar_format=Tqdm.BAR_FMT_NOTOTAL,\n                unit=\"file\",\n            )\n            if not repo.is_dvc_internal(fname)\n            if not Stage.is_stage_file(fname)\n            if not repo.scm.belongs_to_scm(fname)\n            if not repo.scm.is_tracked(fname)\n        ]\n    return [target]\n\n\ndef _create_stages(repo, targets, fname, pbar=None):\n    stages = []\n\n    for out in Tqdm(\n        targets,\n        desc=\"Creating DVC-files\",\n        disable=len(targets) < LARGE_DIR_SIZE,\n        unit=\"file\",\n    ):\n        stage = Stage.create(repo, outs=[out], add=True, fname=fname)\n\n        if not stage:\n            if pbar is not None:\n                pbar.total -= 1\n            continue\n\n        stages.append(stage)\n        if pbar is not None:\n            pbar.update_desc(out)\n\n    return stages\n", "path": "dvc/repo/add.py"}, {"content": "\"\"\"Manages progress bars for DVC repo.\"\"\"\n\nimport logging\nimport sys\nfrom threading import RLock\n\nfrom tqdm import tqdm\n\nfrom dvc.utils import env2bool\n\nlogger = logging.getLogger(__name__)\ntqdm.set_lock(RLock())\n\n\nclass Tqdm(tqdm):\n    \"\"\"\n    maximum-compatibility tqdm-based progressbars\n    \"\"\"\n\n    BAR_FMT_DEFAULT = (\n        \"{percentage:3.0f}% {desc}|{bar}|\"\n        \"{n_fmt}/{total_fmt}\"\n        \" [{elapsed}<{remaining}, {rate_fmt:>11}{postfix}]\"\n    )\n    # nested bars should have fixed bar widths to align nicely\n    BAR_FMT_DEFAULT_NESTED = (\n        \"{percentage:3.0f}%|{bar:10}|{desc:{ncols_desc}.{ncols_desc}}\"\n        \"{n_fmt}/{total_fmt}\"\n        \" [{elapsed}<{remaining}, {rate_fmt:>11}{postfix}]\"\n    )\n    BAR_FMT_NOTOTAL = (\n        \"{desc:{ncols_desc}.{ncols_desc}}{n_fmt}\"\n        \" [{elapsed}, {rate_fmt:>11}{postfix}]\"\n    )\n    BYTES_DEFAULTS = dict(\n        unit=\"B\", unit_scale=True, unit_divisor=1024, miniters=1\n    )\n\n    def __init__(\n        self,\n        iterable=None,\n        disable=None,\n        level=logging.ERROR,\n        desc=None,\n        leave=False,\n        bar_format=None,\n        bytes=False,  # pylint: disable=W0622\n        file=None,\n        total=None,\n        **kwargs\n    ):\n        \"\"\"\n        bytes   : shortcut for\n            `unit='B', unit_scale=True, unit_divisor=1024, miniters=1`\n        desc  : persists after `close()`\n        level  : effective logging level for determining `disable`;\n            used only if `disable` is unspecified\n        disable  : If (default: None) or False,\n            will be determined by logging level.\n            May be overridden to `True` due to non-TTY status.\n            Skip override by specifying env var `DVC_IGNORE_ISATTY`.\n        kwargs  : anything accepted by `tqdm.tqdm()`\n        \"\"\"\n        kwargs = kwargs.copy()\n        if bytes:\n            kwargs = {**self.BYTES_DEFAULTS, **kwargs}\n        else:\n            kwargs.setdefault(\"unit_scale\", total > 999 if total else True)\n        if file is None:\n            file = sys.stderr\n        self.desc_persist = desc\n        # auto-disable based on `logger.level`\n        if not disable:\n            disable = logger.getEffectiveLevel() > level\n        # auto-disable based on TTY\n        if (\n            not disable\n            and not env2bool(\"DVC_IGNORE_ISATTY\")\n            and hasattr(file, \"isatty\")\n        ):\n            disable = not file.isatty()\n        super().__init__(\n            iterable=iterable,\n            disable=disable,\n            leave=leave,\n            desc=desc,\n            bar_format=\"!\",\n            lock_args=(False,),\n            total=total,\n            **kwargs\n        )\n        if bar_format is None:\n            if self.__len__():\n                self.bar_format = (\n                    self.BAR_FMT_DEFAULT_NESTED\n                    if self.pos\n                    else self.BAR_FMT_DEFAULT\n                )\n            else:\n                self.bar_format = self.BAR_FMT_NOTOTAL\n        else:\n            self.bar_format = bar_format\n        self.refresh()\n\n    def update_desc(self, desc, n=1):\n        \"\"\"\n        Calls `set_description_str(desc)` and `update(n)`\n        \"\"\"\n        self.set_description_str(desc, refresh=False)\n        self.update(n)\n\n    def update_to(self, current, total=None):\n        if total:\n            self.total = total  # pylint: disable=W0613,W0201\n        self.update(current - self.n)\n\n    def close(self):\n        if self.desc_persist is not None:\n            self.set_description_str(self.desc_persist, refresh=False)\n        # unknown/zero ETA\n        self.bar_format = self.bar_format.replace(\"<{remaining}\", \"\")\n        # remove completed bar\n        self.bar_format = self.bar_format.replace(\"|{bar:10}|\", \" \")\n        super().close()\n\n    @property\n    def format_dict(self):\n        \"\"\"inject `ncols_desc` to fill the display width (`ncols`)\"\"\"\n        d = super().format_dict\n        ncols = d[\"ncols\"] or 80\n        ncols_desc = ncols - len(self.format_meter(ncols_desc=1, **d)) + 1\n        ncols_desc = max(ncols_desc, 0)\n        if ncols_desc:\n            d[\"ncols_desc\"] = ncols_desc\n        else:\n            # work-around for zero-width description\n            d[\"ncols_desc\"] = 1\n            d[\"prefix\"] = \"\"\n        return d\n", "path": "dvc/progress.py"}]}