Skip to content

Commit 486a67c

Browse files
authored
Merge pull request #188 from kba/really-quiet
Make 'quiet' truly quiet
2 parents 8959b6e + bbcb86b commit 486a67c

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

grip/app.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ def __init__(self, source=None, auth=None, renderer=None,
9999
self.render_inline = render_inline
100100
self.title = title
101101
self.quiet = quiet
102+
if self.quiet:
103+
import logging
104+
log = logging.getLogger('werkzeug')
105+
log.setLevel(logging.ERROR)
106+
102107

103108
# Overridable attributes
104109
if self.renderer is None:
@@ -345,7 +350,7 @@ def default_asset_manager(self):
345350
if cache_directory:
346351
cache_directory = cache_directory.format(version=__version__)
347352
cache_path = os.path.join(self.instance_path, cache_directory)
348-
return GitHubAssetManager(cache_path, self.config['STYLE_URLS'])
353+
return GitHubAssetManager(cache_path, self.config['STYLE_URLS'], self.quiet)
349354

350355
def add_content_types(self):
351356
"""

grip/assets.py

+10-6
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,12 @@ class ReadmeAssetManager(object):
2828
2929
Set cache_path to None to disable caching.
3030
"""
31-
def __init__(self, cache_path, style_urls=None):
31+
def __init__(self, cache_path, style_urls=None, quiet=None):
3232
super(ReadmeAssetManager, self).__init__()
3333
self.cache_path = cache_path
3434
self.style_urls = list(style_urls) if style_urls else []
3535
self.styles = []
36+
self.quiet = quiet
3637

3738
def _stip_url_params(self, url):
3839
return url.rsplit('?', 1)[0].rsplit('#', 1)[0]
@@ -67,8 +68,8 @@ class GitHubAssetManager(ReadmeAssetManager):
6768
6869
Set cache_path to None to disable caching.
6970
"""
70-
def __init__(self, cache_path, style_urls=None):
71-
super(GitHubAssetManager, self).__init__(cache_path, style_urls)
71+
def __init__(self, cache_path, style_urls=None, quiet=None):
72+
super(GitHubAssetManager, self).__init__(cache_path, style_urls, quiet)
7273

7374
def _get_style_urls(self, asset_url_path):
7475
"""
@@ -122,7 +123,8 @@ def _cache_contents(self, style_urls, asset_url_path):
122123

123124
asset_urls = []
124125
for style_url in style_urls:
125-
print(' * Downloading style', style_url, file=sys.stderr)
126+
if not self.quiet:
127+
print(' * Downloading style', style_url, file=sys.stderr)
126128
r = requests.get(style_url)
127129
if not 200 <= r.status_code < 300:
128130
print(' -> Warning: Style request responded with',
@@ -143,7 +145,8 @@ def _cache_contents(self, style_urls, asset_url_path):
143145
files[filename] = contents.encode('utf-8')
144146

145147
for asset_url in asset_urls:
146-
print(' * Downloading asset', asset_url, file=sys.stderr)
148+
if not self.quiet:
149+
print(' * Downloading asset', asset_url, file=sys.stderr)
147150
# Retrieve binary file and show message
148151
r = requests.get(asset_url, stream=True)
149152
if not 200 <= r.status_code < 300:
@@ -169,7 +172,8 @@ def _cache_contents(self, style_urls, asset_url_path):
169172
for filename in cache:
170173
with open(filename, 'wb') as f:
171174
f.write(cache[filename])
172-
print(' * Cached all downloads in', self.cache_path, file=sys.stderr)
175+
if not self.quiet:
176+
print(' * Cached all downloads in', self.cache_path, file=sys.stderr)
173177
return True
174178

175179
def retrieve_styles(self, asset_url_path):

0 commit comments

Comments
 (0)