Beispiel #1
0
    def test_files_cache(self):
        # Given
        yaml_string = textwrap.dedent("""\
            files_cache: "/foo/bar"
        """)

        # When
        config = Configuration.from_yaml_filename(StringIO(yaml_string))

        # Then
        self.assertFalse(config.use_webservice)
        self.assertEqual(config.repository_cache, "/foo/bar")

        # Given
        yaml_string = textwrap.dedent("""\
            files_cache: "~/foo/bar/{PLATFORM}"
        """)

        # When
        config = Configuration.from_yaml_filename(StringIO(yaml_string))

        # Then
        self.assertFalse(config.use_webservice)
        self.assertEqual(config.repository_cache,
                         os.path.expanduser("~/foo/bar/{0}".format(custom_plat)))
Beispiel #2
0
    def test_files_cache(self):
        # Given
        yaml_string = textwrap.dedent("""\
            files_cache: "/foo/bar"
        """)

        # When
        config = Configuration.from_yaml_filename(StringIO(yaml_string))

        # Then
        self.assertFalse(config.use_webservice)
        self.assertEqual(config.repository_cache, "/foo/bar")

        # Given
        yaml_string = textwrap.dedent("""\
            files_cache: "~/foo/bar/{PLATFORM}"
        """)

        # When
        config = Configuration.from_yaml_filename(StringIO(yaml_string))

        # Then
        self.assertFalse(config.use_webservice)
        self.assertEqual(
            config.repository_cache,
            os.path.expanduser("~/foo/bar/{0}".format(custom_plat)))
Beispiel #3
0
    def test_api_token_authentication(self):
        # Given
        yaml_string = textwrap.dedent("""\
            authentication:
              kind: token
              api_token: ulysse
        """)

        # When
        config = Configuration.from_yaml_filename(StringIO(yaml_string))

        # Then
        self.assertFalse(config.use_webservice)
        self.assertEqual(config.auth, APITokenAuth("ulysse"))

        # Given
        yaml_string = textwrap.dedent("""\
            authentication:
              api_token: ulysse
        """)

        # When
        config = Configuration.from_yaml_filename(StringIO(yaml_string))

        # Then
        self.assertFalse(config.use_webservice)
        self.assertEqual(config.auth, APITokenAuth("ulysse"))
Beispiel #4
0
    def test_api_token_authentication(self):
        # Given
        yaml_string = textwrap.dedent("""\
            authentication:
              kind: token
              api_token: ulysse
        """)

        # When
        config = Configuration.from_yaml_filename(StringIO(yaml_string))

        # Then
        self.assertFalse(config.use_webservice)
        self.assertEqual(config.auth, APITokenAuth("ulysse"))

        # Given
        yaml_string = textwrap.dedent("""\
            authentication:
              api_token: ulysse
        """)

        # When
        config = Configuration.from_yaml_filename(StringIO(yaml_string))

        # Then
        self.assertFalse(config.use_webservice)
        self.assertEqual(config.auth, APITokenAuth("ulysse"))
Beispiel #5
0
    def test_invalid_format(self):
        # Given
        yaml_string = textwrap.dedent("""\
            repositoriess:
              - enthought/commercial
        """)

        # When/Then
        with self.assertRaises(InvalidConfiguration):
            Configuration.from_yaml_filename(StringIO(yaml_string))
Beispiel #6
0
    def test_invalid_format(self):
        # Given
        yaml_string = textwrap.dedent("""\
            repositoriess:
              - enthought/commercial
        """)

        # When/Then
        with self.assertRaises(InvalidConfiguration):
            Configuration.from_yaml_filename(StringIO(yaml_string))
Beispiel #7
0
    def test_simple(self):
        # Given
        yaml_string = textwrap.dedent("""\
            store_url: "http://acme.com"

            repositories:
              - enthought/free
              - enthought/commercial
        """)
        platform = custom_plat
        python_tag = PythonImplementation.from_running_python().pep425_tag

        r_indices = (
            ('http://acme.com/api/v0/json/indices/enthought/free/{0}/{1}/eggs'
             .format(platform, python_tag)),
            ('http://acme.com/api/v0/json/indices/enthought/commercial/{0}/{1}/eggs'
             .format(platform, python_tag)),
        )

        # When
        config = Configuration.from_yaml_filename(StringIO(yaml_string))

        # Then
        self.assertFalse(config.use_webservice)
        self.assertEqual(config.store_url, "http://acme.com")
        self.assertEqual(
            tuple(repository_info.index_url
                  for repository_info in config.repositories),
            r_indices
        )
        self.assertEqual(config.max_retries, 0)
        self.assertTrue(config.verify_ssl)
Beispiel #8
0
    def test_load_from_path(self):
        # Given
        yaml_string = textwrap.dedent("""\
            repositories:
              - enthought/free
              - enthought/commercial
        """)
        platform = custom_plat
        r_indices = tuple(((
            'https://api.enthought.com/repo/enthought/free/{0}/index.json'.
            format(platform),
            'https://api.enthought.com/repo/enthought/free/{0}/index.json'.
            format(platform)
        ), ('https://api.enthought.com/repo/enthought/commercial/{0}/index.json'
            .format(platform),
            'https://api.enthought.com/repo/enthought/commercial/{0}/index.json'
            .format(platform))))

        with mkdtemp() as prefix:
            path = os.path.join(prefix, "enstaller.yaml")
            with open(path, "wt") as fp:
                fp.write(yaml_string)

            # When
            config = Configuration.from_yaml_filename(path)

            # Then
            self.assertFalse(config.use_webservice)
            self.assertEqual(config.store_url, "https://api.enthought.com")
            self.assertEqual(config.indices, r_indices)
Beispiel #9
0
    def test_simple(self):
        # Given
        yaml_string = textwrap.dedent("""\
            store_url: "http://acme.com"

            repositories:
              - enthought/free
              - enthought/commercial
        """)
        platform = custom_plat
        r_indices = tuple(
            (('http://acme.com/repo/enthought/free/{0}/index.json'.format(
                platform),
              'http://acme.com/repo/enthought/free/{0}/index.json'.format(
                  platform)),
             ('http://acme.com/repo/enthought/commercial/{0}/index.json'.
              format(platform),
              'http://acme.com/repo/enthought/commercial/{0}/index.json'.
              format(platform))))

        # When
        config = Configuration.from_yaml_filename(StringIO(yaml_string))

        # Then
        self.assertFalse(config.use_webservice)
        self.assertEqual(config.store_url, "http://acme.com")
        self.assertEqual(config.indices, r_indices)
        self.assertEqual(config.max_retries, 0)
        self.assertTrue(config.verify_ssl)
Beispiel #10
0
    def test_simple(self):
        # Given
        yaml_string = textwrap.dedent("""\
            store_url: "http://acme.com"

            repositories:
              - enthought/free
              - enthought/commercial
        """)
        platform = custom_plat
        r_indices = tuple((
            ('http://acme.com/repo/enthought/free/{0}/index.json'.format(platform),
             'http://acme.com/repo/enthought/free/{0}/index.json'.format(platform)),
            ('http://acme.com/repo/enthought/commercial/{0}/index.json'.format(platform),
             'http://acme.com/repo/enthought/commercial/{0}/index.json'.format(platform))
        ))

        # When
        config = Configuration.from_yaml_filename(StringIO(yaml_string))

        # Then
        self.assertFalse(config.use_webservice)
        self.assertEqual(config.store_url, "http://acme.com")
        self.assertEqual(config.indices, r_indices)
        self.assertEqual(config.max_retries, 0)
        self.assertTrue(config.verify_ssl)
Beispiel #11
0
    def test_load_from_path(self):
        # Given
        yaml_string = textwrap.dedent("""\
            repositories:
              - enthought/free
              - enthought/commercial
        """)
        platform = custom_plat
        r_indices = tuple((
            ('https://api.enthought.com/repo/enthought/free/{0}/index.json'.format(platform),
             'https://api.enthought.com/repo/enthought/free/{0}/index.json'.format(platform)),
            ('https://api.enthought.com/repo/enthought/commercial/{0}/index.json'.format(platform),
             'https://api.enthought.com/repo/enthought/commercial/{0}/index.json'.format(platform))
        ))

        with mkdtemp() as prefix:
            path = os.path.join(prefix, "enstaller.yaml")
            with open(path, "wt") as fp:
                fp.write(yaml_string)

            # When
            config = Configuration.from_yaml_filename(path)

            # Then
            self.assertFalse(config.use_webservice)
            self.assertEqual(config.store_url, "https://api.enthought.com")
            self.assertEqual(config.indices, r_indices)
Beispiel #12
0
    def test_load_from_path(self):
        # Given
        yaml_string = textwrap.dedent("""\
            repositories:
              - enthought/free
              - enthought/commercial
        """)
        platform = custom_plat
        python_tag = PythonImplementation.from_running_python().pep425_tag

        r_indices = (
            ('https://api.enthought.com/api/v0/json/indices/enthought/free/{0}/{1}/eggs'
             .format(platform, python_tag)),
            ('https://api.enthought.com/api/v0/json/indices/enthought/commercial/{0}/{1}/eggs'
             .format(platform, python_tag)),
        )

        with mkdtemp() as prefix:
            path = os.path.join(prefix, "enstaller.yaml")
            with open(path, "wt") as fp:
                fp.write(yaml_string)

            # When
            config = Configuration.from_yaml_filename(path)

            # Then
            self.assertFalse(config.use_webservice)
            self.assertEqual(config.store_url, "https://api.enthought.com")
            self.assertEqual(
                tuple(repository_info.index_url
                      for repository_info in config.repositories),
                r_indices
            )
Beispiel #13
0
    def test_default(self):
        # Given/When
        config = Configuration.from_yaml_filename(StringIO(""))

        # Then
        self.assertFalse(config.use_webservice)
        self.assertFalse(config.indices, [])
        self.assertEqual(config.repository_cache, os.path.join(sys.prefix,
                                                               "LOCAL-REPO"))
        self.assertEqual(config.store_kind, "brood")
Beispiel #14
0
    def test_default(self):
        # Given/When
        config = Configuration.from_yaml_filename(StringIO(""))

        # Then
        self.assertFalse(config.use_webservice)
        self.assertFalse(config.indices, [])
        self.assertEqual(config.repository_cache,
                         os.path.join(sys.prefix, "LOCAL-REPO"))
        self.assertEqual(config.store_kind, "brood")
Beispiel #15
0
    def test_max_retries(self):
        # Given
        yaml_string = textwrap.dedent("""\
            max_retries: 1
        """)

        # When
        config = Configuration.from_yaml_filename(StringIO(yaml_string))

        # Then
        self.assertEqual(config.max_retries, 1)
Beispiel #16
0
    def test_max_retries(self):
        # Given
        yaml_string = textwrap.dedent("""\
            max_retries: 1
        """)

        # When
        config = Configuration.from_yaml_filename(StringIO(yaml_string))

        # Then
        self.assertEqual(config.max_retries, 1)
Beispiel #17
0
    def test_verify_ssl(self):
        # Given
        yaml_string = textwrap.dedent("""\
            verify_ssl: True
        """)

        # When
        config = Configuration.from_yaml_filename(StringIO(yaml_string))

        # Then
        self.assertTrue(config.verify_ssl)

        # Given
        yaml_string = textwrap.dedent("""\
            verify_ssl: False
        """)

        # When
        config = Configuration.from_yaml_filename(StringIO(yaml_string))

        # Then
        self.assertFalse(config.verify_ssl)
Beispiel #18
0
    def test_verify_ssl(self):
        # Given
        yaml_string = textwrap.dedent("""\
            verify_ssl: True
        """)

        # When
        config = Configuration.from_yaml_filename(StringIO(yaml_string))

        # Then
        self.assertTrue(config.verify_ssl)

        # Given
        yaml_string = textwrap.dedent("""\
            verify_ssl: False
        """)

        # When
        config = Configuration.from_yaml_filename(StringIO(yaml_string))

        # Then
        self.assertFalse(config.verify_ssl)
Beispiel #19
0
    def test_basic_authentication(self):
        # Given
        yaml_string = textwrap.dedent("""\
            authentication:
              kind: basic
              auth: {0}
        """.format(UserPasswordAuth("*****@*****.**", "ulysse")._encoded_auth))

        # When
        config = Configuration.from_yaml_filename(StringIO(yaml_string))

        # Then
        self.assertFalse(config.use_webservice)
        self.assertEqual(config.auth,
                         UserPasswordAuth("*****@*****.**", "ulysse"))
Beispiel #20
0
    def test_basic_authentication(self):
        # Given
        yaml_string = textwrap.dedent("""\
            authentication:
              kind: basic
              auth: {0}
        """.format(UserPasswordAuth("*****@*****.**", "ulysse")._encoded_auth))

        # When
        config = Configuration.from_yaml_filename(StringIO(yaml_string))

        # Then
        self.assertFalse(config.use_webservice)
        self.assertEqual(config.auth,
                         UserPasswordAuth("*****@*****.**", "ulysse"))
Beispiel #21
0
    def test_simple_authentication(self):
        # Given
        yaml_string = textwrap.dedent("""\
            authentication:
              kind: simple
              username: [email protected]
              password: ulysse
        """)

        # When
        config = Configuration.from_yaml_filename(StringIO(yaml_string))

        # Then
        self.assertFalse(config.use_webservice)
        self.assertEqual(config.auth,
                         UserPasswordAuth("*****@*****.**", "ulysse"))
Beispiel #22
0
    def test_simple_authentication(self):
        # Given
        yaml_string = textwrap.dedent("""\
            authentication:
              kind: simple
              username: [email protected]
              password: ulysse
        """)

        # When
        config = Configuration.from_yaml_filename(StringIO(yaml_string))

        # Then
        self.assertFalse(config.use_webservice)
        self.assertEqual(config.auth,
                         UserPasswordAuth("*****@*****.**", "ulysse"))
Beispiel #23
0
    def test_repositories(self):
        # Given
        yaml_string = textwrap.dedent("""\
            store_url: "http://www.acme.com"

            repositories:
              - "enthought/free"
              - "file:///foo"
        """)
        r_repositories = (
            BroodRepositoryInfo("http://www.acme.com", "enthought/free"),
            FSRepositoryInfo("file:///foo"),
        )

        # When
        config = Configuration.from_yaml_filename(StringIO(yaml_string))

        # Then
        self.assertEqual(config.repositories, r_repositories)
Beispiel #24
0
    def test_repositories(self):
        # Given
        yaml_string = textwrap.dedent("""\
            store_url: "http://www.acme.com"

            repositories:
              - "enthought/free"
              - "file:///foo"
        """)
        r_repositories = (
            "http://www.acme.com/repo/enthought/free/{0}/".format(custom_plat),
            "file:///foo/".format(custom_plat),
        )

        # When
        config = Configuration.from_yaml_filename(StringIO(yaml_string))

        # Then
        self.assertEqual(config.indexed_repositories, r_repositories)
Beispiel #25
0
    def test_repositories(self):
        # Given
        yaml_string = textwrap.dedent("""\
            store_url: "http://www.acme.com"

            repositories:
              - "enthought/free"
              - "file:///foo"
        """)
        r_repositories = (
            "http://www.acme.com/repo/enthought/free/{0}/".format(custom_plat),
            "file:///foo/".format(custom_plat),
        )

        # When
        config = Configuration.from_yaml_filename(StringIO(yaml_string))

        # Then
        self.assertEqual(config.indexed_repositories, r_repositories)
Beispiel #26
0
def main(argv=None):
    if argv is None:  # pragma: no cover
        argv = sys.argv[1:]

    parser, args = _preprocess_options(argv)

    pat = None
    if (args.list or args.search) and args.cnames:
        pat = re.compile(args.cnames[0], re.I)

    if args.config_path:
        config_filename = args.config_path
        try:
            config = Configuration.from_yaml_filename(config_filename)
        except IOError:
            msg = "Error: File {0!r} could not be read".format(config_filename)
            print(msg)
            sys.exit(-1)
        else:
            if config.auth is None:
                print("Authentication missing from {0!r}".format(
                    config_filename))
                sys.exit(-1)
            use_new_format = True
    else:
        config = _ensure_config_or_die()
        config_filename = config.filename
        use_new_format = False

    setup_proxy_or_die(config, args.proxy)

    prefix, prefixes = _compute_prefixes(args, config)

    if args.user:
        try:
            check_prefixes(prefixes)
        except InvalidPythonPathConfiguration:
            msg = "Using the --user option, but your PYTHONPATH is not " \
                  "setup accordingly"
            warnings.warn(msg)

    exit_if_sudo_on_venv(prefix)

    logger.info("prefixes")
    for prefix in prefixes:
        logger.info('    %s%s', prefix, ['', ' (sys)'][prefix == sys.prefix])

    if hasattr(args, "insecure"):
        config.update(verify_ssl=not args.insecure)

    if hasattr(args, "max_retries"):
        config.update(max_retries=args.max_retries)

    with Session.from_configuration(config) as session:
        if dispatch_commands_without_enpkg(args, config, config_filename,
                                           prefixes, prefix, pat, session):
            return

        if config.auth is None:
            configure_authentication_or_exit(config, config_filename, session)
        ensure_authenticated_config(config,
                                    config_filename,
                                    session,
                                    use_new_format=use_new_format)

        repository = repository_factory(session, config.indices, args.quiet)
        if args.quiet:
            progress_bar_context = None
        else:

            def fetch_progress_factory(*a, **kw):
                return console_progress_manager_factory(*a,
                                                        show_speed=True,
                                                        **kw)

            progress_bar_context = ProgressBarContext(
                console_progress_manager_factory, fetch=fetch_progress_factory)
        enpkg = Enpkg(repository,
                      session,
                      prefixes,
                      progress_bar_context,
                      args.force or args.forceall,
                      max_retries=config.max_retries)

        dispatch_commands_with_enpkg(args, enpkg, config, prefix, session,
                                     parser, pat)
Beispiel #27
0
def main(argv=None):
    if argv is None:  # pragma: no cover
        argv = sys.argv[1:]

    parser, args = _preprocess_options(argv)

    pat = None
    if (args.list or args.search) and args.cnames:
        pat = re.compile(args.cnames[0], re.I)

    if args.config_path:
        config_filename = os.path.expanduser(args.config_path)
        try:
            config = Configuration.from_yaml_filename(config_filename)
        except IOError:
            msg = "Error: File {0!r} could not be read".format(config_filename)
            print(msg)
            sys.exit(-1)
        else:
            if config.auth is None:
                print("Authentication missing from {0!r}".format(config_filename))
                sys.exit(-1)
            use_new_format = True
    else:
        config = _ensure_config_or_die()
        config_filename = config.filename
        use_new_format = False

    setup_proxy_or_die(config, args.proxy)

    prefix, prefixes = _compute_prefixes(args, config)
    config.update(prefix=prefix)

    if args.user:
        try:
            check_prefixes(prefixes)
        except InvalidPythonPathConfiguration:
            msg = "Using the --user option, but your PYTHONPATH is not " \
                  "setup accordingly"
            warnings.warn(msg)

    exit_if_root_on_non_owned(args.yes)

    logger.info("prefixes")
    for prefix in prefixes:
        logger.info('    %s%s', prefix, ['', ' (sys)'][prefix == sys.prefix])

    if hasattr(args, "insecure"):
        config.update(verify_ssl=not args.insecure)

    if hasattr(args, "max_retries"):
        config.update(max_retries=args.max_retries)

    with Session.from_configuration(config) as session:
        if dispatch_commands_without_enpkg(args, config, config_filename,
                                           prefixes, prefix, pat,
                                           session):
            return

        if config.auth is None:
            configure_authentication_or_exit(config, config_filename,
                                             session)
        ensure_authenticated_config(config, config_filename, session,
                                    use_new_format=use_new_format)

        repository = repository_factory(session, config.repositories,
                                        args.quiet)
        if args.quiet:
            progress_bar_context = None
        else:
            def fetch_progress_factory(*a, **kw):
                return console_progress_manager_factory(*a, show_speed=True,
                                                        **kw)

            progress_bar_context = ProgressBarContext(
                console_progress_manager_factory, fetch=fetch_progress_factory)
        enpkg = Enpkg(repository, session, prefixes, progress_bar_context,
                      args.force or args.forceall,
                      max_retries=config.max_retries)

        dispatch_commands_with_enpkg(args, enpkg, config, prefix, session, parser,
                                     pat)