~sambuddhabasu1/mailman/fix_mailman_run_error

« back to all changes in this revision

Viewing changes to src/mailman/commands/cli_conf.py

  • Committer: Barry Warsaw
  • Date: 2014-11-08 15:27:56 UTC
  • mfrom: (7255 3.0)
  • mto: This revision was merged to the branch mainline in revision 7260.
  • Revision ID: barry@list.org-20141108152756-p37fhmb0z2dtl7hx
Trunk merge.

Show diffs side-by-side

added added

removed removed

Lines of Context:
65
65
            key-values pair from any section matching the given key will be
66
66
            displayed.
67
67
            """))
68
 
        command_parser.add_argument(
69
 
            '-t', '--sort',
70
 
            default=False, action='store_true',
71
 
            help=_('Sort the output by sections and keys.'))
72
68
 
73
69
    def _get_value(self, section, key):
74
70
        return getattr(getattr(config, section), key)
75
71
 
76
 
    def _sections(self, sort_p):
77
 
        sections = config.schema._section_schemas
78
 
        if sort_p:
79
 
            sections = sorted(sections)
80
 
        return sections
 
72
    def _sections(self):
 
73
        return sorted(config.schema._section_schemas)
81
74
 
82
75
    def _print_full_syntax(self, section, key, value, output):
83
76
        print('[{}] {}: {}'.format(section, key, value), file=output)
88
81
    def _show_section_error(self, section):
89
82
        self.parser.error('No such section: {}'.format(section))
90
83
 
91
 
    def _print_values_for_section(self, section, output, sort_p):
92
 
        current_section = getattr(config, section)
93
 
        if sort_p:
94
 
            current_section = sorted(current_section)
 
84
    def _print_values_for_section(self, section, output):
 
85
        current_section = sorted(getattr(config, section))
95
86
        for key in current_section:
96
87
            self._print_full_syntax(section, key,
97
88
                                    self._get_value(section, key), output)
106
97
        # Process the command, ignoring the closing of the output file.
107
98
        section = args.section
108
99
        key = args.key
109
 
        sort_p = args.sort
110
100
        # Case 1: Both section and key are given, so we can directly look up
111
101
        # the value.
112
102
        if section is not None and key is not None:
119
109
        # Case 2: Section is given, key is not given.
120
110
        elif section is not None and key is None:
121
111
            if self._section_exists(section):
122
 
                self._print_values_for_section(section, output, sort_p)
 
112
                self._print_values_for_section(section, output)
123
113
            else:
124
114
                self._show_section_error(section)
125
115
        # Case 3: Section is not given, key is given.
126
116
        elif section is None and key is not None:
127
 
            for current_section in self._sections(sort_p):
 
117
            for current_section in self._sections():
128
118
                # We have to ensure that the current section actually exists
129
119
                # and that it contains the given key.
130
120
                if (self._section_exists(current_section) and
137
127
        # Case 4: Neither section nor key are given, just display all the
138
128
        # sections and their corresponding key/value pairs.
139
129
        elif section is None and key is None:
140
 
            for current_section in self._sections(sort_p):
 
130
            for current_section in self._sections():
141
131
                # However, we have to make sure that the current sections and
142
132
                # key which are being looked up actually exist before trying
143
133
                # to print them.
144
134
                if self._section_exists(current_section):
145
 
                    self._print_values_for_section(
146
 
                        current_section, output, sort_p)
 
135
                    self._print_values_for_section(current_section, output)
147
136
 
148
137
    def process(self, args):
149
138
        """See `ICLISubCommand`."""