Code Duplication    Length = 41-44 lines in 2 locations

org_fedora_oscap/ks/oscap.py 1 location

@@ 236-279 (lines=44) @@
233
            msg = "Unknown item '%s' for %s addon" % (line, self.name)
234
            raise KickstartParseError(msg)
235
236
    def finalize(self):
237
        """
238
        The finalize method that is called when the end of the %addon section
239
        (the %end line) is reached. It means no more kickstart data will come.
240
241
        """
242
243
        tmpl = "%s missing for the %s addon"
244
245
        # check provided data
246
        if not self.content_type:
247
            raise KickstartValueError(tmpl % ("content-type", self.name))
248
249
        if self.content_type != "scap-security-guide" and not self.content_url:
250
            raise KickstartValueError(tmpl % ("content-url", self.name))
251
252
        if not self.profile_id:
253
            self.profile_id = "default"
254
255
        if self.content_type in ("rpm", "archive") and not self.content_path:
256
            msg = "Path to the XCCDF file has to be given if content in RPM "\
257
                  "or archive is used"
258
            raise KickstartValueError(msg)
259
260
        if self.content_type == "rpm" and not self.content_url.endswith(".rpm"):
261
            msg = "Content type set to RPM, but the content URL doesn't end "\
262
                  "with '.rpm'"
263
            raise KickstartValueError(msg)
264
265
        if self.content_type == "archive":
266
            supported_archive = any(self.content_url.endswith(arch_type)
267
                                    for arch_type in SUPPORTED_ARCHIVES)
268
            if not supported_archive:
269
                msg = "Unsupported archive type of the content "\
270
                      "file '%s'" % self.content_url
271
                raise KickstartValueError(msg)
272
273
        # do some initialization magic in case of SSG
274
        if self.content_type == "scap-security-guide":
275
            if not common.ssg_available():
276
                msg = "SCAP Security Guide not found on the system"
277
                raise KickstartValueError(msg)
278
279
            self.content_path = common.SSG_DIR + common.SSG_CONTENT
280
281
    @property
282
    def content_defined(self):

org_fedora_oscap/service/kickstart.py 1 location

@@ 162-202 (lines=41) @@
159
    def _parse_certificates(self, value):
160
        self.certificates = value
161
162
    def handle_end(self):
163
        """Handle the end of the section."""
164
        tmpl = "%s missing for the %s addon"
165
166
        # check provided data
167
        if not self.content_type:
168
            raise KickstartValueError(tmpl % ("content-type", self.name))
169
170
        if self.content_type != "scap-security-guide" and not self.content_url:
171
            raise KickstartValueError(tmpl % ("content-url", self.name))
172
173
        if not self.profile_id:
174
            self.profile_id = "default"
175
176
        if self.content_type in ("rpm", "archive") and not self.content_path:
177
            msg = "Path to the XCCDF file has to be given if content in RPM "\
178
                  "or archive is used"
179
            raise KickstartValueError(msg)
180
181
        if self.content_type == "rpm" and not self.content_url.endswith(".rpm"):
182
            msg = "Content type set to RPM, but the content URL doesn't end "\
183
                  "with '.rpm'"
184
            raise KickstartValueError(msg)
185
186
        if self.content_type == "archive":
187
            supported_archive = any(
188
                self.content_url.endswith(arch_type)
189
                for arch_type in common.SUPPORTED_ARCHIVES
190
            )
191
            if not supported_archive:
192
                msg = "Unsupported archive type of the content "\
193
                      "file '%s'" % self.content_url
194
                raise KickstartValueError(msg)
195
196
        # do some initialization magic in case of SSG
197
        if self.content_type == "scap-security-guide":
198
            if not common.ssg_available():
199
                msg = "SCAP Security Guide not found on the system"
200
                raise KickstartValueError(msg)
201
202
            self.content_path = common.SSG_DIR + common.SSG_CONTENT
203
204
    def __str__(self):
205
        """Generate the kickstart representation.