A gui application used for interactive upgrade reminders on Debian. I no longer use it and will not push changes.
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

update.py 4.9 KiB

5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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, QProcess,
  10. QCoreApplication)
  11. from PySide2.QtGui import (QIcon, QMovie)
  12. import sys, subprocess, trio
  13. class UpdatePrompt(QDialog):
  14. def __init__(self):
  15. super().__init__()
  16. self.makeView()
  17. return
  18. def makeView(self):
  19. layout = QVBoxLayout()
  20. btnLayout = QHBoxLayout()
  21. self.centStack = QStackedWidget()
  22. updateButton = QPushButton('Update')
  23. cancelButton = QPushButton('Cancel')
  24. notifyLabel = QLabel('There are updates scheduled')
  25. self.inputBox = QLineEdit()
  26. self.outputBox = QTextBrowser()
  27. #refreshIcon = QIcon.fromTheme('process-working')
  28. self.refreshIcon = QMovie('assets/spin3.gif')
  29. refreshAnimation = QLabel()
  30. layout.addWidget(notifyLabel)
  31. layout.addWidget(self.centStack)
  32. layout.addWidget(self.inputBox)
  33. layout.addLayout(btnLayout)
  34. btnLayout.addWidget(cancelButton)
  35. btnLayout.addWidget(updateButton)
  36. self.centStack.addWidget(refreshAnimation)
  37. self.centStack.addWidget(self.outputBox)
  38. refreshAnimation.setMovie(self.refreshIcon)
  39. refreshAnimation.setAlignment(Qt.AlignCenter)
  40. self.refreshIcon.start()
  41. self.inputBox.setEchoMode(QLineEdit.Password)
  42. self.inputBox.setFocus()
  43. self.inputBox.returnPressed.connect(self.pkgUpdates)
  44. updateButton.clicked.connect(self.pkgUpdates)
  45. cancelButton.clicked.connect(self.cancelUpdates)
  46. self.centStack.setCurrentIndex(1)
  47. notifyLabel.setAlignment(Qt.AlignTop)
  48. self.outputBox.setReadOnly(True)
  49. #self.outputBox.setAlignment(Qt.AlignTop)
  50. self.setWindowTitle('Package Updates')
  51. self.setLayout(layout)
  52. self.resize(450, 250)
  53. return
  54. async def asetup(self, password):
  55. async with trio.open_nursery() as nursery:
  56. finishedState = trio.Event()
  57. nursery.start_soon(self.upProc, password, 'update', finishedState)
  58. #nursery.start_soon(self.KEAlive, finishedState)
  59. return
  60. async def upProc(self, password, cmd, finishedState):
  61. proc = await trio.open_process(['sudo', '-S', 'apt-get', cmd, '-y'],
  62. stdin=subprocess.PIPE, stdout=subprocess.PIPE,
  63. stderr=subprocess.STDOUT)
  64. await proc.stdin.send_all((password + '\n').encode())
  65. while (proc.poll() == None):
  66. QCoreApplication.processEvents()
  67. await trio.sleep(0.1)
  68. result = ''
  69. result = await self.pullOutput(proc)
  70. self.appendToOutput(result)
  71. proc.terminate()
  72. if (cmd == 'update'):
  73. await self.upProc(password, 'upgrade', finishedState)
  74. finishedState.set()
  75. return
  76. async def pullOutput(self, proc):
  77. x = await proc.stdout.receive_some()
  78. x = x.decode()
  79. result = ''
  80. while (x != ''):
  81. QCoreApplication.processEvents()
  82. result = result + x
  83. x = await proc.stdout.receive_some()
  84. x = x.decode()
  85. return result
  86. async def KEAlive(self, finishedState):
  87. while finishedState.is_set():
  88. QCoreApplication.processEvents()
  89. trio.sleep(0.1)
  90. return
  91. return
  92. def appendToOutput(self, add):
  93. currentText = self.outputBox.toPlainText()
  94. self.outputBox.setText(currentText + 'Running updates\n' + add + '\n')
  95. print (add)
  96. return
  97. def pkgUpdates(self):
  98. self.centStack.setCurrentIndex(0)
  99. self.refreshIcon.start()
  100. QCoreApplication.processEvents()
  101. password = self.inputBox.text()
  102. if (password == ''):
  103. self.passError('The password field cannot be empty')
  104. return
  105. trio.run(self.asetup, password)
  106. self.centStack.setCurrentIndex(1)
  107. self.refreshIcon.stop()
  108. return
  109. def passError(self, s):
  110. passError = QDialog(self)
  111. msg = QLabel(s)
  112. layout = QVBoxLayout()
  113. layout.addWidget(msg)
  114. passError.setLayout(layout)
  115. okBtn = QPushButton('OK')
  116. okBtn.clicked.connect(passError.reject)
  117. layout.addWidget(okBtn)
  118. passError.exec_()
  119. return
  120. def cancelUpdates(self):
  121. self.reject()
  122. return
  123. if __name__ == '__main__':
  124. app = QApplication([])
  125. view = UpdatePrompt()
  126. view.show()
  127. sys.exit(app.exec_())