def test_recursive_path_option_exclude_absolute(self, oswalk_mock):
        """
        Test paths returned by the recursive processing when using absolute
        excludes.

        testing paths
            /jjb_configs/dir1/test1/
            /jjb_configs/dir1/file
            /jjb_configs/dir2/test2/
            /jjb_configs/dir3/bar/
            /jjb_configs/test3/bar/
            /jjb_configs/test3/baz/
        """

        os_walk_paths = [
            ('/jjb_configs', (['dir1', 'dir2', 'dir3', 'test3'], ())),
            ('/jjb_configs/dir1', None),
            ('/jjb_configs/dir2', (['test2'], ())),
            ('/jjb_configs/dir3', (['bar'], ())),
            ('/jjb_configs/test3', (['bar', 'baz'], ())),
            ('/jjb_configs/dir2/test2', ([], ())),
            ('/jjb_configs/dir3/bar', ([], ())),
            ('/jjb_configs/test3/bar', ([], ())),
            ('/jjb_configs/test3/baz', ([], ()))
        ]

        paths = [k for k, v in os_walk_paths if v is not None]

        oswalk_mock.side_effect = fake_os_walk(os_walk_paths)

        self.assertEqual(paths, utils.recurse_path('/jjb_configs',
                                                   ['/jjb_configs/dir1']))
Exemplo n.º 2
0
    def test_recursive_path_option_exclude_absolute(self, oswalk_mock):
        """
        Test paths returned by the recursive processing when using absolute
        excludes.

        testing paths
            /jjb_configs/dir1/test1/
            /jjb_configs/dir1/file
            /jjb_configs/dir2/test2/
            /jjb_configs/dir3/bar/
            /jjb_configs/test3/bar/
            /jjb_configs/test3/baz/
        """

        os_walk_paths = [
            ("/jjb_configs", (["dir1", "dir2", "dir3", "test3"], ())),
            ("/jjb_configs/dir1", None),
            ("/jjb_configs/dir2", (["test2"], ())),
            ("/jjb_configs/dir3", (["bar"], ())),
            ("/jjb_configs/test3", (["bar", "baz"], ())),
            ("/jjb_configs/dir2/test2", ([], ())),
            ("/jjb_configs/dir3/bar", ([], ())),
            ("/jjb_configs/test3/bar", ([], ())),
            ("/jjb_configs/test3/baz", ([], ())),
        ]

        paths = [k for k, v in os_walk_paths if v is not None]

        oswalk_mock.side_effect = fake_os_walk(os_walk_paths)

        self.assertEqual(
            paths, utils.recurse_path("/jjb_configs", ["/jjb_configs/dir1"]))
Exemplo n.º 3
0
    def _parse_additional(self):

        self._set_config(self.jjb_config.builder, "ignore_cache")
        self._set_config(self.jjb_config.builder, "flush_cache")
        self._set_config(self.jjb_config.builder, "update")
        self._set_config(self.jjb_config.yamlparser, "allow_empty_variables")
        self._set_config(self.jjb_config.jenkins, "section")
        self._set_config(self.jjb_config.jenkins, "user")
        self._set_config(self.jjb_config.jenkins, "password")

        # Note: CLI options override config file options.
        if getattr(self.options, "update", None) is None:
            self.options.update = self.jjb_config.builder.get("update")
            if self.options.update is None:
                self.options.update = "all"

        if getattr(self.options, "plugins_info_path", None) is not None:
            with io.open(self.options.plugins_info_path, "r",
                         encoding="utf-8") as yaml_file:
                plugins_info = yaml.load(yaml_file)
            if not isinstance(plugins_info, list):
                self.parser.error("{0} must contain a Yaml list!".format(
                    self.options.plugins_info_path))
            self.jjb_config.builder["plugins_info"] = plugins_info

        if getattr(self.options, "path", None):
            if hasattr(self.options.path, "read"):
                logger.debug("Input file is stdin")
                if self.options.path.isatty():
                    if platform.system() == "Windows":
                        key = "CTRL+Z"
                    else:
                        key = "CTRL+D"
                    logger.warning(
                        "Reading configuration from STDIN. "
                        "Press %s to end input.",
                        key,
                    )
                self.options.path = [self.options.path]
            else:
                # take list of paths
                self.options.path = self.options.path.split(os.pathsep)

                do_recurse = (getattr(self.options, "recursive", False)
                              or self.jjb_config.recursive)

                excludes = [
                    e for elist in self.options.exclude
                    for e in elist.split(os.pathsep)
                ] or self.jjb_config.excludes
                paths = []
                for path in self.options.path:
                    if do_recurse and os.path.isdir(path):
                        paths.extend(utils.recurse_path(path, excludes))
                    else:
                        paths.append(path)
                self.options.path = paths
Exemplo n.º 4
0
    def _parse_additional(self):

        self._set_config(self.jjb_config.builder, 'ignore_cache')
        self._set_config(self.jjb_config.builder, 'flush_cache')
        self._set_config(self.jjb_config.builder, 'update')
        self._set_config(self.jjb_config.yamlparser, 'allow_empty_variables')
        self._set_config(self.jjb_config.jenkins, 'section')
        self._set_config(self.jjb_config.jenkins, 'user')
        self._set_config(self.jjb_config.jenkins, 'password')

        # Note: CLI options override config file options.
        if getattr(self.options, 'update', None) is None:
            self.options.update = self.jjb_config.builder.get('update')
            if self.options.update is None:
                self.options.update = 'all'

        if getattr(self.options, 'plugins_info_path', None) is not None:
            with io.open(self.options.plugins_info_path, 'r',
                         encoding='utf-8') as yaml_file:
                plugins_info = yaml.load(yaml_file)
            if not isinstance(plugins_info, list):
                self.parser.error("{0} must contain a Yaml list!".format(
                    self.options.plugins_info_path))
            self.jjb_config.builder['plugins_info'] = plugins_info

        if getattr(self.options, 'path', None):
            if hasattr(self.options.path, 'read'):
                logger.debug("Input file is stdin")
                if self.options.path.isatty():
                    if platform.system() == 'Windows':
                        key = 'CTRL+Z'
                    else:
                        key = 'CTRL+D'
                    logger.warning(
                        "Reading configuration from STDIN. "
                        "Press %s to end input.", key)
                self.options.path = [self.options.path]
            else:
                # take list of paths
                self.options.path = self.options.path.split(os.pathsep)

                do_recurse = (getattr(self.options, 'recursive', False)
                              or self.jjb_config.recursive)

                excludes = ([
                    e for elist in self.options.exclude
                    for e in elist.split(os.pathsep)
                ] or self.jjb_config.excludes)
                paths = []
                for path in self.options.path:
                    if do_recurse and os.path.isdir(path):
                        paths.extend(utils.recurse_path(path, excludes))
                    else:
                        paths.append(path)
                self.options.path = paths
Exemplo n.º 5
0
    def _parse_additional(self):

        self._set_config(self.jjb_config.builder, 'ignore_cache')
        self._set_config(self.jjb_config.builder, 'flush_cache')
        self._set_config(self.jjb_config.builder, 'update')
        self._set_config(self.jjb_config.yamlparser, 'allow_empty_variables')
        self._set_config(self.jjb_config.jenkins, 'section')
        self._set_config(self.jjb_config.jenkins, 'user')
        self._set_config(self.jjb_config.jenkins, 'password')

        # Note: CLI options override config file options.
        if getattr(self.options, 'update', None) is None:
            self.options.update = self.jjb_config.builder.get('update')
            if self.options.update is None:
                self.options.update = 'all'

        if getattr(self.options, 'plugins_info_path', None) is not None:
            with io.open(self.options.plugins_info_path, 'r',
                         encoding='utf-8') as yaml_file:
                plugins_info = yaml.load(yaml_file)
            if not isinstance(plugins_info, list):
                self.parser.error("{0} must contain a Yaml list!".format(
                                  self.options.plugins_info_path))
            self.jjb_config.builder['plugins_info'] = plugins_info

        if getattr(self.options, 'path', None):
            if hasattr(self.options.path, 'read'):
                logger.debug("Input file is stdin")
                if self.options.path.isatty():
                    if platform.system() == 'Windows':
                        key = 'CTRL+Z'
                    else:
                        key = 'CTRL+D'
                    logger.warning("Reading configuration from STDIN. "
                                   "Press %s to end input.", key)
                self.options.path = [self.options.path]
            else:
                # take list of paths
                self.options.path = self.options.path.split(os.pathsep)

                do_recurse = (getattr(self.options, 'recursive', False) or
                              self.jjb_config.recursive)

                excludes = ([e for elist in self.options.exclude
                             for e in elist.split(os.pathsep)] or
                            self.jjb_config.excludes)
                paths = []
                for path in self.options.path:
                    if do_recurse and os.path.isdir(path):
                        paths.extend(utils.recurse_path(path, excludes))
                    else:
                        paths.append(path)
                self.options.path = paths
Exemplo n.º 6
0
    def test_recursive_path_option_exclude_relative(self, oswalk_mock):
        """
        Test paths returned by the recursive processing when using relative
        excludes.

        testing paths
            ./jjb_configs/dir1/test/
            ./jjb_configs/dir1/file
            ./jjb_configs/dir2/test/
            ./jjb_configs/dir3/bar/
            ./jjb_configs/test3/bar/
            ./jjb_configs/test3/baz/
        """

        os_walk_paths = [
            ("jjb_configs", (["dir1", "dir2", "dir3", "test3"], ())),
            ("jjb_configs/dir1", (["test"], ("file"))),
            ("jjb_configs/dir2", (["test2"], ())),
            ("jjb_configs/dir3", (["bar"], ())),
            ("jjb_configs/test3", (["bar", "baz"], ())),
            ("jjb_configs/dir1/test", ([], ())),
            ("jjb_configs/dir2/test2", ([], ())),
            ("jjb_configs/dir3/bar", ([], ())),
            ("jjb_configs/test3/bar", None),
            ("jjb_configs/test3/baz", ([], ())),
        ]

        rel_os_walk_paths = [(os.path.abspath(os.path.join(os.path.curdir,
                                                           k)), v)
                             for k, v in os_walk_paths]

        paths = [k for k, v in rel_os_walk_paths if v is not None]

        oswalk_mock.side_effect = fake_os_walk(rel_os_walk_paths)

        self.assertEqual(
            paths, utils.recurse_path("jjb_configs",
                                      ["jjb_configs/test3/bar"]))
    def test_recursive_path_option_exclude_relative(self, oswalk_mock):
        """
        Test paths returned by the recursive processing when using relative
        excludes.

        testing paths
            ./jjb_configs/dir1/test/
            ./jjb_configs/dir1/file
            ./jjb_configs/dir2/test/
            ./jjb_configs/dir3/bar/
            ./jjb_configs/test3/bar/
            ./jjb_configs/test3/baz/
        """

        os_walk_paths = [
            ('jjb_configs', (['dir1', 'dir2', 'dir3', 'test3'], ())),
            ('jjb_configs/dir1', (['test'], ('file'))),
            ('jjb_configs/dir2', (['test2'], ())),
            ('jjb_configs/dir3', (['bar'], ())),
            ('jjb_configs/test3', (['bar', 'baz'], ())),
            ('jjb_configs/dir1/test', ([], ())),
            ('jjb_configs/dir2/test2', ([], ())),
            ('jjb_configs/dir3/bar', ([], ())),
            ('jjb_configs/test3/bar', None),
            ('jjb_configs/test3/baz', ([], ()))
        ]

        rel_os_walk_paths = [
            (os.path.abspath(
                os.path.join(os.path.curdir, k)), v) for k, v in os_walk_paths]

        paths = [k for k, v in rel_os_walk_paths if v is not None]

        oswalk_mock.side_effect = fake_os_walk(rel_os_walk_paths)

        self.assertEqual(paths, utils.recurse_path('jjb_configs',
                                                   ['jjb_configs/test3/bar']))