Browse Source

add options to control whether progress bar appears

Make it possible to turn off the progress bar without completely
silencing the app.

Signed-off-by: Doug Hellmann <doug@doughellmann.com>
Doug Hellmann 2 years ago
parent
commit
e8f616d9cf
3 changed files with 26 additions and 4 deletions
  1. 13
    0
      aerostat/app.py
  2. 8
    3
      aerostat/download.py
  3. 5
    1
      aerostat/export.py

+ 13
- 0
aerostat/app.py View File

@@ -42,6 +42,19 @@ def main():
42 42
         const=0,
43 43
         help='Suppress output except warnings and errors.',
44 44
     )
45
+    progress_group = parser.add_mutually_exclusive_group()
46
+    progress_group.add_argument(
47
+        '--progress', '-p',
48
+        default=True,
49
+        action='store_true',
50
+        help='show download progress',
51
+    )
52
+    progress_group.add_argument(
53
+        '--no-progress',
54
+        dest='progress',
55
+        action='store_false',
56
+        help='do not show download progress',
57
+    )
45 58
 
46 59
     config.register_argparse_arguments(parser, sys.argv, None)
47 60
     subparsers = parser.add_subparsers(title='commands')

+ 8
- 3
aerostat/download.py View File

@@ -58,9 +58,10 @@ class ProgressBarDownloader:
58 58
 
59 59
 class Downloader:
60 60
 
61
-    def __init__(self, output_dir, cloud):
61
+    def __init__(self, output_dir, cloud, use_progress_bar):
62 62
         self.output_dir = output_dir
63 63
         self.cloud = cloud
64
+        self.use_progress_bar = use_progress_bar
64 65
         self._tasks = []
65 66
 
66 67
     def _add(self, resource_type, resource, output_path):
@@ -91,8 +92,12 @@ class Downloader:
91 92
                     resource.name,
92 93
                     output_path,
93 94
                 )
94
-                with ProgressBarDownloader(output_path, resource.size) as out:
95
-                    self.cloud.download_image(resource.name, output_file=out)
95
+                if self.use_progress_bar:
96
+                    with ProgressBarDownloader(output_path, resource.size) as out:
97
+                        self.cloud.download_image(resource.name, output_file=out)
98
+                else:
99
+                    with open(output_path, 'wb') as out:
100
+                        self.cloud.download_image(resource.name, output_file=out)
96 101
                 LOG.info(
97 102
                     'downloaded image %s to %s',
98 103
                     resource.name,

+ 5
- 1
aerostat/export.py View File

@@ -27,7 +27,11 @@ LOG = logging.getLogger(__name__)
27 27
 def export_data(cloud, config, args):
28 28
     output_path = args.output_path
29 29
 
30
-    downloader = download.Downloader(output_path, cloud)
30
+    downloader = download.Downloader(
31
+        output_path,
32
+        cloud,
33
+        use_progress_bar=(args.progress and (args.verbose_level >= 1)),
34
+    )
31 35
     res = resolver.Resolver(cloud, downloader)
32 36
     tasks = []
33 37
 

Loading…
Cancel
Save