Code Duplication    Length = 42-44 lines in 2 locations

org_fedora_oscap/service/installation.py 2 locations

@@ 270-313 (lines=44) @@
267
            return
268
269
270
class ScheduleFirstbootRemediationTask(Task):
271
    """The installation task for running the remediation."""
272
273
    def __init__(self, sysroot, policy_data, target_content_path,
274
                 target_tailoring_path):
275
        """Create a task."""
276
        super().__init__()
277
        self._sysroot = sysroot
278
        self._policy_data = policy_data
279
        self._target_content_path = target_content_path
280
        self._target_tailoring_path = target_tailoring_path
281
282
    @property
283
    def name(self):
284
        return "Schedule first-boot remediation"
285
286
    def run(self):
287
        """Run the task."""
288
        try:
289
            common.assert_scanner_works(
290
                chroot=self._sysroot, executable="oscap")
291
        except Exception as exc:
292
            msg_lines = [_(
293
                "The 'oscap' scanner doesn't work in the installed system: {error}"
294
                .format(error=str(exc)))]
295
            msg_lines.append(_("As a result, the installed system can't be hardened."))
296
            terminate("\n".join(msg_lines))
297
            return
298
299
        try:
300
            common.schedule_firstboot_remediation(
301
                self._sysroot,
302
                self._policy_data.profile_id,
303
                self._target_content_path,
304
                self._policy_data.datastream_id,
305
                self._policy_data.xccdf_id,
306
                self._target_tailoring_path,
307
            )
308
        except Exception as exc:
309
            msg = _(
310
                "Something went wrong when scheduling the first-boot remediation: {exc}."
311
                .format(exc=str(exc)))
312
            terminate(msg)
313
            return
314
@@ 226-267 (lines=42) @@
223
            shutil.copy2(self._tailoring_path, target_content_dir)
224
225
226
class RemediateSystemTask(Task):
227
    """The installation task for running the remediation."""
228
229
    def __init__(self, sysroot, policy_data, target_content_path,
230
                 target_tailoring_path):
231
        """Create a task."""
232
        super().__init__()
233
        self._sysroot = sysroot
234
        self._policy_data = policy_data
235
        self._target_content_path = target_content_path
236
        self._target_tailoring_path = target_tailoring_path
237
238
    @property
239
    def name(self):
240
        return "Remediate the system"
241
242
    def run(self):
243
        """Run the task."""
244
        try:
245
            common.assert_scanner_works(
246
                chroot=self._sysroot, executable="oscap")
247
        except Exception as exc:
248
            msg_lines = [_(
249
                "The 'oscap' scanner doesn't work in the installed system: {error}"
250
                .format(error=str(exc)))]
251
            msg_lines.append(_("As a result, the installed system can't be hardened."))
252
            terminate("\n".join(msg_lines))
253
            return
254
255
        try:
256
            common.run_oscap_remediate(
257
                self._policy_data.profile_id,
258
                self._target_content_path,
259
                self._policy_data.datastream_id,
260
                self._policy_data.xccdf_id,
261
                self._target_tailoring_path,
262
                chroot=self._sysroot
263
            )
264
        except Exception as exc:
265
            msg = _(f"Something went wrong during the final hardening: {str(exc)}.")
266
            terminate(msg)
267
            return
268
269
270
class ScheduleFirstbootRemediationTask(Task):