-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_worker.py
executable file
·75 lines (69 loc) · 2.69 KB
/
update_worker.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/python3
# Depend on
# update-notifier-common https://packages.ubuntu.com/disco/update-notifier-common
#
#from PyQt5.QtCore import QProcess
import subprocess
class update_worker_t():
def __init__(self):
#self.m_runner = QProcess()
self.upgrades = 0
self.security_upgrades = 0
self.packages = []
def check_for_updates(self):
apt_check = "/usr/lib/update-notifier/apt-check"
#output = subprocess.call(apt_check)
output = subprocess.check_output(apt_check, stderr=subprocess.STDOUT)
print(output)
print(subprocess.STDOUT)
if (subprocess.STDOUT <= 0):
parts = output.split(b";")
try:
self.upgrades = int(parts[0])
self.security_upgrades = int(parts[1])
except:
print ("PARSING OUTPUT FAILED")
return
else:
print(subprocess.STDOUT)
def check_updates_names(self):
apt_check = "/usr/lib/update-notifier/apt-check"
#output = subprocess.call(apt_check)
output = subprocess.check_output([apt_check, '-p'], stderr=subprocess.STDOUT).decode('utf-8') #it comes in byte
print(output)
print(subprocess.STDOUT)
if (subprocess.STDOUT <= 0):
#parts = output.split(b"\n")
if (output != ""):
try:
#self.packages = int(parts[0])
self.packages = output.split("\n")
self.upgrades = len(self.packages)
except:
print ("PARSING OUTPUT FAILED")
return
else:
self.upgrades = 0
else:
print(subprocess.STDOUT)
''' def check_for_updates(self):
if self.m_runner.state() == QProcess.NotRunning:
apt_check= "/usr/lib/update-notifier/apt-check"
#self.m_runner.finished.connect(self.runner_done)
self.m_runner.start(apt_check)
self.m_runner.waitForFinished()
if (self.m_runner.exitStatus() == QProcess.NormalExit and self.m_runner.exitCode() == 0):
result = self.m_runner.readAllStandardError()
print(result)
parts = result.trimmed().split(";")
try:
self.upgrades = int(parts[0])
self.security_upgrades = int(parts[1])
except:
print ("PARSING OUTPUT FAILED")
return
else:
print("exit status: " + str (self.m_runner.exitStatus()))
print("error code: " + str(self.m_runner.exitCode()))
else:
print ("ALREADY RUNNING")'''