Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable tqdm by default #11

Merged
merged 1 commit into from
Nov 9, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions conda_mirror/conda_mirror.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
import tarfile


logging.basicConfig(level=logging.INFO)
logging.basicConfig(level=logging.INFO,
format='%(asctime)-15s %(message)s')
DEFAULT_BAD_LICENSES = ['agpl', '']

DOWNLOAD_URL="https://anaconda.org/{channel}/{name}/{version}/download/{platform}/{file_name}"
Expand Down Expand Up @@ -75,6 +76,12 @@ def _make_arg_parser():
" 'linux-64', 'linux-32', 'osx-64', 'win-32', 'win-64'}"),
default=[],
)
ap.add_argument(
'-v', '--verbose',
action="store_true",
help="This basically turns on tqdm progress bars for downloads",
default=False,
)

return ap

Expand All @@ -88,7 +95,7 @@ def cli():
if 'all' in args.platform and len(args.platform) != 1:
logging.warning("If you pass 'all' as a platform option, all other "
"options will be ignored")
main(args.upstream_channel, args.target_directory, args.platform)
main(args.upstream_channel, args.target_directory, args.platform, args.verbose)


def not_in_upstream(local_repo_metadata, upstream_repo_metadata):
Expand Down Expand Up @@ -167,7 +174,7 @@ def not_blacklisted_license(package_names_to_mirror, upstream_repo_metadata,
yield pkg


def main(upstream_channel, target_directory, platform):
def main(upstream_channel, target_directory, platform, verbose=False):
"""
The business logic of conda_mirror.

Expand All @@ -181,6 +188,8 @@ def main(upstream_channel, target_directory, platform):
platform : iterable
The platforms that you want to mirror from anaconda.org/<upstream_channel>
The defaults are listed in the module level global "DEFAULT_PLATFORMS"
verbose : bool
Increase chattiness of conda-mirror
"""
full_platform_list = copy.copy(platform)
if 'all' in full_platform_list:
Expand Down Expand Up @@ -235,10 +244,13 @@ def main(upstream_channel, target_directory, platform):
with open(os.path.join(target_directory, platform, package), 'wb') as f:
logging.info("Downloading {}".format(package))
ret = requests.get(url, stream=True)
for data in tqdm.tqdm(ret.iter_content(chunk_size),
desc=package,
unit="KB",
total=expected_iterations):
iterator = ret.iter_content(chunk_size)
if verbose:
iterator = tqdm.tqdm(iterator,
desc=package,
unit="KB",
total=expected_iterations)
for data in iterator:
f.write(data)
if idx % 5 == 0:
# intermittently run conda index so that, in case of failure,
Expand Down