Exemplo n.º 1
0
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)
Exemplo n.º 2
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)
Exemplo n.º 3
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)
Exemplo n.º 4
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))
Exemplo n.º 5
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))
Exemplo n.º 6
0
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)
Exemplo n.º 7
0
 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)
Exemplo n.º 8
0
 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)
Exemplo n.º 9
0
 def test_single_line(self):
     self.assertFalse(is_url('http://foo.bar/baz\nhttp://foo.bar/baz'))
Exemplo n.º 10
0
 def test_nospace(self):
     self.assertFalse(is_url('http://foo. bar/baz'))
Exemplo n.º 11
0
 def test_ftp(self):
     self.assertTrue(is_url('ftp://foo.bar/baz'))
Exemplo n.º 12
0
 def test_https(self):
     self.assertTrue(is_url('https://foo.bar/baz'))
Exemplo n.º 13
0
 def test_single_line(self):
     self.assertFalse(is_url('http://foo.bar/baz\nhttp://foo.bar/baz'))
Exemplo n.º 14
0
 def test_nospace(self):
     self.assertFalse(is_url('http://foo. bar/baz'))
Exemplo n.º 15
0
 def test_ftp(self):
     self.assertTrue(is_url('ftp://foo.bar/baz'))
Exemplo n.º 16
0
 def test_https(self):
     self.assertTrue(is_url('https://foo.bar/baz'))