def test_ensure_location(self): aserver_api = mock.MagicMock() aserver_api.package = mock.MagicMock(return_value=files) downloader = Downloader(aserver_api, 'username', 'notebook') self.assertEqual(downloader.list_files()[0]['version'], '2') self.assertEqual(downloader.list_files()[1]['version'], '2')
def main(args): aserver_api = get_server_api(args.token, args.site) username, notebook = parse(args.handle) username = username or aserver_api.user()['login'] downloader = Downloader(aserver_api, username, notebook) packages_types = args.package_type or list(PACKAGE_TYPES.keys()) # Check valid package type for ty in packages_types: if ty not in list(PACKAGE_TYPES.keys()): raise Exception("Invalid package type '{}'".format(ty)) try: download_files = downloader.list_download_files(packages_types, output=args.output, force=args.force) for download_file, download_dist in download_files.items(): downloader.download(download_dist) logger.info("{} has been downloaded as {}".format( args.handle, download_file)) if has_environment(download_file): logger.info( "{} has an environment embedded.".format(download_file)) logger.info("Run:") logger.info(" conda env create {}".format(download_file)) logger.info("To install the environment in your system") except (errors.DestionationPathExists, errors.NotFound, errors.BinstarError, OSError) as err: logger.info(err)
def test_ensure_location(self): binstar = mock.MagicMock() binstar.package = mock.MagicMock(return_value=files) downloader = Downloader(binstar, "username", "notebook") self.assertEqual(downloader.list_files()[0]["version"], "2") self.assertEqual(downloader.list_files()[1]["version"], "2")
def test_can_download(self): package_1 = {'basename': 'notebook.ipynb'} package_2 = {'basename': 'NOEXIST'} downloader = Downloader('binstar', 'username', 'notebook') downloader.output = data_dir('') self.assertTrue(not downloader.can_download(package_1)) self.assertTrue(downloader.can_download(package_1, True)) self.assertTrue(downloader.can_download(package_2))
def test_can_download(self): package_1 = {"basename": "notebook.ipynb"} package_2 = {"basename": "NOEXIST"} downloader = Downloader("binstar", "username", "notebook") downloader.output = self.data_dir("") self.assertTrue(not downloader.can_download(package_1)) self.assertTrue(downloader.can_download(package_1, True)) self.assertTrue(downloader.can_download(package_2))
def test_list_old_files(self): old_files = {'files': [{ 'basename': 'old-notebook', 'version': '1.0.0', 'upload_time': '2015-04-02 22:32:31.253000+00:00' }]} aserver_api = mock.MagicMock() aserver_api.package = mock.MagicMock(return_value=old_files) downloader = Downloader(aserver_api, 'username', 'notebook') self.assertEqual(downloader.list_files()[0]['version'], '1.0.0')
def test_list_old_files(self): old_files = { "files": [ {"basename": "old-notebook", "version": "1.0.0", "upload_time": "2015-04-02 22:32:31.253000+00:00"} ] } binstar = mock.MagicMock() binstar.package = mock.MagicMock(return_value=old_files) downloader = Downloader(binstar, "username", "notebook") self.assertEqual(downloader.list_files()[0]["version"], "1.0.0")
def test_list_old_files(self): old_files = { 'files': [{ 'basename': 'old-notebook', 'version': '1.0.0', 'upload_time': '2015-04-02 22:32:31.253000+00:00' }] } aserver_api = mock.MagicMock() aserver_api.package = mock.MagicMock(return_value=old_files) downloader = Downloader(aserver_api, 'username', 'notebook') self.assertEqual(downloader.list_files()[0]['version'], '1.0.0')
def download(args): binstar = get_binstar(args) username, notebook = parse(args.handle) username = username or binstar.user()['login'] downloader = Downloader(binstar, username, notebook) try: download_info = downloader(output=args.output, force=args.force) log.info("{} has been downloaded as {}.".format( args.handle, download_info[0])) except (errors.DestionationPathExists, errors.NotFound, OSError) as err: log.info(err.msg)
def test_can_download(self): package_1 = {'basename': 'notebook.ipynb'} package_2 = {'basename': 'NOEXIST'} downloader = Downloader('binstar', 'username', 'notebook') downloader.output = self.data_dir('') self.assertTrue(not downloader.can_download(package_1)) self.assertTrue(downloader.can_download(package_1, True)) self.assertTrue(downloader.can_download(package_2))
def main(args): aserver_api = get_server_api(args.token, args.site) username, notebook = parse(args.handle) username = username or aserver_api.user()['login'] downloader = Downloader(aserver_api, username, notebook) packages_types = args.package_type or list(PACKAGE_TYPES.keys()) # Check valid package type for ty in packages_types: if ty not in list(PACKAGE_TYPES.keys()): raise Exception("Invalid package type '{}'".format(ty)) try: download_files = downloader.list_download_files(packages_types, output=args.output, force=args.force) for download_file, download_dist in download_files.items(): downloader.download(download_dist) logger.info("{} has been downloaded as {}".format(args.handle, download_file)) if has_environment(download_file): logger.info("{} has an environment embedded.".format(download_file)) logger.info("Run:") logger.info(" conda env create {}".format(download_file)) logger.info("To install the environment in your system") except (errors.DestionationPathExists, errors.NotFound, errors.BinstarError, OSError) as err: logger.info(err)
def main(args): aserver_api = get_binstar(args) username, notebook = parse(args.handle) username = username or aserver_api.user()['login'] downloader = Downloader(aserver_api, username, notebook) try: download_info = downloader(output=args.output, force=args.force) log.info("{} has been downloaded as {}.".format(args.handle, download_info[0])) if has_environment(download_info[0]): log.info("{} has an environment embedded.".format(download_info[0])) log.info("Run:") log.info(" conda env create {}".format(download_info[0])) log.info("To install the environment in your system") except (errors.DestionationPathExists, errors.NotFound, errors.BinstarError, OSError) as err: log.info(err.msg)
def download(args): aserver_api = get_server_api(args.token, args.site, args.log_level) username, notebook = parse(args.handle) username = username or aserver_api.user()['login'] downloader = Downloader(aserver_api, username, notebook) try: download_info = downloader(output=args.output, force=args.force) log.warn("`anaconda notebook` is going to be deprecated") log.warn("use `anaconda download` instead.") log.info("{} has been downloaded as {}.".format( args.handle, download_info[0])) if has_environment(download_info[0]): log.info("{} has an environment embedded.".format( download_info[0])) log.info("Run:") log.info(" conda env create {}".format(download_info[0])) log.info("To install the environment in your system") except (errors.DestionationPathExists, errors.NotFound, OSError) as err: log.info(err.msg)