A gui application used for interactive upgrade reminders on Debian. I no longer use it and will not push changes.
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

121 lines
4.1 KiB

  1. #!/usr/bin/python3
  2. from PySide2.QtWidgets import (QApplication, QLabel,
  3. QPushButton, QSlider,
  4. QLineEdit, QWidget, QVBoxLayout, QHBoxLayout,
  5. QDialog, QGroupBox, QTabWidget, QErrorMessage,
  6. QListWidgetItem, QGridLayout, QTextEdit,
  7. QComboBox, QToolBar, QInputDialog, QAction,
  8. QStackedWidget, QTextBrowser)
  9. from PySide2.QtCore import (Qt, QThread, Signal, QDir)
  10. from PySide2.QtGui import (QIcon, QMovie)
  11. import sys, subprocess
  12. class UpdatePrompt(QDialog):
  13. def __init__(self):
  14. super().__init__()
  15. self.makeView()
  16. return
  17. def makeView(self):
  18. layout = QVBoxLayout()
  19. btnLayout = QHBoxLayout()
  20. self.centStack = QStackedWidget()
  21. updateButton = QPushButton('Update')
  22. cancelButton = QPushButton('Cancel')
  23. notifyLabel = QLabel('There are updates scheduled')
  24. self.inputBox = QLineEdit()
  25. self.outputBox = QTextBrowser()
  26. #refreshIcon = QIcon.fromTheme('process-working')
  27. self.refreshIcon = QMovie('assets/spin3.gif')
  28. refreshAnimation = QLabel()
  29. layout.addWidget(notifyLabel)
  30. layout.addWidget(self.centStack)
  31. layout.addWidget(self.inputBox)
  32. layout.addLayout(btnLayout)
  33. btnLayout.addWidget(cancelButton)
  34. btnLayout.addWidget(updateButton)
  35. self.centStack.addWidget(refreshAnimation)
  36. self.centStack.addWidget(self.outputBox)
  37. refreshAnimation.setMovie(self.refreshIcon)
  38. refreshAnimation.setAlignment(Qt.AlignCenter)
  39. self.refreshIcon.start()
  40. self.inputBox.setEchoMode(QLineEdit.Password)
  41. self.inputBox.setFocus()
  42. self.inputBox.returnPressed.connect(self.pkgUpdates)
  43. updateButton.clicked.connect(self.pkgUpdates)
  44. cancelButton.clicked.connect(self.cancelUpdates)
  45. self.centStack.setCurrentIndex(1)
  46. notifyLabel.setAlignment(Qt.AlignTop)
  47. self.outputBox.setReadOnly(True)
  48. #self.outputBox.setAlignment(Qt.AlignTop)
  49. self.setWindowTitle('Package Updates')
  50. self.setLayout(layout)
  51. self.resize(450, 250)
  52. return
  53. def pkgUpdates(self):
  54. self.centStack.setCurrentIndex(0)
  55. self.refreshIcon.start()
  56. password = self.inputBox.text()
  57. if (password == ''):
  58. self.passError('The password field cannot be empty')
  59. return
  60. password = password.encode()
  61. result = subprocess.run(['sudo', '-S', 'apt-get', 'update'],
  62. stdout=subprocess.PIPE,
  63. stderr=subprocess.STDOUT, input=password)
  64. stdout = result.stdout.decode()
  65. currentText = self.outputBox.toPlainText()
  66. self.outputBox.setText('Running updates\n' + stdout)
  67. result = subprocess.run(['sudo', '-S', 'apt-get', 'upgrade', '-y'],
  68. stdout=subprocess.PIPE,
  69. stderr=subprocess.STDOUT, input=password)
  70. stdout = result.stdout.decode()
  71. currentText = self.outputBox.toPlainText()
  72. self.outputBox.setText(currentText + '\nRunning upgrades\n' + stdout)
  73. # result = subprocess.run(['sudo', 'apt', 'upgrade', '-y'],
  74. # stdout=subprocess.PIPE,
  75. # stderr=subprocess.STDOUT, input=password)
  76. # currentText = self.outputBox.toPlainText()
  77. # self.outputBox.setText(currentText + '\n' + stdout)
  78. #self.refreshIcon.stop()
  79. self.centStack.setCurrentIndex(1)
  80. return
  81. def passError(self, s):
  82. passError = QDialog(self)
  83. msg = QLabel(s)
  84. layout = QVBoxLayout()
  85. layout.addWidget(msg)
  86. passError.setLayout(layout)
  87. okBtn = QPushButton('OK')
  88. okBtn.clicked.connect(passError.reject)
  89. layout.addWidget(okBtn)
  90. passError.exec_()
  91. return
  92. def cancelUpdates(self):
  93. self.reject()
  94. return
  95. if __name__ == '__main__':
  96. app = QApplication([])
  97. view = UpdatePrompt()
  98. view.show()
  99. sys.exit(app.exec_())