1 | import xmlrpclib |
---|
2 | import os |
---|
3 | import shutil |
---|
4 | import subprocess |
---|
5 | import socket |
---|
6 | import threading |
---|
7 | import datetime |
---|
8 | from math import pi |
---|
9 | |
---|
10 | import LliurexUpCore |
---|
11 | |
---|
12 | from gi.repository import Gtk, Gdk, GObject, GLib, PangoCairo, Pango |
---|
13 | |
---|
14 | import signal |
---|
15 | signal.signal(signal.SIGINT, signal.SIG_DFL) |
---|
16 | |
---|
17 | |
---|
18 | class LliurexUpConnect(): |
---|
19 | |
---|
20 | def __init__(self): |
---|
21 | self.llxUpCore=LliurexUpCore.LliurexUpCore() |
---|
22 | GObject.threads_init() |
---|
23 | log_msg="------------------------------------------\n"+"LLIUREX-UP STARTING AT: " + datetime.datetime.today().strftime("%d/%m/%y %H:%M:%S") +"\n------------------------------------------" |
---|
24 | self.log(log_msg) |
---|
25 | self.checkInitialFlavour() |
---|
26 | |
---|
27 | |
---|
28 | #def __init__ |
---|
29 | |
---|
30 | |
---|
31 | def checkInitialFlavour(self): |
---|
32 | self.targetMetapackage=None |
---|
33 | try: |
---|
34 | self.targetMetapackage=self.llxUpCore.checkFlavour() |
---|
35 | log_msg="Initial check metapackage. Metapackage to install: " + str(self.targetMetapackage) |
---|
36 | self.log(log_msg) |
---|
37 | self.previousFlavours=self.llxUpCore.previuosFlavours |
---|
38 | log_msg="Get initial flavours: " + str(self.previousFlavours) |
---|
39 | self.log(log_msg) |
---|
40 | self.flavours=self.llxUpCore.flavours |
---|
41 | log_msg="Get update flavours " + str(self.flavours) |
---|
42 | self.log(log_msg) |
---|
43 | |
---|
44 | except Exception as e: |
---|
45 | log_msg="Initial check metapackage. Error: " + str(e) |
---|
46 | self.log(log_msg) |
---|
47 | |
---|
48 | return self.targetMetapackage |
---|
49 | |
---|
50 | #def checkFlavoour |
---|
51 | |
---|
52 | def requiresInstallFlavour(self): |
---|
53 | |
---|
54 | flavourToInstall=None |
---|
55 | if self.targetMetapackage !=None: |
---|
56 | flavourToInstall=self.targetMetapackage |
---|
57 | log_msg="Requires Install this flavour: " + str(flavourToInstall) |
---|
58 | self.log(log_msg) |
---|
59 | else: |
---|
60 | if self.previousFlavours==self.flavours: |
---|
61 | log_msg="Requires Install Flavour: No" |
---|
62 | self.log(log_msg) |
---|
63 | else: |
---|
64 | log_msg="Requires Install Flavour: Yes" |
---|
65 | self.log(log_msg) |
---|
66 | |
---|
67 | return flavourToInstall |
---|
68 | |
---|
69 | |
---|
70 | def canConnectToLliurexNet(self): |
---|
71 | |
---|
72 | try: |
---|
73 | can_connect=self.llxUpCore.canConnectToLliurexNet() |
---|
74 | if can_connect: |
---|
75 | return True |
---|
76 | else: |
---|
77 | return False |
---|
78 | except: |
---|
79 | return False |
---|
80 | |
---|
81 | #def canConnectToLliurexNet |
---|
82 | |
---|
83 | def isLliurexUpIsUpdated(self): |
---|
84 | |
---|
85 | try: |
---|
86 | is_lliurexup_updated=self.llxUpCore.isLliurexUpIsUpdated() |
---|
87 | log_msg="Checking lliurex-up. Is lliurex-up updated: "+ str(is_lliurexup_updated) |
---|
88 | self.log(log_msg) |
---|
89 | return is_lliurexup_updated |
---|
90 | |
---|
91 | except Exception as e: |
---|
92 | log_msg="Checking lliurex-up. Error: " + str(e) |
---|
93 | self.log(log_msg) |
---|
94 | return True |
---|
95 | |
---|
96 | #def isLliurexUpIsUpdated |
---|
97 | |
---|
98 | def installLliurexUp(self): |
---|
99 | |
---|
100 | try: |
---|
101 | is_lliurexup_installed=self.llxUpCore.installLliurexUp() |
---|
102 | log_msg="Installing lliurex-up: " + str(is_lliurexup_installed) |
---|
103 | self.log(log_msg) |
---|
104 | return is_lliurexup_installed |
---|
105 | |
---|
106 | except Exception as e: |
---|
107 | log_msg="Installing lliurex-up. Error: " + str(e) |
---|
108 | self.log(log_msg) |
---|
109 | return True |
---|
110 | |
---|
111 | #def installLliurexUp |
---|
112 | |
---|
113 | |
---|
114 | def lliurexMirrorIsUpdated(self): |
---|
115 | |
---|
116 | try: |
---|
117 | is_mirror_updated=self.llxUpCore.lliurexMirrorIsUpdated() |
---|
118 | |
---|
119 | if is_mirror_updated !=None: |
---|
120 | |
---|
121 | if is_mirror_updated['action']=='update': |
---|
122 | log_msg="Checking mirror. Is mirror update: False" |
---|
123 | self.log(log_msg) |
---|
124 | return False |
---|
125 | else: |
---|
126 | log_msg="Checking mirror. Is mirror update: " + is_mirror_updated['action'] |
---|
127 | self.log(log_msg) |
---|
128 | return True |
---|
129 | else: |
---|
130 | log_msg="Checking mirror. Is mirror update: None" |
---|
131 | self.log(log_msg) |
---|
132 | return True |
---|
133 | |
---|
134 | |
---|
135 | except Exception as e: |
---|
136 | log_msg="Checking mirror. Error: " + str(e) |
---|
137 | self.log(log_msg) |
---|
138 | return True |
---|
139 | |
---|
140 | #def lliurexMirrorIsUpdated |
---|
141 | |
---|
142 | def lliurexMirrorIsRunning(self): |
---|
143 | |
---|
144 | try: |
---|
145 | is_lliurexmirror_running=self.llxUpCore.lliurexMirrorIsRunning() |
---|
146 | return is_lliurexmirror_running |
---|
147 | |
---|
148 | except Exception as e: |
---|
149 | log_msg="Updating mirror. Error: " + str(e) |
---|
150 | self.log(log_msg) |
---|
151 | return False |
---|
152 | |
---|
153 | #def lliurexMirrorIsRunning |
---|
154 | |
---|
155 | def getPercentageLliurexMirror(self): |
---|
156 | |
---|
157 | try: |
---|
158 | percentage_mirror=self.llxUpCore.getPercentageLliurexMirror() |
---|
159 | if percentage_mirror != None: |
---|
160 | return percentage_mirror |
---|
161 | else: |
---|
162 | return 0 |
---|
163 | |
---|
164 | except Exception as e: |
---|
165 | return 0 |
---|
166 | |
---|
167 | |
---|
168 | #def getPercentageLliurexMirror |
---|
169 | |
---|
170 | def getLliurexVersionLocal(self): |
---|
171 | |
---|
172 | try: |
---|
173 | self.lliurexVersionLocal=self.llxUpCore.getLliurexVersionLocal()["candidate"] |
---|
174 | log_msg="Get LliurexVersion from Local repository: " + self.lliurexVersionLocal |
---|
175 | self.log(log_msg) |
---|
176 | |
---|
177 | |
---|
178 | except Exception as e: |
---|
179 | log_msg="Get LliurexVersion from Local repository. Error: " + str(e) |
---|
180 | self.log(log_msg) |
---|
181 | self.lliurexVersionLocal=None |
---|
182 | |
---|
183 | return self.lliurexVersionLocal |
---|
184 | |
---|
185 | def getLliurexVersionNet(self): |
---|
186 | |
---|
187 | try: |
---|
188 | self.lliurexVersionNet=self.llxUpCore.getLliurexVersionLliurexNet()["candidate"] |
---|
189 | log_msg="Get LliurexVersion from Lliurex Net: " + self.lliurexVersionNet |
---|
190 | self.log(log_msg) |
---|
191 | |
---|
192 | |
---|
193 | except Exception as e: |
---|
194 | log_msg="Get LliurexVersion from Lliurex Net. Error: " + str(e) |
---|
195 | self.log(log_msg) |
---|
196 | self.lliurexVersionNet=None |
---|
197 | |
---|
198 | return self.lliurexVersionNet |
---|
199 | |
---|
200 | |
---|
201 | def getPackagesToUpdate(self): |
---|
202 | |
---|
203 | try: |
---|
204 | packages_parse=[] |
---|
205 | packages=self.llxUpCore.getPackagesToUpdate() |
---|
206 | if len(packages)>0: |
---|
207 | for item in packages: |
---|
208 | version=packages[item] |
---|
209 | packages_parse.append(item+";"+version['candidate']+";"+'20Mb') |
---|
210 | |
---|
211 | log_msg="Get packages to update: OK" |
---|
212 | self.log(log_msg) |
---|
213 | return packages_parse |
---|
214 | |
---|
215 | except Exception as e: |
---|
216 | log_msg="Get packages to update. Error: " + str(e) |
---|
217 | self.log(log_msg) |
---|
218 | return packages_parse |
---|
219 | |
---|
220 | |
---|
221 | def checkFinalFlavour(self): |
---|
222 | self.targetMetapackage=None |
---|
223 | |
---|
224 | try: |
---|
225 | self.targetMetapackage=self.llxUpCore.checkFlavour() |
---|
226 | log_msg="Final check metapackage. Metapackage to install: " + str(targetMetapackage) |
---|
227 | self.log(log_msg) |
---|
228 | except Exception as e: |
---|
229 | log_msg="Final check metapackage. Error: " + str(e) |
---|
230 | self.log(log_msg) |
---|
231 | |
---|
232 | return self.targetMetapackage |
---|
233 | |
---|
234 | #def getPackagesToUpdate |
---|
235 | |
---|
236 | def log(self,msg): |
---|
237 | |
---|
238 | log_file="/var/log/lliurex-up.log" |
---|
239 | f=open(log_file,"a+") |
---|
240 | f.write(msg + '\n') |
---|
241 | f.close() |
---|
242 | |
---|
243 | #def log |
---|