From 332b24e1721ca11d18cd59e75b36c24a7b328a98 Mon Sep 17 00:00:00 2001 From: Jens Nie Date: Tue, 10 Jan 2017 11:19:37 +0100 Subject: [PATCH] Update conda_mirror.py Added an optional command line parameter to choose the temporary download location for applying the checks before moving the packages to the target location, which was hardcoded to the default temporary directory before. Now this is the default location, when not explicitly specifying the temp_directory parameter. --- conda_mirror/conda_mirror.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/conda_mirror/conda_mirror.py b/conda_mirror/conda_mirror.py index cb093ed..2157ca2 100644 --- a/conda_mirror/conda_mirror.py +++ b/conda_mirror/conda_mirror.py @@ -110,6 +110,12 @@ def _make_arg_parser(): help='The place where packages should be mirrored to', required=True ) + ap.add_argument( + '--temp-directory', + help='Temporary download location for the packages', + required=False, + default=tempfile.gettempdir() + ) ap.add_argument( '--platform', help=("The OS platform(s) to mirror. one of: {'linux-64', 'linux-32'," @@ -179,8 +185,8 @@ def pdb_hook(exctype, value, traceback): blacklist = config_dict.get('blacklist') whitelist = config_dict.get('whitelist') - main(args.upstream_channel, args.target_directory, args.platform, - blacklist, whitelist) + main(args.upstream_channel, args.target_directory, args.temp_directory, + args.platform, blacklist, whitelist) def _remove_package(pkg_path): @@ -289,8 +295,8 @@ def _validate_packages(repodata, package_directory): size=info.get('size')) -def main(upstream_channel, target_directory, platform, blacklist=None, - whitelist=None): +def main(upstream_channel, target_directory, temp_directory, platform, + blacklist=None, whitelist=None): """ Parameters @@ -302,6 +308,10 @@ def main(upstream_channel, target_directory, platform, blacklist=None, The path on disk to produce a local mirror of the upstream channel. Note that this is the directory that contains the platform subdirectories. + temp_directory : str + The path on disk to an existing and writable directory to temporarily + store the packages before moving them to the target_directory to + apply checks platform : str The platform that you want to mirror from anaconda.org/ @@ -415,7 +425,7 @@ def main(upstream_channel, target_directory, platform, blacklist=None, # b. validate contents of temp file # c. move to local repo # mirror all new packages - with tempfile.TemporaryDirectory() as download_dir: + with tempfile.TemporaryDirectory(dir=temp_directory) as download_dir: logger.info('downloading to the tempdir %s', download_dir) for package_name in sorted(to_mirror): url = DOWNLOAD_URL.format(