Exemple #1
0
 def reject_removal_test(self):
     mocked_user_io = UserIO(out=TestBufferConanOutput())
     mocked_user_io.request_boolean = Mock(return_value=False)
     self.client.run("remove hello/* -s -b -p", user_io=mocked_user_io)
     self.assert_folders(local_folders={
         "H1": [1, 2],
         "H2": [1, 2],
         "B": [1, 2],
         "O": [1, 2]
     },
                         remote_folders={
                             "H1": [1, 2],
                             "H2": [1, 2],
                             "B": [1, 2],
                             "O": [1, 2]
                         },
                         build_folders={
                             "H1": [1, 2],
                             "H2": [1, 2],
                             "B": [1, 2],
                             "O": [1, 2]
                         },
                         src_folders={
                             "H1": True,
                             "H2": True,
                             "B": True,
                             "O": True
                         })
Exemple #2
0
 def basic_mocked_test(self):
     mocked_user_io = UserIO(out=TestBufferConanOutput())
     mocked_user_io.request_boolean = Mock(return_value=True)
     self.client.run("remove hello/*", user_io=mocked_user_io)
     self.assert_folders(local_folders={
         "H1": None,
         "H2": None,
         "B": [1, 2],
         "O": [1, 2]
     },
                         remote_folders={
                             "H1": [1, 2],
                             "H2": [1, 2],
                             "B": [1, 2],
                             "O": [1, 2]
                         },
                         build_folders={
                             "H1": None,
                             "H2": None,
                             "B": [1, 2],
                             "O": [1, 2]
                         },
                         src_folders={
                             "H1": False,
                             "H2": False,
                             "B": True,
                             "O": True
                         })
     folders = os.listdir(self.client.storage_folder)
     six.assertCountEqual(self, ["Other", "Bye"], folders)
Exemple #3
0
    def setUpClass(cls):
        if not cls.server:
            cls.server = TestServerLauncher(
                server_capabilities=['ImCool', 'TooCool'])
            cls.server.start()

            filename = os.path.join(temp_folder(), "conan.conf")
            save(filename, "")
            config = ConanClientConfigParser(filename)
            requester = ConanRequester(config, requests)
            client_factory = RestApiClientFactory(TestBufferConanOutput(),
                                                  requester=requester,
                                                  config=config)
            localdb = LocalDBMock()

            mocked_user_io = UserIO(out=TestBufferConanOutput())
            mocked_user_io.get_username = Mock(return_value="private_user")
            mocked_user_io.get_password = Mock(return_value="private_pass")

            cls.auth_manager = ConanApiAuthManager(client_factory,
                                                   mocked_user_io, localdb)
            cls.remote = Remote("myremote",
                                "http://127.0.0.1:%s" % str(cls.server.port),
                                True, True)
            cls.auth_manager._authenticate(cls.remote,
                                           user="******",
                                           password="******")
            cls.api = client_factory.new(cls.remote, localdb.access_token,
                                         localdb.refresh_token, {})
Exemple #4
0
 def __init__(self, logins, ins=sys.stdin, out=None):
     """
     logins is a list of (user, password)==> [("lasote", "mypass"), ("other", "otherpass")]
     will return sequentially
     """
     self.logins = logins
     self.login_index = 0
     UserIO.__init__(self, ins, out)
Exemple #5
0
 def reject_removal_test(self):
     mocked_user_io = UserIO(out=TestBufferConanOutput())
     mocked_user_io.request_boolean = Mock(return_value=False)
     self.client.run("remove hello/* -s -b -p", user_io=mocked_user_io)
     self.assert_folders({"H1": [1, 2], "H2": [1, 2], "B": [1, 2], "O": [1, 2]},
                         {"H1": [1, 2], "H2": [1, 2], "B": [1, 2], "O": [1, 2]},
                         {"H1": [1, 2], "H2": [1, 2], "B": [1, 2], "O": [1, 2]},
                         {"H1": True, "H2": True, "B": True, "O": True})
Exemple #6
0
 def basic_mocked_test(self):
     mocked_user_io = UserIO(out=TestBufferConanOutput())
     mocked_user_io.request_boolean = Mock(return_value=True)
     self.client.run("remove hello/*", user_io=mocked_user_io)
     self.assert_folders({"H1": None, "H2": None, "B": [1, 2], "O": [1, 2]},
                         {"H1": [1, 2], "H2": [1, 2], "B": [1, 2], "O": [1, 2]},
                         {"H1": None, "H2": None, "B": [1, 2], "O": [1, 2]},
                         {"H1": False, "H2": False, "B": True, "O": True})
Exemple #7
0
 def __init__(self, logins, ins=sys.stdin, out=None):
     """
     logins is a list of (user, password)==> [("lasote", "mypass"), ("other", "otherpass")]
     will return sequentially
     """
     self.logins = logins
     self.login_index = 0
     UserIO.__init__(self, ins, out)
Exemple #8
0
 def __init__(self, logins, ins=sys.stdin, out=None):
     """
     logins is a dict of {remote: list(user, password)}
     will return sequentially
     """
     assert isinstance(logins, dict)
     self.logins = logins
     self.login_index = Counter()
     UserIO.__init__(self, ins, out)
Exemple #9
0
 def __init__(self, logins, ins=sys.stdin, out=None):
     """
     logins is a dict of {remote: list(user, password)}
     will return sequentially
     """
     assert isinstance(logins, dict)
     self.logins = logins
     self.login_index = Counter()
     UserIO.__init__(self, ins, out)
Exemple #10
0
 def basic_mocked_test(self):
     mocked_user_io = UserIO(out=TestBufferConanOutput())
     mocked_user_io.request_boolean = Mock(return_value=True)
     self.client.run("remove hello/*", user_io=mocked_user_io)
     self.assert_folders(
         {"H1": None, "H2": None, "B": [1, 2], "O": [1, 2]},
         {"H1": [1, 2], "H2": [1, 2], "B": [1, 2], "O": [1, 2]},
         {"H1": None, "H2": None, "B": [1, 2], "O": [1, 2]},
         {"H1": False, "H2": False, "B": True, "O": True},
     )
Exemple #11
0
 def basic_mocked_test(self):
     mocked_user_io = UserIO(out=TestBufferConanOutput())
     mocked_user_io.request_boolean = Mock(return_value=True)
     self.client.run("remove hello/*", user_io=mocked_user_io)
     self.assert_folders({"H1": None, "H2": None, "B": [1, 2], "O": [1, 2]},
                         {"H1": [1, 2], "H2": [1, 2], "B": [1, 2], "O": [1, 2]},
                         {"H1": None, "H2": None, "B": [1, 2], "O": [1, 2]},
                         {"H1": False, "H2": False, "B": True, "O": True})
     folders = os.listdir(self.client.storage_folder)
     six.assertCountEqual(self, ["Other", "Bye"], folders)
Exemple #12
0
    def test_request_login(self, m1, m2):
        user_io = UserIO()

        # Use mocked ones
        u, p = user_io.request_login(remote_name="lol")
        self.assertEqual(u, "username")
        self.assertEqual(p, "passwd")

        # Use from argument
        username = "******"
        u, p = user_io.request_login(remote_name="lol", username=username)
        self.assertEqual(u, username)
        self.assertEqual(p, "passwd")
    def setUp(self):
        mocked_user_io = UserIO(out=TestBufferConanOutput())
        mocked_user_io.get_username = Mock(return_value="myuser")
        mocked_user_io.get_password = Mock(return_value="mypassword")

        requester = RequesterWithTokenMock()
        config = namedtuple("ConfigMock", "revisions_enabled download_cache")(False, None)
        self.rest_client_factory = RestApiClientFactory(mocked_user_io.out,
                                                        requester, config=config,
                                                        artifacts_properties=None)
        self.localdb = LocalDBMock()
        self.auth_manager = ConanApiAuthManager(self.rest_client_factory, mocked_user_io,
                                                self.localdb)
        self.remote = Remote("myremote", "myurl", True, True)
        self.ref = ConanFileReference.loads("lib/1.0@conan/stable")
Exemple #14
0
    def setUp(self):
        mocked_user_io = UserIO(out=TestBufferConanOutput())
        mocked_user_io.get_username = Mock(return_value="myuser")
        mocked_user_io.get_password = Mock(return_value="mypassword")

        requester = RequesterWithTokenMock()
        self.rest_client = RestApiClient(mocked_user_io.out,
                                         requester,
                                         revisions_enabled=False,
                                         put_headers=None)
        self.localdb = LocalDBMock()
        self.auth_manager = ConanApiAuthManager(self.rest_client,
                                                mocked_user_io, self.localdb)
        self.auth_manager.remote = Remote("myremote", "myurl", True, True)
        self.auth_manager.user = None
Exemple #15
0
 def src_test(self):
     mocked_user_io = UserIO(out=TestBufferConanOutput())
     mocked_user_io.request_boolean = Mock(return_value=True)
     self.client.run("remove hello/* -s", user_io=mocked_user_io)
     self.assert_folders({"H1": [1, 2], "H2": [1, 2], "B": [1, 2], "O": [1, 2]},
                         {"H1": [1, 2], "H2": [1, 2], "B": [1, 2], "O": [1, 2]},
                         {"H1": [1, 2], "H2": [1, 2], "B": [1, 2], "O": [1, 2]},
                         {"H1": False, "H2": False, "B": True, "O": True})
     folders = os.listdir(self.client.storage_folder)
     six.assertCountEqual(self, ["Hello", "Other", "Bye"], folders)
     six.assertCountEqual(self, ["package", "build", "export"],
                           os.listdir(os.path.join(self.client.storage_folder,
                                                   "Hello/1.4.10/fenix/testing")))
     six.assertCountEqual(self, ["package", "build", "export"],
                           os.listdir(os.path.join(self.client.storage_folder,
                                                   "Hello/2.4.11/fenix/testing")))
Exemple #16
0
 def builds_test(self):
     mocked_user_io = UserIO(out=TestBufferConanOutput())
     mocked_user_io.request_boolean = Mock(return_value=True)
     self.client.run("remove hello/* -b", user_io=mocked_user_io)
     self.assert_folders(local_folders={
         "H1": [1, 2],
         "H2": [1, 2],
         "B": [1, 2],
         "O": [1, 2]
     },
                         remote_folders={
                             "H1": [1, 2],
                             "H2": [1, 2],
                             "B": [1, 2],
                             "O": [1, 2]
                         },
                         build_folders={
                             "H1": [],
                             "H2": [],
                             "B": [1, 2],
                             "O": [1, 2]
                         },
                         src_folders={
                             "H1": True,
                             "H2": True,
                             "B": True,
                             "O": True
                         })
     folders = os.listdir(self.client.storage_folder)
     six.assertCountEqual(self, ["Hello", "Other", "Bye"], folders)
     six.assertCountEqual(
         self, [
             "package", "source", "export", "export_source",
             "metadata.json", "metadata.json.lock"
         ],
         os.listdir(
             os.path.join(self.client.storage_folder,
                          "Hello/1.4.10/myuser/testing")))
     six.assertCountEqual(
         self, [
             "package", "source", "export", "export_source",
             "metadata.json", "metadata.json.lock"
         ],
         os.listdir(
             os.path.join(self.client.storage_folder,
                          "Hello/2.4.11/myuser/testing")))
Exemple #17
0
def get_command():
    def instance_remote_manager(client_cache):
        requester = requests.Session()
        requester.proxies = client_cache.conan_config.proxies
        # Verify client version against remotes
        version_checker_requester = VersionCheckerRequester(
            requester, Version(CLIENT_VERSION),
            Version(MIN_SERVER_COMPATIBLE_VERSION), out)
        # To handle remote connections
        rest_api_client = RestApiClient(out,
                                        requester=version_checker_requester)
        # To store user and token
        localdb = LocalDB(client_cache.localdb)
        # Wraps RestApiClient to add authentication support (same interface)
        auth_manager = ConanApiAuthManager(rest_api_client, user_io, localdb)
        # Handle remote connections
        remote_manager = RemoteManager(client_cache, auth_manager, out)
        return remote_manager

    use_color = get_env("CONAN_COLOR_DISPLAY", 1)
    if use_color and hasattr(sys.stdout, "isatty") and sys.stdout.isatty():
        import colorama
        colorama.init()
        color = True
    else:
        color = False
    out = ConanOutput(sys.stdout, color)
    user_io = UserIO(out=out)

    user_folder = os.getenv("CONAN_USER_HOME", conan_expand_user("~"))

    try:
        # To capture exceptions in conan.conf parsing
        client_cache = ClientCache(user_folder, None, out)
        # obtain a temp ConanManager instance to execute the migrations
        remote_manager = instance_remote_manager(client_cache)

        # Get a DiskSearchManager
        search_adapter = DiskSearchAdapter()
        search_manager = DiskSearchManager(client_cache, search_adapter)
        manager = ConanManager(client_cache, user_io, ConanRunner(),
                               remote_manager, search_manager)

        client_cache = migrate_and_get_client_cache(user_folder, out, manager)
    except Exception as e:
        out.error(str(e))
        sys.exit(True)

    # Get the new command instance after migrations have been done
    remote_manager = instance_remote_manager(client_cache)

    # Get a search manager
    search_adapter = DiskSearchAdapter()
    search_manager = DiskSearchManager(client_cache, search_adapter)
    command = Command(client_cache, user_io, ConanRunner(), remote_manager,
                      search_manager)
    return command
Exemple #18
0
    def factory():
        """Factory"""
        def instance_remote_manager(client_cache):
            requester = get_basic_requester(client_cache)
            # Verify client version against remotes
            version_checker_req = VersionCheckerRequester(
                requester, Version(client_version),
                Version(MIN_SERVER_COMPATIBLE_VERSION), out)
            # To handle remote connections
            put_headers = client_cache.read_put_headers()
            rest_api_client = RestApiClient(out,
                                            requester=version_checker_req,
                                            put_headers=put_headers)
            # To store user and token
            localdb = LocalDB(client_cache.localdb)
            # Wraps RestApiClient to add authentication support (same interface)
            auth_manager = ConanApiAuthManager(rest_api_client, user_io,
                                               localdb)
            # Handle remote connections
            remote_manager = RemoteManager(client_cache, auth_manager, out)
            return remote_manager

        use_color = get_env("CONAN_COLOR_DISPLAY", 1)
        if use_color and hasattr(sys.stdout, "isatty") and sys.stdout.isatty():
            import colorama
            colorama.init()
            color = True
        else:
            color = False
        out = ConanOutput(sys.stdout, color)
        user_io = UserIO(out=out)

        try:
            client_cache = migrate_and_get_client_cache(
                get_conan_user_home(), out)
        except Exception as e:
            out.error(str(e))
            raise

        with tools.environment_append(client_cache.conan_config.env_vars):
            # Adjust CONAN_LOGGING_LEVEL with the env readed
            conans.util.log.logger = configure_logger()

            # Get the new command instance after migrations have been done
            remote_manager = instance_remote_manager(client_cache)

            # Get a search manager
            search_adapter = DiskSearchAdapter()
            search_manager = DiskSearchManager(client_cache, search_adapter)

            # Settings preprocessor
            conan = Conan(client_cache, user_io, get_conan_runner(),
                          remote_manager, search_manager,
                          settings_preprocessor)

        return conan, client_cache, user_io
Exemple #19
0
 def __init__(self, cache_folder=None, quiet=True, user_io=None, http_requester=None,
              runner=None):
     self.out = ConanOutput(quiet=quiet)
     self.user_io = user_io or UserIO(out=self.out)
     self.cache_folder = cache_folder or os.path.join(get_conan_user_home(), ".conan")
     self.http_requester = http_requester
     self.runner = runner
     # Migration system
     migrator = ClientMigrator(self.cache_folder, Version(client_version), self.out)
     migrator.migrate()
Exemple #20
0
    def factory(interactive=None):
        """Factory"""
        # Respect color env setting or check tty if unset
        color_set = "CONAN_COLOR_DISPLAY" in os.environ
        if ((color_set and get_env("CONAN_COLOR_DISPLAY", 1))
                or (not color_set
                    and hasattr(sys.stdout, "isatty")
                    and sys.stdout.isatty())):
            import colorama
            if get_env("PYCHARM_HOSTED"):  # in PyCharm disable convert/strip
                colorama.init(convert=False, strip=False)
            else:
                colorama.init()
            color = True
        else:
            color = False
        out = ConanOutput(sys.stdout, color)
        user_io = UserIO(out=out)

        try:
            user_home = get_conan_user_home()
            client_cache = migrate_and_get_client_cache(user_home, out)
            sys.path.append(os.path.join(user_home, "python"))
        except Exception as e:
            out.error(str(e))
            raise

        with tools.environment_append(client_cache.conan_config.env_vars):
            # Adjust CONAN_LOGGING_LEVEL with the env readed
            conans.util.log.logger = configure_logger()

            # Create Plugin Manager
            plugin_manager = PluginManager(client_cache.plugins_path,
                                           get_env("CONAN_PLUGINS", list()), user_io.out)

            # Get the new command instance after migrations have been done
            requester = get_basic_requester(client_cache)
            _, _, remote_manager = ConanAPIV1.instance_remote_manager(
                requester,
                client_cache, user_io,
                Version(client_version),
                Version(MIN_SERVER_COMPATIBLE_VERSION),
                plugin_manager)

            # Adjust global tool variables
            set_global_instances(out, requester)

            # Settings preprocessor
            if interactive is None:
                interactive = not get_env("CONAN_NON_INTERACTIVE", False)
            conan = ConanAPIV1(client_cache, user_io, get_conan_runner(), remote_manager,
                               plugin_manager, interactive=interactive)

        return conan, client_cache, user_io
Exemple #21
0
    def factory(interactive=None):
        """Factory"""

        use_color = get_env("CONAN_COLOR_DISPLAY", 1)
        if use_color and hasattr(sys.stdout, "isatty") and sys.stdout.isatty():
            import colorama
            colorama.init()
            color = True
        else:
            color = False
        out = ConanOutput(sys.stdout, color)
        user_io = UserIO(out=out)

        try:
            user_home = get_conan_user_home()
            client_cache = migrate_and_get_client_cache(user_home, out)
            sys.path.append(os.path.join(user_home, "python"))
        except Exception as e:
            out.error(str(e))
            raise

        with tools.environment_append(client_cache.conan_config.env_vars):
            # Adjust CONAN_LOGGING_LEVEL with the env readed
            conans.util.log.logger = configure_logger()

            # Get the new command instance after migrations have been done
            requester = get_basic_requester(client_cache)
            _, _, remote_manager = ConanAPIV1.instance_remote_manager(
                                                requester,
                                                client_cache, user_io,
                                                Version(client_version),
                                                Version(MIN_SERVER_COMPATIBLE_VERSION))

            # Adjust global tool variables
            set_global_instances(out, requester)

            # Get a search manager
            search_manager = DiskSearchManager(client_cache)

            # Settings preprocessor
            if interactive is None:
                interactive = not get_env("CONAN_NON_INTERACTIVE", False)
            conan = Conan(client_cache, user_io, get_conan_runner(), remote_manager, search_manager,
                          settings_preprocessor, interactive=interactive)

        return conan, client_cache, user_io
Exemple #22
0
def main(args):
    """ main entry point of the conans application, using a Command to
    parse parameters
    """
    if hasattr(sys.stdout, "isatty") and sys.stdout.isatty():
        import colorama
        colorama.init()
        color = True
    else:
        color = False
    out = ConanOutput(sys.stdout, color)
    user_io = UserIO(out=out)

    user_folder = os.path.expanduser("~")
    paths = migrate_and_get_paths(user_folder, out)

    # Verify client version against remotes
    version_checker_requester = VersionCheckerRequester(
        requests, Version(CLIENT_VERSION),
        Version(MIN_SERVER_COMPATIBLE_VERSION), out)
    # To handle remote connections
    rest_api_client = RestApiClient(out, requester=version_checker_requester)
    # To store user and token
    localdb = LocalDB(paths.localdb)
    # Wraps RestApiClient to add authentication support (same interface)
    auth_manager = ConanApiAuthManager(rest_api_client, user_io, localdb)
    # Handle remote connections
    remote_manager = RemoteManager(paths, paths.conan_config.remotes,
                                   auth_manager, out)

    command = Command(paths, user_io, os.system, remote_manager, localdb)
    current_dir = os.getcwd()
    try:
        import signal

        def sigint_handler(signal, frame):
            print('You pressed Ctrl+C!')
            sys.exit(0)

        signal.signal(signal.SIGINT, sigint_handler)
        error = command.run(args)
    finally:
        os.chdir(current_dir)
    sys.exit(error)
Exemple #23
0
 def __init__(self, answer, ins=sys.stdin, out=None):
     self.answer = answer
     UserIO.__init__(self, ins, out)
 def __init__(self, answer, ins=sys.stdin, out=None):
     self.answer = answer
     UserIO.__init__(self, ins, out)