コード例 #1
0
    def test_env_vars_output(self):
        users = {"remote1": "my_user", "my_artifactory": "other_user"}
        passwords = {"remote1": "my_pass", "my_artifactory": "my_pass2"}
        manager = AuthManager(self.conan_api,
                              self.printer,
                              login_input=users,
                              passwords_input=passwords)
        expected = {
            'CONAN_PASSWORD_REMOTE1': 'my_pass',
            'CONAN_LOGIN_USERNAME_REMOTE1': 'my_user',
            'CONAN_PASSWORD_MY_ARTIFACTORY': 'my_pass2',
            'CONAN_LOGIN_USERNAME_MY_ARTIFACTORY': 'other_user'
        }
        self.assertEquals(manager.env_vars(), expected)

        with tools.environment_append(expected):
            manager = AuthManager(self.conan_api, self.printer)
            self.assertEquals(manager.env_vars(), expected)

        manager = AuthManager(self.conan_api,
                              self.printer,
                              login_input="myuser",
                              passwords_input="mypassword")
        expected = {
            'CONAN_PASSWORD': '******',
            'CONAN_LOGIN_USERNAME': '******'
        }

        self.assertEquals(manager.env_vars(), expected)
コード例 #2
0
    def plain_multiple_from_env_test(self):
        # Bad mix
        with tools.environment_append({
                "CONAN_LOGIN_USERNAME_R1": "myuser",
                "CONAN_PASSWORD": "******"
        }):
            with self.assertRaisesRegexp(
                    Exception, "Password for remote 'R1' not specified"):
                AuthManager(self.conan_api, self.printer)

        with tools.environment_append({
                "CONAN_LOGIN_USERNAME_R1": "myuser",
                "CONAN_PASSWORD_R1": "mypass",
                "CONAN_LOGIN_USERNAME_R_OTHER": "myuser2",
                "CONAN_PASSWORD_R_OTHER": "mypass2"
        }):
            manager = AuthManager(self.conan_api, self.printer)
            user, password = manager.get_user_password("r1")
            self.assertEquals(user, "myuser")
            self.assertEquals(password, "mypass")

            user, password = manager.get_user_password("r_other")
            self.assertEquals(user, "myuser2")
            self.assertEquals(password, "mypass2")

        # Miss password
        with tools.environment_append({
                "CONAN_LOGIN_USERNAME_R1": "myuser",
                "CONAN_PASSWORD_R2": "mypass"
        }):
            with self.assertRaisesRegexp(
                    Exception, "Password for remote 'R1' not specified"):
                AuthManager(self.conan_api, self.printer)
コード例 #3
0
    def test_plain_credentials(self):

        # Without default
        manager = AuthManager(self.conan_api,
                              self.printer,
                              login_input="myuser",
                              passwords_input="mypassword")

        user, password = manager.get_user_password("any")
        self.assertEquals(user, "myuser")
        self.assertEquals(password, "mypassword")

        user, password = manager.get_user_password(None)
        self.assertEquals(user, "myuser")
        self.assertEquals(password, "mypassword")

        # Only password is discarded
        manager = AuthManager(self.conan_api,
                              self.printer,
                              passwords_input="mypassword")
        user, password = manager.get_user_password()
        self.assertEquals(user, None)
        self.assertEquals(password, None)

        # With default
        manager = AuthManager(self.conan_api,
                              self.printer,
                              passwords_input="mypassword",
                              default_username="******")

        user, password = manager.get_user_password("any")
        self.assertEquals(user, "myuser")
        self.assertEquals(password, "mypassword")
コード例 #4
0
    def test_dict_credentials(self):
        users = {"remote1": "my_user", "my_artifactory": "other_user"}
        passwords = {"remote1": "my_pass", "my_artifactory": "my_pass2"}
        manager = AuthManager(self.conan_api,
                              self.printer,
                              login_input=users,
                              passwords_input=passwords,
                              default_username=None)

        with self.assertRaisesRegexp(
                Exception, "User and password for remote "
                "'not_exist' not specified"):
            manager.get_user_password("not_exist")

        user, password = manager.get_user_password("my_artifactory")
        self.assertEquals(user, "other_user")
        self.assertEquals(password, "my_pass2")

        user, password = manager.get_user_password("remote1")
        self.assertEquals(user, "my_user")
        self.assertEquals(password, "my_pass")

        # Mix them
        with self.assertRaisesRegexp(Exception,
                                     "Specify a dict for 'login_username'"):
            AuthManager(self.conan_api,
                        self.printer,
                        passwords_input=passwords,
                        default_username="******")
コード例 #5
0
def run():
    # Get all from environ
    conan_api, client_cache, _ = Conan.factory()
    printer = Printer()

    remotes_manager = RemotesManager(conan_api, printer)
    remotes_manager.add_remotes_to_conan()
    default_username = os.getenv("CONAN_USERNAME")
    auth_manager = AuthManager(conan_api, printer, default_username=default_username)

    upload_retry = os.getenv("CPT_UPLOAD_RETRY")
    upload_only_recipe = os.getenv("CPT_UPLOAD_ONLY_RECIPE")
    uploader = Uploader(conan_api, remotes_manager, auth_manager, printer, upload_retry)
    build_policy = unscape_env(os.getenv("CPT_BUILD_POLICY"))
    test_folder = unscape_env(os.getenv("CPT_TEST_FOLDER"))
    reference = ConanFileReference.loads(os.getenv("CONAN_REFERENCE"))

    profile_text = unscape_env(os.getenv("CPT_PROFILE"))
    abs_profile_path = save_profile_to_tmp(profile_text)
    base_profile_text = unscape_env(os.getenv("CPT_BASE_PROFILE"))
    config_url = unscape_env(os.getenv("CPT_CONFIG_URL"))
    upload_dependencies = unscape_env(os.getenv("CPT_UPLOAD_DEPENDENCIES"))
    conanfile = unscape_env(os.getenv("CPT_CONANFILE"))
    if base_profile_text:
        base_profile_name = unscape_env(os.getenv("CPT_BASE_PROFILE_NAME"))
        tools.save(os.path.join(client_cache.profiles_path, base_profile_name),
                   base_profile_text)

    upload = os.getenv("CPT_UPLOAD_ENABLED")
    runner = CreateRunner(abs_profile_path, reference, conan_api, uploader,
                          build_policy=build_policy, printer=printer, upload=upload,
                          upload_only_recipe=upload_only_recipe,
                          test_folder=test_folder, config_url=config_url,
                          upload_dependencies=upload_dependencies, conanfile=conanfile)
    runner.run()
コード例 #6
0
def run():
    # Get all from environ
    conan_api, client_cache, _ = Conan.factory()
    printer = Printer()
    if os.path.exists(client_cache.default_profile_path):
        os.remove(client_cache.default_profile_path)

    remotes_manager = RemotesManager(conan_api, printer)
    default_username = os.getenv("CONAN_USERNAME", None)
    auth_manager = AuthManager(conan_api, printer, default_username=default_username)

    uploader = Uploader(conan_api, remotes_manager, auth_manager, printer)
    args = os.getenv("CPT_ARGS", "")
    build_policy = unscape_env(os.getenv("CPT_BUILD_POLICY"))
    reference = ConanFileReference.loads(os.getenv("CONAN_REFERENCE"))

    profile_text = unscape_env(os.getenv("CPT_PROFILE"))
    abs_profile_path = save_profile_to_tmp(profile_text)
    base_profile_text = unscape_env(os.getenv("CPT_BASE_PROFILE"))
    if base_profile_text:
        base_profile_name = unscape_env(os.getenv("CPT_BASE_PROFILE_NAME"))
        tools.save(os.path.join(client_cache.profiles_path, base_profile_name),
                   base_profile_text)

    upload = os.getenv("CPT_UPLOAD_ENABLED", None)
    runner = CreateRunner(abs_profile_path, reference, conan_api, uploader,
                          args=args,
                          build_policy=build_policy, printer=printer, upload=upload)
    runner.run()
コード例 #7
0
def run():
    conan_version = get_client_version()
    if conan_version < Version("1.18.0"):
        conan_api, client_cache, _ = Conan.factory()
    else:
        conan_api, _, _ = Conan.factory()
        conan_api.create_app()
        client_cache = conan_api.app.cache

    printer = Printer()

    remotes_manager = RemotesManager(conan_api, printer)
    remotes_manager.add_remotes_to_conan()
    default_username = os.getenv("CONAN_USERNAME")
    auth_manager = AuthManager(conan_api,
                               printer,
                               default_username=default_username)

    upload_retry = os.getenv("CPT_UPLOAD_RETRY")
    upload_only_recipe = os.getenv("CPT_UPLOAD_ONLY_RECIPE")
    upload_force = os.getenv("CPT_UPLOAD_FORCE")
    uploader = Uploader(conan_api, remotes_manager, auth_manager, printer,
                        upload_retry, upload_force)
    build_policy = unscape_env(os.getenv("CPT_BUILD_POLICY"))
    test_folder = unscape_env(os.getenv("CPT_TEST_FOLDER"))
    reference = ConanFileReference.loads(os.getenv("CONAN_REFERENCE"))

    profile_text = unscape_env(os.getenv("CPT_PROFILE"))
    abs_profile_path = save_profile_to_tmp(profile_text)
    base_profile_text = unscape_env(os.getenv("CPT_BASE_PROFILE"))
    config_url = unscape_env(os.getenv("CPT_CONFIG_URL"))
    config_args = unscape_env(os.getenv("CPT_CONFIG_ARGS"))
    upload_dependencies = unscape_env(os.getenv("CPT_UPLOAD_DEPENDENCIES"))
    update_dependencies = unscape_env(os.getenv("CPT_UPDATE_DEPENDENCIES"))
    conanfile = unscape_env(os.getenv("CPT_CONANFILE"))
    lockfile = unscape_env(os.getenv("CPT_LOCKFILE"))
    skip_recipe_export = unscape_env(os.getenv("CPT_SKIP_RECIPE_EXPORT"))
    if base_profile_text:
        base_profile_name = unscape_env(os.getenv("CPT_BASE_PROFILE_NAME"))
        tools.save(os.path.join(client_cache.profiles_path, base_profile_name),
                   base_profile_text)

    upload = os.getenv("CPT_UPLOAD_ENABLED")
    runner = CreateRunner(abs_profile_path,
                          reference,
                          conan_api,
                          uploader,
                          build_policy=build_policy,
                          printer=printer,
                          upload=upload,
                          upload_only_recipe=upload_only_recipe,
                          test_folder=test_folder,
                          config_url=config_url,
                          config_args=config_args,
                          upload_dependencies=upload_dependencies,
                          conanfile=conanfile,
                          skip_recipe_export=skip_recipe_export,
                          update_dependencies=update_dependencies,
                          lockfile=lockfile)
    runner.run()
コード例 #8
0
 def plain_from_env_test(self):
     with tools.environment_append({
             "CONAN_LOGIN_USERNAME": "******",
             "CONAN_PASSWORD": "******"
     }):
         manager = AuthManager(self.conan_api, self.printer)
         user, password = manager.get_user_password()
         self.assertEquals(user, "myuser")
         self.assertEquals(password, "mypass")
コード例 #9
0
    def __init__(self,
                 username=None,
                 channel=None,
                 runner=None,
                 gcc_versions=None,
                 visual_versions=None,
                 visual_runtimes=None,
                 visual_toolsets=None,
                 apple_clang_versions=None,
                 archs=None,
                 options=None,
                 use_docker=None,
                 curpage=None,
                 total_pages=None,
                 docker_image=None,
                 reference=None,
                 password=None,
                 remotes=None,
                 upload=None,
                 stable_branch_pattern=None,
                 vs10_x86_64_enabled=False,
                 mingw_configurations=None,
                 stable_channel=None,
                 platform_info=None,
                 upload_retry=None,
                 clang_versions=None,
                 login_username=None,
                 upload_only_when_stable=None,
                 upload_only_when_tag=None,
                 upload_only_recipe=None,
                 build_types=None,
                 cppstds=None,
                 skip_check_credentials=False,
                 allow_gcc_minors=False,
                 exclude_vcvars_precommand=False,
                 docker_run_options=None,
                 docker_image_skip_update=False,
                 docker_image_skip_pull=False,
                 docker_entry_script=None,
                 docker_32_images=None,
                 docker_conan_home=None,
                 docker_shell=None,
                 pip_install=None,
                 build_policy=None,
                 always_update_conan_in_docker=False,
                 conan_api=None,
                 client_cache=None,
                 conanfile=None,
                 ci_manager=None,
                 out=None,
                 test_folder=None,
                 cwd=None,
                 config_url=None,
                 config_args=None,
                 upload_dependencies=None,
                 force_selinux=None,
                 skip_recipe_export=False,
                 update_dependencies=None,
                 lockfile=None):

        conan_version = get_client_version()

        self.printer = Printer(out)
        self.printer.print_rule()
        self.printer.print_ascci_art()

        self.cwd = cwd or os.getcwd()

        if not conan_api:
            self.conan_api, _, _ = Conan.factory()
            self.conan_api.create_app()
            self.client_cache = self.conan_api.app.cache
        else:
            self.conan_api = conan_api
            self.client_cache = client_cache

        self.ci_manager = ci_manager or CIManager(self.printer)
        self.remotes_manager = RemotesManager(self.conan_api, self.printer,
                                              remotes, upload)
        self.username = username or os.getenv("CONAN_USERNAME", None)

        self.skip_check_credentials = skip_check_credentials or get_bool_from_env(
            "CONAN_SKIP_CHECK_CREDENTIALS")

        self.auth_manager = AuthManager(
            self.conan_api,
            self.printer,
            login_username,
            password,
            default_username=self.username,
            skip_check_credentials=self.skip_check_credentials)

        # Upload related variables
        self.upload_retry = upload_retry or os.getenv("CONAN_UPLOAD_RETRY", 3)

        if upload_only_when_stable is not None:
            self.upload_only_when_stable = upload_only_when_stable
        else:
            self.upload_only_when_stable = get_bool_from_env(
                "CONAN_UPLOAD_ONLY_WHEN_STABLE")

        if upload_only_when_tag is not None:
            self.upload_only_when_tag = upload_only_when_tag
        else:
            self.upload_only_when_tag = get_bool_from_env(
                "CONAN_UPLOAD_ONLY_WHEN_TAG")

        self.upload_only_recipe = upload_only_recipe or get_bool_from_env(
            "CONAN_UPLOAD_ONLY_RECIPE")

        self.remotes_manager.add_remotes_to_conan()
        self.uploader = Uploader(self.conan_api, self.remotes_manager,
                                 self.auth_manager, self.printer,
                                 self.upload_retry)

        self._builds = []
        self._named_builds = {}
        self._packages_summary = []

        self._update_conan_in_docker = always_update_conan_in_docker or get_bool_from_env(
            "CONAN_ALWAYS_UPDATE_CONAN_DOCKER")

        self._platform_info = platform_info or PlatformInfo()

        self.stable_branch_pattern = stable_branch_pattern or \
                                     os.getenv("CONAN_STABLE_BRANCH_PATTERN", None)

        self.stable_channel = stable_channel or os.getenv(
            "CONAN_STABLE_CHANNEL", "stable")
        self.stable_channel = self.stable_channel.rstrip()
        self.partial_reference = reference or os.getenv(
            "CONAN_REFERENCE", None)
        self.channel = self._get_specified_channel(channel, reference)
        self.conanfile = conanfile or os.getenv("CONAN_CONANFILE",
                                                "conanfile.py")

        if self.partial_reference:
            if "@" in self.partial_reference:
                self.reference = ConanFileReference.loads(
                    self.partial_reference)
            else:
                name, version = self.partial_reference.split("/")
                self.reference = ConanFileReference(name, version,
                                                    self.username,
                                                    self.channel)
        else:
            if not os.path.exists(os.path.join(self.cwd, self.conanfile)):
                raise Exception("Conanfile not found, specify a 'reference' "
                                "parameter with name and version")

            conanfile = load_cf_class(os.path.join(self.cwd, self.conanfile),
                                      self.conan_api)
            name, version = conanfile.name, conanfile.version
            if name and version:
                self.reference = ConanFileReference(name, version,
                                                    self.username,
                                                    self.channel)
            else:
                self.reference = None

        self._docker_image = docker_image or os.getenv("CONAN_DOCKER_IMAGE",
                                                       None)

        # If CONAN_DOCKER_IMAGE is specified, then use docker is True
        self.use_docker = (use_docker or os.getenv("CONAN_USE_DOCKER", False)
                           or self._docker_image is not None)

        self.docker_conan_home = docker_conan_home or os.getenv(
            "CONAN_DOCKER_HOME", None)

        os_name = self._platform_info.system(
        ) if not self.use_docker else "Linux"
        self.build_generator = BuildGenerator(
            reference, os_name, gcc_versions, apple_clang_versions,
            clang_versions, visual_versions, visual_runtimes, visual_toolsets,
            vs10_x86_64_enabled, mingw_configurations, archs, allow_gcc_minors,
            build_types, options, cppstds)

        self.build_policy = (build_policy
                             or self.ci_manager.get_commit_build_policy()
                             or split_colon_env("CONAN_BUILD_POLICY"))
        if isinstance(self.build_policy, list):
            self.build_policy = ",".join(self.build_policy)

        self.sudo_docker_command = ""
        if "CONAN_DOCKER_USE_SUDO" in os.environ:
            self.sudo_docker_command = "sudo -E" if get_bool_from_env(
                "CONAN_DOCKER_USE_SUDO") else ""
        elif platform.system() != "Windows":
            self.sudo_docker_command = "sudo -E"

        self.sudo_pip_command = ""
        if "CONAN_PIP_USE_SUDO" in os.environ:
            self.sudo_pip_command = "sudo -E" if get_bool_from_env(
                "CONAN_PIP_USE_SUDO") else ""
        elif platform.system(
        ) != "Windows" and self._docker_image and 'conanio/' not in str(
                self._docker_image):
            self.sudo_pip_command = "sudo -E"
        self.pip_command = os.getenv("CONAN_PIP_COMMAND", "pip")
        pip_found = True if tools.os_info.is_windows else tools.which(
            self.pip_command)
        if not pip_found or not "pip" in self.pip_command:
            raise Exception(
                "CONAN_PIP_COMMAND: '{}' is not a valid pip command.".format(
                    self.pip_command))
        self.docker_pip_command = os.getenv("CONAN_DOCKER_PIP_COMMAND", "pip")

        self.docker_shell = docker_shell or os.getenv("CONAN_DOCKER_SHELL")

        if self.is_wcow:
            if self.docker_conan_home is None:
                self.docker_conan_home = "C:/Users/ContainerAdministrator"
                self.docker_shell = docker_shell or "cmd /C"
        else:
            if self.docker_conan_home is None:
                self.docker_conan_home = "/home/conan"
                self.docker_shell = docker_shell or "/bin/sh -c"

        self.docker_platform_param = ""
        self.lcow_user_workaround = ""

        if self.is_lcow:
            self.docker_platform_param = "--platform=linux"
            # With LCOW, Docker doesn't respect USER directive in dockerfile yet
            self.lcow_user_workaround = "sudo su conan && "

        self.exclude_vcvars_precommand = exclude_vcvars_precommand or \
                                          get_bool_from_env("CONAN_EXCLUDE_VCVARS_PRECOMMAND")
        self._docker_image_skip_update = docker_image_skip_update or \
                                          get_bool_from_env("CONAN_DOCKER_IMAGE_SKIP_UPDATE")
        self._docker_image_skip_pull = docker_image_skip_pull or \
                                        get_bool_from_env("CONAN_DOCKER_IMAGE_SKIP_PULL")

        self.runner = runner or os.system
        self.output_runner = ConanOutputRunner()

        self.docker_run_options = docker_run_options or split_colon_env(
            "CONAN_DOCKER_RUN_OPTIONS")
        if isinstance(self.docker_run_options, list):
            self.docker_run_options = " ".join(self.docker_run_options)

        self.docker_entry_script = docker_entry_script or os.getenv(
            "CONAN_DOCKER_ENTRY_SCRIPT")

        self.pip_install = pip_install or split_colon_env("CONAN_PIP_INSTALL")

        self.upload_dependencies = upload_dependencies or split_colon_env(
            "CONAN_UPLOAD_DEPENDENCIES") or ""
        if isinstance(self.upload_dependencies, list):
            self.upload_dependencies = ",".join(self.upload_dependencies)
        if "all" in self.upload_dependencies and self.upload_dependencies != "all":
            raise Exception(
                "Upload dependencies only accepts or 'all' or package references. Do not mix both!"
            )

        self.update_dependencies = update_dependencies or get_bool_from_env(
            "CONAN_UPDATE_DEPENDENCIES")

        if self.channel:
            os.environ["CONAN_CHANNEL"] = self.channel

        if docker_32_images is not None:
            self.docker_32_images = docker_32_images
        else:
            self.docker_32_images = os.getenv("CONAN_DOCKER_32_IMAGES", False)

        self.force_selinux = force_selinux or get_bool_from_env(
            "CONAN_FORCE_SELINUX")
        self.curpage = curpage or os.getenv("CONAN_CURRENT_PAGE", 1)
        self.total_pages = total_pages or os.getenv("CONAN_TOTAL_PAGES", 1)

        self.conan_pip_package = os.getenv("CONAN_PIP_PACKAGE",
                                           "conan==%s" % conan_version)
        if self.conan_pip_package in ("0", "False"):
            self.conan_pip_package = ""
        self.vs10_x86_64_enabled = vs10_x86_64_enabled

        self.builds_in_current_page = []

        self.test_folder = test_folder or os.getenv("CPT_TEST_FOLDER")

        self.config_url = config_url or os.getenv("CONAN_CONFIG_URL")

        self.skip_recipe_export = skip_recipe_export or \
                                     get_bool_from_env("CONAN_SKIP_RECIPE_EXPORT")
        self.config_args = config_args or os.getenv("CONAN_CONFIG_ARGS")

        self.lockfile = lockfile or os.getenv("CONAN_LOCKFILE")

        def valid_pair(var, value):
            return (isinstance(value, six.string_types)
                    or isinstance(value, bool) or isinstance(value, list)
                    ) and not var.startswith("_") and "password" not in var

        with self.printer.foldable_output("local_vars"):
            self.printer.print_dict({
                var: value
                for var, value in self.__dict__.items()
                if valid_pair(var, value)
            })

        self._newest_supported_conan_version = Version(
            NEWEST_CONAN_SUPPORTED).minor(fill=False)
        self._client_conan_version = conan_version
コード例 #10
0
ファイル: packager.py プロジェクト: ZCube/conan-package-tools
    def __init__(self,
                 args=None,
                 username=None,
                 channel=None,
                 runner=None,
                 gcc_versions=None,
                 visual_versions=None,
                 visual_runtimes=None,
                 apple_clang_versions=None,
                 archs=None,
                 use_docker=None,
                 curpage=None,
                 total_pages=None,
                 docker_image=None,
                 reference=None,
                 password=None,
                 remotes=None,
                 upload=None,
                 stable_branch_pattern=None,
                 vs10_x86_64_enabled=False,
                 mingw_configurations=None,
                 stable_channel=None,
                 platform_info=None,
                 upload_retry=None,
                 clang_versions=None,
                 login_username=None,
                 upload_only_when_stable=None,
                 build_types=None,
                 skip_check_credentials=False,
                 allow_gcc_minors=False,
                 exclude_vcvars_precommand=False,
                 docker_image_skip_update=False,
                 docker_image_skip_pull=False,
                 docker_entry_script=None,
                 docker_32_images=None,
                 build_policy=None,
                 always_update_conan_in_docker=False,
                 conan_api=None,
                 client_cache=None,
                 ci_manager=None,
                 out=None,
                 test_folder=None):

        self.printer = Printer(out)
        self.printer.print_rule()
        self.printer.print_ascci_art()

        if not conan_api:
            self.conan_api, self.client_cache, _ = Conan.factory()
        else:
            self.conan_api = conan_api
            self.client_cache = client_cache

        self.ci_manager = ci_manager or CIManager(self.printer)
        self.remotes_manager = RemotesManager(self.conan_api, self.printer,
                                              remotes, upload)
        self.username = username or os.getenv("CONAN_USERNAME", None)

        if not self.username:
            raise Exception(
                "Instance ConanMultiPackage with 'username' parameter or use "
                "CONAN_USERNAME env variable")
        self.skip_check_credentials = skip_check_credentials or \
                                      os.getenv("CONAN_SKIP_CHECK_CREDENTIALS", False)

        self.auth_manager = AuthManager(
            self.conan_api,
            self.printer,
            login_username,
            password,
            default_username=self.username,
            skip_check_credentials=self.skip_check_credentials)
        self.uploader = Uploader(self.conan_api, self.remotes_manager,
                                 self.auth_manager, self.printer)

        self._builds = []
        self._named_builds = {}

        self._update_conan_in_docker = (
            always_update_conan_in_docker
            or os.getenv("CONAN_ALWAYS_UPDATE_CONAN_DOCKER", False))

        self._platform_info = platform_info or PlatformInfo()

        self.stable_branch_pattern = stable_branch_pattern or \
                                     os.getenv("CONAN_STABLE_BRANCH_PATTERN", None)
        self.specified_channel = channel or os.getenv("CONAN_CHANNEL",
                                                      "testing")
        self.specified_channel = self.specified_channel.rstrip()
        self.stable_channel = stable_channel or os.getenv(
            "CONAN_STABLE_CHANNEL", "stable")
        self.stable_channel = self.stable_channel.rstrip()
        self.channel = self._get_channel(self.specified_channel,
                                         self.stable_channel)
        self.partial_reference = reference or os.getenv(
            "CONAN_REFERENCE", None)

        if self.partial_reference:
            if "@" in self.partial_reference:
                self.reference = ConanFileReference.loads(
                    self.partial_reference)
            else:
                name, version = self.partial_reference.split("/")
                self.reference = ConanFileReference(name, version,
                                                    self.username,
                                                    self.channel)
        else:
            if not os.path.exists("conanfile.py"):
                raise Exception(
                    "Conanfile not found, specify a 'reference' parameter with name and version"
                )
            conanfile = load_conanfile_class("./conanfile.py")
            name, version = conanfile.name, conanfile.version
            if name and version:
                self.reference = ConanFileReference(name, version,
                                                    self.username,
                                                    self.channel)
            else:
                self.reference = None

        # If CONAN_DOCKER_IMAGE is speified, then use docker is True
        self.use_docker = (use_docker or os.getenv("CONAN_USE_DOCKER", False)
                           or os.getenv("CONAN_DOCKER_IMAGE",
                                        None) is not None)

        os_name = self._platform_info.system(
        ) if not self.use_docker else "Linux"
        self.build_generator = BuildGenerator(
            reference, os_name, gcc_versions, apple_clang_versions,
            clang_versions, visual_versions, visual_runtimes,
            vs10_x86_64_enabled, mingw_configurations, archs, allow_gcc_minors,
            build_types)

        build_policy = (build_policy
                        or self.ci_manager.get_commit_build_policy()
                        or os.getenv("CONAN_BUILD_POLICY", None))

        if build_policy:
            if build_policy.lower() not in ("never", "outdated", "missing"):
                raise Exception(
                    "Invalid build policy, valid values: never, outdated, missing"
                )

        self.build_policy = build_policy

        self.sudo_docker_command = ""
        if "CONAN_DOCKER_USE_SUDO" in os.environ:
            self.sudo_docker_command = "sudo -E" if get_bool_from_env(
                "CONAN_DOCKER_USE_SUDO") else ""
        elif platform.system() != "Windows":
            self.sudo_docker_command = "sudo -E"

        self.sudo_pip_command = ""
        if "CONAN_PIP_USE_SUDO" in os.environ:
            self.sudo_pip_command = "sudo -E" if get_bool_from_env(
                "CONAN_PIP_USE_SUDO") else ""
        elif platform.system() != "Windows":
            self.sudo_pip_command = "sudo -E"

        self.docker_shell = ""
        self.docker_conan_home = ""

        if self.is_wcow:
            self.docker_conan_home = "C:/Users/ContainerAdministrator"
            self.docker_shell = "cmd /C"
        else:
            self.docker_conan_home = "/home/conan"
            self.docker_shell = "/bin/sh -c"

        self.docker_platform_param = ""
        self.lcow_user_workaround = ""

        if self.is_lcow:
            self.docker_platform_param = "--platform=linux"
            # With LCOW, Docker doesn't respect USER directive in dockerfile yet
            self.lcow_user_workaround = "sudo su conan && "

        self.exclude_vcvars_precommand = (
            exclude_vcvars_precommand
            or os.getenv("CONAN_EXCLUDE_VCVARS_PRECOMMAND", False))
        self._docker_image_skip_update = (
            docker_image_skip_update
            or os.getenv("CONAN_DOCKER_IMAGE_SKIP_UPDATE", False))
        self._docker_image_skip_pull = (docker_image_skip_pull or os.getenv(
            "CONAN_DOCKER_IMAGE_SKIP_PULL", False))

        self.runner = runner or os.system
        self.output_runner = ConanOutputRunner()
        self.args = " ".join(args) if args else " ".join(sys.argv[1:])

        # Upload related variables
        self.upload_retry = upload_retry or os.getenv("CONAN_UPLOAD_RETRY", 3)

        if upload_only_when_stable is not None:
            self.upload_only_when_stable = upload_only_when_stable
        else:
            self.upload_only_when_stable = get_bool_from_env(
                "CONAN_UPLOAD_ONLY_WHEN_STABLE")

        self.docker_entry_script = docker_entry_script or os.getenv(
            "CONAN_DOCKER_ENTRY_SCRIPT")

        os.environ["CONAN_CHANNEL"] = self.channel

        # If CONAN_DOCKER_IMAGE is speified, then use docker is True
        self.use_docker = use_docker or os.getenv("CONAN_USE_DOCKER", False) or \
                          (os.getenv("CONAN_DOCKER_IMAGE", None) is not None)

        if docker_32_images is not None:
            self.docker_32_images = docker_32_images
        else:
            self.docker_32_images = os.getenv("CONAN_DOCKER_32_IMAGES", False)

        self.curpage = curpage or os.getenv("CONAN_CURRENT_PAGE", 1)
        self.total_pages = total_pages or os.getenv("CONAN_TOTAL_PAGES", 1)
        self._docker_image = docker_image or os.getenv("CONAN_DOCKER_IMAGE",
                                                       None)

        self.conan_pip_package = os.getenv("CONAN_PIP_PACKAGE",
                                           "conan==%s" % client_version)
        if self.conan_pip_package in ("0", "False"):
            self.conan_pip_package = False
        self.vs10_x86_64_enabled = vs10_x86_64_enabled

        self.builds_in_current_page = []

        self.test_folder = test_folder or os.getenv("CPT_TEST_FOLDER", None)

        def valid_pair(var, value):
            return (isinstance(value, six.string_types)
                    or isinstance(value, bool) or isinstance(value, list)
                    ) and not var.startswith("_") and "password" not in var

        with self.printer.foldable_output("local_vars"):
            self.printer.print_dict({
                var: value
                for var, value in self.__dict__.items()
                if valid_pair(var, value)
            })
コード例 #11
0
 def no_credentials_test(self):
     manager = AuthManager(self.conan_api, self.printer)
     user, password = manager.get_user_password()
     self.assertEquals(user, None)
     self.assertEquals(password, None)