Ejemplo n.º 1
0
    def _make_plugin_section(self, plugin_cls, base_name=None):
        section_name = plugin_cls.get_name()
        if base_name:
            section_name += " [%s]" % base_name
        section_obj = section(section_name)

        info = plugin_cls.get_info()
        if info["title"]:
            section_obj.append(paragraph(info["title"]))

        if info["description"]:
            section_obj.extend(parse_text(info["description"]))

        if info["namespace"]:
            section_obj.append(
                paragraph("**Namespace**: %s" % info["namespace"]))

        if info["parameters"]:
            if base_name:
                ref_prefix = "%s-%s-" % (base_name, plugin_cls.get_name())
            else:
                ref_prefix = "%s-" % plugin_cls.get_name()

            section_obj.extend(
                self._make_pretty_parameters(info["parameters"], ref_prefix))

            if info["returns"]:
                section_obj.extend(
                    parse_text("**Returns**:\n%s" % info["returns"]))

        filename = info["module"].replace(".", "/")
        ref = "https://github.com/openstack/rally/blob/master/%s.py" % filename
        section_obj.extend(
            parse_text("**Module**:\n`%s`__\n\n__ %s" % (info["module"], ref)))
        return section_obj
Ejemplo n.º 2
0
    def parse_item(self, response):
        article = Article()

        title = response.xpath(self.rule.title_xpath).extract()
        article["title"] = parse_text(title, self.rule.name, 'title')

        body = response.xpath(self.rule.body_xpath).extract()
        article["body"] = parse_text(body, self.rule.name, 'body')

        publish_time = response.xpath(self.rule.publish_time_xpath).extract()
        article["publish_time"] = parse_text(publish_time, self.rule.name,
                                             'publish_time')

        return article
Ejemplo n.º 3
0
def make_command_section(category_name, name, parser):
    section = utils.subcategory("rally %s %s" % (category_name, name))
    section.extend(utils.parse_text(parser["description"]))
    if parser["parser"].arguments:
        defaults = get_defaults(parser["parser"].defaults["action_fn"])
        section.extend(make_arguments_section(
            category_name, name, parser["parser"].arguments, defaults))
    return section
Ejemplo n.º 4
0
def make_command_section(category_name, name, parser):
    section = utils.subcategory("rally %s %s" % (category_name, name))
    section.extend(utils.parse_text(parser["description"]))
    if parser["parser"].arguments:
        defaults = get_defaults(parser["parser"].defaults["action_fn"])
        section.extend(
            make_arguments_section(category_name, name,
                                   parser["parser"].arguments, defaults))
    return section
Ejemplo n.º 5
0
def make_command_section(category_name, name, parser):
    # NOTE(andreykurilin): there is only one category in rally-manage, so
    # let's just hardcode it.
    cmd = "rally-manage" if category_name == "db" else "rally"
    section = subcategory("%s %s %s" % (cmd, category_name, name))
    section.extend(parse_text(parser["description"]))
    if parser["parser"].arguments:
        defaults = get_defaults(parser["parser"].defaults["action_fn"])
        section.extend(make_arguments_section(
            category_name, name, parser["parser"].arguments, defaults))
    return section
Ejemplo n.º 6
0
def make_command_section(category_name, name, parser):
    # NOTE(andreykurilin): there is only one category in rally-manage, so
    # let's just hardcode it.
    cmd = "rally-manage" if category_name == "db" else "rally"
    section = utils.subcategory("%s %s %s" % (cmd, category_name, name))
    section.extend(utils.parse_text(parser["description"]))
    if parser["parser"].arguments:
        defaults = get_defaults(parser["parser"].defaults["action_fn"])
        section.extend(
            make_arguments_section(category_name, name,
                                   parser["parser"].arguments, defaults))
    return section
Ejemplo n.º 7
0
def make_plugin_section(plugin, base_name):
    subcategory_obj = subcategory("%s [%s]" % (plugin.get_name(), base_name))
    info = plugin.get_info()
    if info["title"]:
        subcategory_obj.append(paragraph(info["title"]))

    if info["description"]:
        subcategory_obj.extend(parse_text(info["description"]))

    if info["namespace"]:
        subcategory_obj.append(
            paragraph("**Namespace**: %s" % info["namespace"]))

    if info["parameters"]:
        subcategory_obj.extend(
            parse_text(_make_pretty_parameters(info["parameters"])))
        if info["returns"]:
            subcategory_obj.extend(
                parse_text("**Returns**:\n%s" % info["returns"]))
    filename = info["module"].replace(".", "/")
    ref = "https://github.com/openstack/rally/blob/master/%s.py" % filename
    subcategory_obj.extend(
        parse_text("**Module**:\n`%s`__\n\n__ %s" % (info["module"], ref)))
    return subcategory_obj
Ejemplo n.º 8
0
def make_plugin_section(plugin, base_name):
    subcategory_obj = subcategory("%s [%s]" % (plugin.get_name(), base_name))
    info = plugin.get_info()
    if info["title"]:
        subcategory_obj.append(paragraph(info["title"]))

    if info["description"]:
        subcategory_obj.extend(parse_text(info["description"]))

    if info["namespace"]:
        subcategory_obj.append(paragraph(
                "**Namespace**: %s" % info["namespace"]))

    if info["parameters"]:
        subcategory_obj.extend(parse_text(
                _make_pretty_parameters(info["parameters"])))
        if info["returns"]:
            subcategory_obj.extend(parse_text(
                    "**Returns**:\n%s" % info["returns"]))
    filename = info["module"].replace(".", "/")
    ref = "https://github.com/openstack/rally/blob/master/%s.py" % filename
    subcategory_obj.extend(parse_text("**Module**:\n`%s`__\n\n__ %s"
                                      % (info["module"], ref)))
    return subcategory_obj
Ejemplo n.º 9
0
def make_category_section(name, parser):
    category_obj = utils.category("Category: %s" % name)
    # NOTE(andreykurilin): we are re-using `_add_command_parsers` method from
    # `rally.cli.cliutils`, but, since it was designed to print help message,
    # generated description for categories contains specification for all
    # sub-commands. We don't need information about sub-commands at this point,
    # so let's skip "generated description" and take it directly from category
    # class.
    description = parser.defaults["command_object"].__doc__
    # TODO(andreykurilin): write a decorator which will mark cli-class as
    #   deprecated without changing its docstring.
    if description.startswith("[Deprecated"):
        i = description.find("]")
        msg = description[1:i]
        description = description[i + 1:].strip()
        category_obj.append(utils.warning(msg))
    category_obj.extend(utils.parse_text(description))

    for command in sorted(parser.subparser.parsers.keys()):
        subparser = parser.subparser.parsers[command]
        category_obj.append(make_command_section(name, command, subparser))
    return category_obj
Ejemplo n.º 10
0
def make_category_section(name, parser):
    category_obj = category("Category: %s" % name)
    # NOTE(andreykurilin): we are re-using `_add_command_parsers` method from
    # `rally.cli.cliutils`, but, since it was designed to print help message,
    # generated description for categories contains specification for all
    # sub-commands. We don't need information about sub-commands at this point,
    # so let's skip "generated description" and take it directly from category
    # class.
    description = parser.defaults["command_object"].__doc__
    # TODO(andreykurilin): write a decorator which will mark cli-class as
    #   deprecated without changing its docstring.
    if description.startswith("[Deprecated"):
        i = description.find("]")
        msg = description[1:i]
        description = description[i+1:].strip()
        category_obj.append(warning(msg))
    category_obj.extend(parse_text(description))

    for command in sorted(parser.subparser.parsers.keys()):
        subparser = parser.subparser.parsers[command]
        category_obj.append(make_command_section(name, command, subparser))
    return category_obj
Ejemplo n.º 11
0
    def _make_plugin_section(self, plugin_cls, base_name=None):
        section_name = plugin_cls.get_name()
        if base_name:
            section_name += " [%s]" % base_name
        section_obj = utils.section(section_name)

        info = plugin_cls.get_info()
        if info["title"]:
            section_obj.append(utils.paragraph(info["title"]))

        if info["description"]:
            section_obj.extend(utils.parse_text(info["description"]))

        if info["namespace"]:
            section_obj.append(
                utils.paragraph("**Namespace**: %s" % info["namespace"]))

        if base_name:
            ref_prefix = "%s-%s-" % (base_name, plugin_cls.get_name())
        else:
            ref_prefix = "%s-" % plugin_cls.get_name()

        if info["parameters"]:
            section_obj.extend(
                self._make_arg_items(info["parameters"], ref_prefix))

        if info["returns"]:
            section_obj.extend(
                utils.parse_text("**Returns**:\n%s" % info["returns"]))

        if info["schema"]:
            schema = process_jsonschema(info["schema"])
            if "type" in schema:
                if "parameters" in schema:
                    section_obj.extend(
                        self._make_arg_items(items=schema["parameters"],
                                             ref_prefix=ref_prefix))
                elif "patternProperties" in schema:
                    section_obj.extend(
                        self._make_arg_items(
                            items=schema["patternProperties"],
                            ref_prefix=ref_prefix,
                            description=[
                                "*Dictionary is expected. Keys should "
                                "follow pattern(s) described bellow.*"
                            ]))
                elif "oneOf" in schema:
                    section_obj.append(
                        utils.note("One of the following groups of "
                                   "parameters should be provided."))
                    for i, oneOf in enumerate(schema["oneOf"], 1):
                        description = None
                        if oneOf.get("doc", None):
                            description = [oneOf["doc"]]
                        section_obj.extend(
                            self._make_arg_items(
                                items=oneOf["parameters"],
                                ref_prefix=ref_prefix,
                                title="Option %s of parameters" % i,
                                description=description))
                else:
                    section_obj.extend(
                        self._make_arg_items(items=[schema],
                                             ref_prefix=ref_prefix))
            else:
                raise Exception("Failed to display provided schema: %s" %
                                info["schema"])

        if issubclass(plugin_cls, validation.ValidatablePluginMixin):
            validators = plugin_cls._meta_get("validators", default=[])
            platforms = [
                kwargs for name, args, kwargs in validators
                if name == "required_platform"
            ]
            if platforms:
                section_obj.append(
                    utils.paragraph("**Requires platform(s)**:"))
                section = ""
                for p in platforms:
                    section += "* %s" % p["platform"]
                    admin_msg = "credentials for admin user"
                    user_msg = ("regular users (temporary users can be created"
                                " via the 'users' context if admin user is "
                                "specified for the platform)")
                    if p.get("admin", False) and p.get("users", False):
                        section += " with %s and %s." % (admin_msg, user_msg)
                    elif p.get("admin", False):
                        section += " with %s." % admin_msg
                    elif p.get("users", False):
                        section += " with %s." % user_msg
                    section += "\n"

                section_obj.extend(utils.parse_text(section))

        filename = info["module"].replace(".", "/")
        ref = "https://github.com/openstack/rally/blob/master/%s.py" % filename
        section_obj.extend(
            utils.parse_text("**Module**:\n`%s`__\n\n__ %s" %
                             (info["module"], ref)))
        return section_obj
Ejemplo n.º 12
0
    def _make_plugin_section(self, plugin_cls, base_name=None):
        section_name = plugin_cls.get_name()
        if base_name:
            section_name += " [%s]" % base_name
        section_obj = section(section_name)

        info = plugin_cls.get_info()
        if info["title"]:
            section_obj.append(paragraph(info["title"]))

        if info["description"]:
            section_obj.extend(parse_text(info["description"]))

        if info["namespace"]:
            section_obj.append(
                paragraph("**Namespace**: %s" % info["namespace"]))

        if base_name:
            ref_prefix = "%s-%s-" % (base_name, plugin_cls.get_name())
        else:
            ref_prefix = "%s-" % plugin_cls.get_name()

        if info["parameters"]:
            section_obj.extend(
                self._make_arg_items(info["parameters"], ref_prefix))

        if info["returns"]:
            section_obj.extend(parse_text("**Returns**:\n%s" %
                                          info["returns"]))

        if info["schema"]:
            schema = process_jsonschema(info["schema"])
            if "type" in schema:
                if "parameters" in schema:
                    section_obj.extend(
                        self._make_arg_items(items=schema["parameters"],
                                             ref_prefix=ref_prefix))
                elif "patternProperties" in schema:
                    section_obj.extend(
                        self._make_arg_items(
                            items=schema["patternProperties"],
                            ref_prefix=ref_prefix,
                            description=[
                                "*Dictionary is expected. Keys should "
                                "follow pattern(s) described bellow.*"
                            ]))
                elif "oneOf" in schema:
                    section_obj.append(
                        note("One of the following groups of "
                             "parameters should be provided."))
                    for i, oneOf in enumerate(schema["oneOf"], 1):
                        description = None
                        if oneOf.get("doc", None):
                            description = [oneOf["doc"]]
                        section_obj.extend(
                            self._make_arg_items(
                                items=oneOf["parameters"],
                                ref_prefix=ref_prefix,
                                title="Option %s of parameters" % i,
                                description=description))
                else:
                    section_obj.extend(
                        self._make_arg_items(items=[schema],
                                             ref_prefix=ref_prefix))
            else:
                raise Exception("Failed to display provided schema: %s" %
                                info["schema"])

        filename = info["module"].replace(".", "/")
        ref = "https://github.com/openstack/rally/blob/master/%s.py" % filename
        section_obj.extend(
            parse_text("**Module**:\n`%s`__\n\n__ %s" % (info["module"], ref)))
        return section_obj
Ejemplo n.º 13
0
    def _make_plugin_section(self, plugin_cls, base_name=None):
        section_name = plugin_cls.get_name()
        if base_name:
            section_name += " [%s]" % base_name
        section_obj = utils.section(section_name)

        info = plugin_cls.get_info()
        if info["title"]:
            section_obj.append(utils.paragraph(info["title"]))

        if info["description"]:
            section_obj.extend(utils.parse_text(info["description"]))

        if info["platform"]:
            section_obj.append(utils.paragraph(
                "**Platform**: %s" % info["platform"]))

        if base_name:
            ref_prefix = "%s-%s-" % (base_name, plugin_cls.get_name())
        else:
            ref_prefix = "%s-" % plugin_cls.get_name()

        if info["parameters"]:
            section_obj.extend(self._make_arg_items(info["parameters"],
                                                    ref_prefix))

        if info["returns"]:
            section_obj.extend(utils.parse_text(
                "**Returns**:\n%s" % info["returns"]))

        if info["schema"]:
            schema = process_jsonschema(info["schema"])
            if "type" in schema:
                if "parameters" in schema:
                    section_obj.extend(self._make_arg_items(
                        items=schema["parameters"],
                        ref_prefix=ref_prefix))
                elif "patternProperties" in schema:
                    section_obj.extend(self._make_arg_items(
                        items=schema["patternProperties"],
                        ref_prefix=ref_prefix,
                        description=["*Dictionary is expected. Keys should "
                                     "follow pattern(s) described bellow.*"]))
                elif "oneOf" in schema:
                    section_obj.append(utils.note(
                        "One of the following groups of "
                        "parameters should be provided."))
                    for i, oneOf in enumerate(schema["oneOf"], 1):
                        description = None
                        if oneOf.get("doc", None):
                            description = [oneOf["doc"]]
                        section_obj.extend(self._make_arg_items(
                            items=oneOf["parameters"],
                            ref_prefix=ref_prefix,
                            title="Option %s of parameters" % i,
                            description=description))
                else:
                    section_obj.extend(self._make_arg_items(
                        items=[schema], ref_prefix=ref_prefix))
            else:
                raise Exception("Failed to display provided schema: %s" %
                                info["schema"])

        if issubclass(plugin_cls, validation.ValidatablePluginMixin):
            validators = plugin_cls._meta_get("validators", default=[])
            platforms = [kwargs for name, args, kwargs in validators
                         if name == "required_platform"]
            if platforms:
                section_obj.append(
                    utils.paragraph("**Requires platform(s)**:"))
                section = ""
                for p in platforms:
                    section += "* %s" % p["platform"]
                    admin_msg = "credentials for admin user"
                    user_msg = ("regular users (temporary users can be created"
                                " via the 'users' context if admin user is "
                                "specified for the platform)")
                    if p.get("admin", False) and p.get("users", False):
                        section += " with %s and %s." % (admin_msg, user_msg)
                    elif p.get("admin", False):
                        section += " with %s." % admin_msg
                    elif p.get("users", False):
                        section += " with %s." % user_msg
                    section += "\n"

                section_obj.extend(utils.parse_text(section))

        filename = info["module"].replace(".", "/")
        if filename.startswith("rally/"):
            project = "rally"
        elif filename.startswith("rally_openstack/"):
            project = "rally-openstack"
        else:
            # WTF is it?!
            return None
        ref = ("https://github.com/openstack/%s/blob/master/%s.py"
               % (project, filename))
        section_obj.extend(utils.parse_text("**Module**:\n`%s`__\n\n__ %s"
                           % (info["module"], ref)))
        return section_obj