def run(): parser = make_parser() if len(sys.argv) == 1: parser.print_help() return args = parser.parse_args(sys.argv[1:]) if args.log is not None: level = getattr(logging, args.log.upper()) log.setLevel(level=level) log.debug('Commandline arguments: %s', args) if args.no_check_certificate: try: import ssl ssl._create_default_https_context = ssl._create_unverified_context except ImportError: pass app = Application(timeout=args.timeout, quiet=args.quiet) if (not args.print_fastest_mirror) and (args.url_or_tarball is None): parser.print_help() print('') print( 'error: either --print-fastest-mirror or url_or_tarball is required' ) sys.exit(2) if args.print_fastest_mirror: app.print_fastest_mirror() elif is_url(args.url_or_tarball): app.download_url(args.url_or_tarball, args.destination) else: app.download_tarball(args.url_or_tarball, args.destination, args.allow_upstream)
def test_print_mirror_list_no_network(self): """ Subsequent runs of sage-download-file """ try: os.remove(MIRRORLIST_FILENAME) except OSError: pass env = dict(os.environ) env['http_proxy'] = 'http://192.0.2.0:5187/' env['https_proxy'] = 'http://192.0.2.0:5187/' env['ftp_proxy'] = 'http://192.0.2.0:5187/' env['rsync_proxy'] = 'http://192.0.2.0:5187/' proc = subprocess.Popen( [EXECUTABLE, '--print-fastest-mirror', '--timeout=0.001'], stdin=None, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env, ) stdout, stderr = proc.communicate() stdout = stdout.decode('utf-8') stderr = stderr.decode('utf-8') rc = proc.returncode # returns successfully self.assertEqual(rc, 0) # Prints single url (the default) to stdout self.assertTrue(is_url(stdout)) # Prints error to stderr self.assertTrue(stderr.find('Downloading the mirror list failed') >= 0)
def test_print_mirror_list_no_network(self): """ Subsequent runs of sage-download-file """ try: os.remove(MIRRORLIST_FILENAME) except OSError: pass env = dict(os.environ) env['http_proxy'] = 'http://192.0.2.0:5187/' env['https_proxy'] = 'http://192.0.2.0:5187/' env['ftp_proxy'] = 'http://192.0.2.0:5187/' env['rsync_proxy'] = 'http://192.0.2.0:5187/' proc = subprocess.Popen( [EXECUTABLE, '--print-fastest-mirror', '--timeout=0.001'], stdin=None, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env, ) stdout, stderr = proc.communicate() stdout = stdout.decode('utf-8') stderr = stderr.decode('utf-8') rc = proc.returncode # returns successfully self.assertEqual(rc, 0) # Prints single url (the default) to stdout self.assertTrue(is_url(stdout)) # Prints error to stderr self.assertTrue(stderr.find('Downloading the mirror list failed') >= 0)
def test_print_mirror_list_cached(self): """ Subsequent runs of sage-download-file """ proc = subprocess.Popen( [EXECUTABLE, '--print-fastest-mirror'], stdin=None, stdout=subprocess.PIPE, stderr=subprocess.PIPE, ) stdout, stderr = proc.communicate() stdout = stdout.decode('utf-8') stderr = stderr.decode('utf-8') rc = proc.returncode # returns successfully self.assertEqual(rc, 0) # Prints single url to stdout self.assertTrue(is_url(stdout))
def test_print_mirror_list_cached(self): """ Subsequent runs of sage-download-file """ proc = subprocess.Popen( [EXECUTABLE, '--print-fastest-mirror'], stdin=None, stdout=subprocess.PIPE, stderr=subprocess.PIPE, ) stdout, stderr = proc.communicate() stdout = stdout.decode('utf-8') stderr = stderr.decode('utf-8') rc = proc.returncode # returns successfully self.assertEqual(rc, 0) # Prints single url to stdout self.assertTrue(is_url(stdout))
def run(): parser = make_parser() if len(sys.argv) == 1: parser.print_help() return args = parser.parse_args(sys.argv[1:]) if args.log is not None: level = getattr(logging, args.log.upper()) log.setLevel(level=level) log.debug('Commandline arguments: %s', args) app = Application(timeout=args.timeout, quiet=args.quiet) if (not args.print_fastest_mirror) and (args.url_or_tarball is None): parser.print_help() print('') print('error: either --print-fastest-mirror or url_or_tarball is required') sys.exit(2) if args.print_fastest_mirror: app.print_fastest_mirror() elif is_url(args.url_or_tarball): app.download_url(args.url_or_tarball, args.destination) else: app.download_tarball(args.url_or_tarball, args.destination)
def test_print_mirror_list_timing(self): """ The first run of sage-download-file """ try: os.remove(MIRRORLIST_FILENAME) except OSError: pass proc = subprocess.Popen( [EXECUTABLE, '--print-fastest-mirror'], stdin=None, stdout=subprocess.PIPE, stderr=subprocess.PIPE, ) stdout, stderr = proc.communicate() stdout = stdout.decode('utf-8') stderr = stderr.decode('utf-8') rc = proc.returncode # returns successfully self.assertEqual(rc, 0) # Prints single url to stdout self.assertTrue(is_url(stdout)) # Prints mirrors to stderr self.assertTrue(len(stderr.strip().splitlines()) > 3)
def test_print_mirror_list_timing(self): """ The first run of sage-download-file """ try: os.remove(MIRRORLIST_FILENAME) except OSError: pass proc = subprocess.Popen( [EXECUTABLE, '--print-fastest-mirror'], stdin=None, stdout=subprocess.PIPE, stderr=subprocess.PIPE, ) stdout, stderr = proc.communicate() stdout = stdout.decode('utf-8') stderr = stderr.decode('utf-8') rc = proc.returncode # returns successfully self.assertEqual(rc, 0) # Prints single url to stdout self.assertTrue(is_url(stdout)) # Prints mirrors to stderr self.assertTrue(len(stderr.strip().splitlines()) > 3)
def test_single_line(self): self.assertFalse(is_url('http://foo.bar/baz\nhttp://foo.bar/baz'))
def test_nospace(self): self.assertFalse(is_url('http://foo. bar/baz'))
def test_ftp(self): self.assertTrue(is_url('ftp://foo.bar/baz'))
def test_https(self): self.assertTrue(is_url('https://foo.bar/baz'))
def test_single_line(self): self.assertFalse(is_url('http://foo.bar/baz\nhttp://foo.bar/baz'))
def test_nospace(self): self.assertFalse(is_url('http://foo. bar/baz'))
def test_ftp(self): self.assertTrue(is_url('ftp://foo.bar/baz'))
def test_https(self): self.assertTrue(is_url('https://foo.bar/baz'))