repair.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. ########################################################################
  2. # Wiizard - A Wii games manager
  3. # Copyright (C) 2023 CYBERDEViL
  4. #
  5. # This file is part of Wiizard.
  6. #
  7. # Wiizard is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation, either version 3 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # Wiizard is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  19. #
  20. ########################################################################
  21. from PyQt5.QtWidgets import (
  22. QDialog,
  23. QListWidget,
  24. QGridLayout,
  25. QLabel,
  26. QPushButton,
  27. QCheckBox,
  28. QMessageBox
  29. )
  30. import pywwt
  31. from wiizard.source import PartitionRepairThread
  32. import wiizard.globals as Global
  33. from wiizard.translations import _
  34. """
  35. _________[REPAIR]___________
  36. Partition: /dev/sdb1
  37. Errors : 1783
  38. ________Summary_______
  39. |... |
  40. |.... |
  41. |.. |
  42. |______________________|
  43. [X] Simulate
  44. [Cancel] [Repair]
  45. """
  46. class RepairDialog(QDialog):
  47. def __init__(self, sourceModel, parent=None):
  48. QDialog.__init__(self, parent=parent)
  49. self.__sourceModel = sourceModel
  50. self.__repairThread = None
  51. self.setWindowTitle(_("Repair partition"))
  52. layout = QGridLayout(self)
  53. layout.addWidget(QLabel(_("Partition:"), self), 0, 0, 1, 1)
  54. layout.addWidget(QLabel(sourceModel.location, self), 0, 1, 1, 1)
  55. layout.addWidget(QLabel(_("Errors:"), self), 1, 0, 1, 1)
  56. layout.addWidget(QLabel(str(sourceModel.hasErrors()), self), 1, 1, 1, 1)
  57. self.__errorsList = QListWidget(self)
  58. for errorMessage in sourceModel.getErrors():
  59. self.__errorsList.addItem(errorMessage)
  60. layout.addWidget(self.__errorsList, 2, 0, 1, 2)
  61. self.__simulateCheck = QCheckBox(_("Simulate"), self)
  62. self.__simulateCheck.setChecked(True)
  63. layout.addWidget(self.__simulateCheck, 3, 0, 1, 2)
  64. self.__cancelButton = QPushButton(_("Cancel"), self)
  65. self.__repairButton = QPushButton(_("Repair"), self)
  66. layout.addWidget(self.__cancelButton, 4, 0, 1, 1)
  67. layout.addWidget(self.__repairButton, 4, 1, 1, 1)
  68. self.__cancelButton.clicked.connect(self.reject)
  69. self.__repairButton.clicked.connect(self.__onRepairClicked)
  70. def __onRepairClicked(self):
  71. testMode = True
  72. if not self.__simulateCheck.isChecked():
  73. r = QMessageBox.question(self, _("Continue?"),
  74. _("You can lose your data when anything goes "
  75. "wrong, do you want to continue?"))
  76. if r != QMessageBox.Yes:
  77. return
  78. testMode = False
  79. self.startRepair(testMode=testMode)
  80. def startRepair(self, repairMode=pywwt.REPAIR_ALL, testMode=True):
  81. if self.__repairThread is not None:
  82. print("PartitionSourceModel Already repairing .. FIXME this should not "
  83. "happen! Please report.")
  84. return
  85. self.__repairThread = PartitionRepairThread(
  86. self.__sourceModel.location,
  87. repairMode=repairMode,
  88. testMode=testMode)
  89. self.__repairThread.completed.connect(self.__onRepairComplete)
  90. Global.ActiveThreads.append(self.__repairThread)
  91. self.__repairThread.start()
  92. def __onRepairComplete(self):
  93. self.__repairThread.wait()
  94. Global.ActiveThreads.remove(self.__repairThread)
  95. message = None
  96. if self.__repairThread.result:
  97. QMessageBox.information(self, _("Repair result"),
  98. _("Repair successfull!"))
  99. else:
  100. QMessageBox.critical(self, _("Repair result"),
  101. _(f"Repair failed! {self.__repairThread.error}"))
  102. self.__repairThread.quit()
  103. self.__repairThread = None