def gen_tasks_goals_reference_data(): """Generate the template data for the goals reference rst doc.""" goal_dict = {} goal_names = [] for goal in Goal.all(): tasks = [] for task_name in goal.ordered_task_names(): task_type = goal.task_type_by_name(task_name) doc_rst = indent_docstring_by_n(task_type.__doc__ or '', 2) doc_html = rst_to_html(dedent_docstring(task_type.__doc__)) option_parser = Parser(env={}, config={}, scope='', parent_parser=None) task_type.register_options(option_parser.register) argparser = option_parser._help_argparser scope = Goal.scope(goal.name, task_name) # task_type may actually be a synthetic subclass of the authored class from the source code. # We want to display the authored class's name in the docs (but note that we must use the # subclass for registering options above) for authored_task_type in task_type.mro(): if authored_task_type.__module__ != 'abc': break impl = '{0}.{1}'.format(authored_task_type.__module__, authored_task_type.__name__) tasks.append(TemplateData( impl=impl, doc_html=doc_html, doc_rst=doc_rst, ogroup=gref_template_data_from_options(scope, argparser))) goal_dict[goal.name] = TemplateData(goal=goal, tasks=tasks) goal_names.append(goal.name) goals = [goal_dict[name] for name in sorted(goal_names, key=lambda x: x.lower())] return goals
def gen_tasks_options_reference_data(): """Generate the template data for the options reference rst doc.""" goal_dict = {} goal_names = [] for goal in Goal.all(): tasks = [] for task_name in goal.ordered_task_names(): task_type = goal.task_type_by_name(task_name) doc_rst = indent_docstring_by_n(task_type.__doc__ or '', 2) doc_html = rst_to_html(dedent_docstring(task_type.__doc__)) option_parser = Parser(env={}, config={}, scope='', help_request=None, parent_parser=None) def register(*args, **kwargs): option_parser.register(*args, **kwargs) register.bootstrap = bootstrap_option_values() task_type.register_options(register) argparser = option_parser._help_argparser scope = Goal.scope(goal.name, task_name) # task_type may actually be a synthetic subclass of the authored class from the source code. # We want to display the authored class's name in the docs (but note that we must use the # subclass for registering options above) for authored_task_type in task_type.mro(): if authored_task_type.__module__ != 'abc': break impl = '{0}.{1}'.format(authored_task_type.__module__, authored_task_type.__name__) tasks.append(TemplateData( impl=impl, doc_html=doc_html, doc_rst=doc_rst, ogroup=oref_template_data_from_options(scope, argparser))) goal_dict[goal.name] = TemplateData(goal=goal, tasks=tasks) goal_names.append(goal.name) goals = [goal_dict[name] for name in sorted(goal_names, key=lambda x: x.lower())] return goals
def add_member(cls, group_member): """Enlists a member in this group. A group task delegates all its work to group members who act cooperatively on targets they claim. The order members are added affects the target claim process by setting the order the group members are asked to claim targets in on a first-come, first-served basis. """ if not issubclass(group_member, GroupMember): raise ValueError('Only GroupMember subclasses can join a GroupTask, ' 'given {} of type {}'.format(group_member, type(group_member))) group_member.options_scope = Goal.scope(cls.parent_options_scope, group_member.name()) cls._member_types().append(group_member)
def add_member(cls, group_member): """Enlists a member in this group. A group task delegates all its work to group members who act cooperatively on targets they claim. The order members are added affects the target claim process by setting the order the group members are asked to claim targets in on a first-come, first-served basis. """ if not issubclass(group_member, GroupMember): raise ValueError('Only GroupMember subclasses can join a GroupTask, ' 'given %s of type %s' % (group_member, type(group_member))) group_member.options_scope = Goal.scope(cls.parent_options_scope, group_member.name()) cls._member_types().append(group_member)
def setup_parser(cls, option_group, args, mkflag): base_namespace = flag_namespace or mkflag.namespace for member_type in cls._member_types(): member_namespace = base_namespace + [member_type.name()] mkflag = Mkflag(*member_namespace) # Hack to find the right option group. Ugly, but old options are # going away soon anyway. title = Goal.scope(cls.parent_options_scope, member_type.name()) member_og = None for og in option_group.parser.option_groups: if og.title == title: member_og = og break member_og = member_og or OptionGroup(option_group.parser, title=title) member_type.setup_parser(member_og, args, mkflag)
def gen_tasks_goals_reference_data(): """Generate the template data for the goals reference rst doc.""" goal_dict = {} goal_names = [] for goal in Goal.all(): parser = optparse.OptionParser(add_help_option=False) Goal.setup_parser(parser, [], [goal]) options_by_title = defaultdict(lambda: None) for group in parser.option_groups: options_by_title[group.title] = group found_option_groups = set() tasks = [] for task_name in goal.ordered_task_names(): task_type = goal.task_type_by_name(task_name) doc_rst = indent_docstring_by_n(task_type.__doc__ or '', 2) doc_html = rst_to_html(dedent_docstring(task_type.__doc__)) options_title = Goal.scope(goal.name, task_name) og = options_by_title[options_title] if og: found_option_groups.add(options_title) impl = '{0}.{1}'.format(task_type.__module__, task_type.__name__) tasks.append(TemplateData( impl=impl, doc_html=doc_html, doc_rst=doc_rst, ogroup=gref_template_data_from_options(og))) leftover_option_groups = [] for group in parser.option_groups: if group.title in found_option_groups: continue leftover_option_groups.append(gref_template_data_from_options(group)) leftover_options = [] for option in parser.option_list: leftover_options.append(TemplateData(st=str(option))) goal_dict[goal.name] = TemplateData(goal=goal, tasks=tasks, leftover_opts=leftover_options, leftover_ogs=leftover_option_groups) goal_names.append(goal.name) goals = [goal_dict[name] for name in sorted(goal_names, key=lambda x: x.lower())] return goals