1 | #!/usr/bin/env python3 |
---|
2 | |
---|
3 | import os |
---|
4 | import subprocess |
---|
5 | import sys |
---|
6 | import json |
---|
7 | import platform |
---|
8 | #import socket |
---|
9 | import tempfile |
---|
10 | import time |
---|
11 | import datetime |
---|
12 | import urllib.request |
---|
13 | |
---|
14 | import lliurexstore.storeManager as StoreManager |
---|
15 | |
---|
16 | |
---|
17 | class EpiManager: |
---|
18 | |
---|
19 | def __init__(self): |
---|
20 | |
---|
21 | |
---|
22 | self.storeManager=StoreManager.StoreManager() |
---|
23 | self.reposPath="/etc/apt/sources.list.d/" |
---|
24 | self.sources_list="epi.list" |
---|
25 | self.epi_sources=os.path.join(self.reposPath,self.sources_list) |
---|
26 | self.epi_keyring="/tmp/epi_keyring" |
---|
27 | |
---|
28 | self.order=0 |
---|
29 | self.epiFiles={} |
---|
30 | self.arquitecture=False |
---|
31 | self.update=False |
---|
32 | self.zomando_name={} |
---|
33 | self.epi_base={"repository":[], |
---|
34 | "force32" : False, |
---|
35 | "required_x" : False, |
---|
36 | "script": {}, |
---|
37 | "depends":"", |
---|
38 | "zomando":"", |
---|
39 | "required_root":False, |
---|
40 | "download_byscript":False |
---|
41 | } |
---|
42 | |
---|
43 | #self.read_conf(epi_file) |
---|
44 | |
---|
45 | |
---|
46 | #def __init__ |
---|
47 | |
---|
48 | |
---|
49 | def check_connection(self): |
---|
50 | |
---|
51 | try: |
---|
52 | ''' |
---|
53 | s=socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
---|
54 | host=socket.gethostbyname('lliurex.net') |
---|
55 | result=s.connect_ex((host, 80)) |
---|
56 | s.close() |
---|
57 | if result: |
---|
58 | return False |
---|
59 | |
---|
60 | return True |
---|
61 | ''' |
---|
62 | #req=urllib.request("http://lliurex.net") |
---|
63 | res=urllib.request.urlopen("http://lliurex.net") |
---|
64 | return True |
---|
65 | |
---|
66 | except: |
---|
67 | return False |
---|
68 | |
---|
69 | #def check_connection |
---|
70 | |
---|
71 | def read_conf(self,epi_file): |
---|
72 | |
---|
73 | |
---|
74 | #file=os.path.join(CONF_FOLDER,conf_file) |
---|
75 | #self.zomando_name[self.order]=os.path.splitext(conf_file)[0] |
---|
76 | |
---|
77 | if os.path.exists(epi_file): |
---|
78 | f=open(epi_file) |
---|
79 | epi_load=json.load(f) |
---|
80 | epi_conf=self.epi_base.copy() |
---|
81 | f.close() |
---|
82 | epi_conf.update(epi_load) |
---|
83 | self.epiFiles[self.order]=epi_conf |
---|
84 | self.zomando_name[self.order]=epi_conf["zomando"] |
---|
85 | try: |
---|
86 | if epi_conf["depends"]!="": |
---|
87 | self.order=self.order+1 |
---|
88 | self.read_conf(epi_conf["depends"]) |
---|
89 | except : |
---|
90 | pass |
---|
91 | |
---|
92 | #def read_conf |
---|
93 | |
---|
94 | |
---|
95 | def get_pkg_info(self): |
---|
96 | |
---|
97 | pkg_list=[] |
---|
98 | self.pkg_info={} |
---|
99 | tmp_list=self.epiFiles.copy() |
---|
100 | |
---|
101 | for item in tmp_list: |
---|
102 | pkg_list=[] |
---|
103 | #if tmp_list[item]["type"]!="file": |
---|
104 | pkg_list=tmp_list[item]["pkg_list"] |
---|
105 | |
---|
106 | ''' |
---|
107 | else: |
---|
108 | |
---|
109 | element={} |
---|
110 | element["name"]=tmp_list[item]["name"] |
---|
111 | element["key_store"]=tmp_list[item]["key_store"] |
---|
112 | pkg_list.append(element) |
---|
113 | ''' |
---|
114 | info=self.get_store_info(pkg_list,item) |
---|
115 | |
---|
116 | cont=0 |
---|
117 | |
---|
118 | for element in pkg_list: |
---|
119 | name=element["name"] |
---|
120 | if info[name]["status"]=="installed": |
---|
121 | cont=cont+1 |
---|
122 | |
---|
123 | if cont==len(pkg_list): |
---|
124 | if item>0: |
---|
125 | self.epiFiles.pop(item) |
---|
126 | self.zomando_name.pop(item) |
---|
127 | else: |
---|
128 | self.epiFiles[item]["status"]="installed" |
---|
129 | self.pkg_info.update(info) |
---|
130 | else: |
---|
131 | self.epiFiles[item]["status"]="availabled" |
---|
132 | self.pkg_info.update(info) |
---|
133 | |
---|
134 | #def get_pkg_info |
---|
135 | |
---|
136 | |
---|
137 | def get_store_info(self,pkg_list,order): |
---|
138 | |
---|
139 | pkg_info={} |
---|
140 | |
---|
141 | for item in pkg_list: |
---|
142 | app=item["name"] |
---|
143 | name="" |
---|
144 | summary="" |
---|
145 | status="" |
---|
146 | description="" |
---|
147 | icon="" |
---|
148 | debian_name="" |
---|
149 | component="" |
---|
150 | pkg=item["key_store"] |
---|
151 | action="info" |
---|
152 | self.storeManager.execute_action(action,pkg) |
---|
153 | while self.storeManager.is_action_running(action): |
---|
154 | time.sleep(0.2) |
---|
155 | |
---|
156 | ret=self.storeManager.get_status(action) |
---|
157 | |
---|
158 | if ret["status"]==0: |
---|
159 | data=self.storeManager.get_result(action) |
---|
160 | |
---|
161 | if len(data)>0: |
---|
162 | if (data["info"][0]["state"]) !="": |
---|
163 | status=data["info"][0]["state"] |
---|
164 | else: |
---|
165 | status=self.check_pkg_status(app,order) |
---|
166 | |
---|
167 | |
---|
168 | description=data["info"][0]["description"] |
---|
169 | icon=data["info"][0]["icon"] |
---|
170 | name=data["info"][0]["name"] |
---|
171 | summary=data["info"][0]["summary"] |
---|
172 | debian_name=data["info"][0]["package"] |
---|
173 | component=data["info"][0]["component"] |
---|
174 | |
---|
175 | else: |
---|
176 | status=self.check_pkg_status(app,order) |
---|
177 | else: |
---|
178 | status=self.check_pkg_status(app,order) |
---|
179 | |
---|
180 | pkg_info[app]={} |
---|
181 | pkg_info[app]["debian_name"]=debian_name |
---|
182 | pkg_info[app]["component"]=component |
---|
183 | pkg_info[app]["status"]=status |
---|
184 | pkg_info[app]["description"]=description |
---|
185 | pkg_info[app]["icon"]=icon |
---|
186 | pkg_info[app]["name"]=name |
---|
187 | pkg_info[app]["summary"]=summary |
---|
188 | |
---|
189 | return pkg_info |
---|
190 | |
---|
191 | #def get_store_info |
---|
192 | |
---|
193 | def check_pkg_status(self,pkg,order=None): |
---|
194 | |
---|
195 | |
---|
196 | cmd='dpkg -l '+ pkg + '| grep "^i[i]"' |
---|
197 | p=subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE) |
---|
198 | poutput,perror=p.communicate() |
---|
199 | |
---|
200 | if len(poutput)>0: |
---|
201 | return "installed" |
---|
202 | else: |
---|
203 | if order !=None: |
---|
204 | if len(self.epiFiles[order]["script"])>0: |
---|
205 | try: |
---|
206 | if self.epiFiles[order]["script"]["getStatus"]: |
---|
207 | |
---|
208 | if os.path.exists(self.epiFiles[order]["script"]["name"]): |
---|
209 | cmd=self.epiFiles[order]["script"]["name"] +' getStatus'; |
---|
210 | p=subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE) |
---|
211 | poutput=p.communicate() |
---|
212 | if len(poutput)>0: |
---|
213 | if poutput[0].decode("utf-8").split("\n")[0]=='0': |
---|
214 | return "installed" |
---|
215 | |
---|
216 | except Exception as e: |
---|
217 | print (str(e)) |
---|
218 | pass |
---|
219 | |
---|
220 | return "available" |
---|
221 | |
---|
222 | #def check_pkg_status |
---|
223 | |
---|
224 | def check_root(self): |
---|
225 | |
---|
226 | self.root=False |
---|
227 | |
---|
228 | try: |
---|
229 | f=open("/etc/epi.token","w") |
---|
230 | f.close() |
---|
231 | os.remove("/etc/epi.token") |
---|
232 | self.download_path="/var/cache/epi-downloads" |
---|
233 | self.root=True |
---|
234 | except: |
---|
235 | if not os.path.exists(os.path.expanduser("~/.cache/epi-downloads/")): |
---|
236 | os.mkdir(os.path.expanduser("~/.cache/epi-downloads/")) |
---|
237 | self.download_path=os.path.expanduser("~/.cache/epi-downloads/") |
---|
238 | |
---|
239 | #def check_root |
---|
240 | |
---|
241 | |
---|
242 | def required_root (self): |
---|
243 | |
---|
244 | cont=0 |
---|
245 | |
---|
246 | if not self.root: |
---|
247 | for item in self.epiFiles: |
---|
248 | if self.epiFiles[item]["type"]!="file": |
---|
249 | cont=cont+1 |
---|
250 | |
---|
251 | else: |
---|
252 | if self.epiFiles[item]["required_root"]: |
---|
253 | cont=cont+1 |
---|
254 | |
---|
255 | if cont>0: |
---|
256 | return True |
---|
257 | else: |
---|
258 | return False |
---|
259 | |
---|
260 | else: |
---|
261 | return False |
---|
262 | |
---|
263 | #def required_root |
---|
264 | |
---|
265 | |
---|
266 | |
---|
267 | def check_update_repos(self): |
---|
268 | |
---|
269 | #Only update repos if needed |
---|
270 | current_date=datetime.date.today().strftime('%y%m%d') |
---|
271 | filename='/var/cache/apt/pkgcache.bin' |
---|
272 | lastmod=os.path.getmtime(filename) |
---|
273 | lastupdate=datetime.datetime.fromtimestamp(lastmod).strftime('%y%m%d') |
---|
274 | cmd="" |
---|
275 | |
---|
276 | if current_date !=lastupdate or self.update: |
---|
277 | cmd="LANG=C LANGUAGE=en apt-get update; " |
---|
278 | else: |
---|
279 | for item in self.epi_conf["pkg_list"]: |
---|
280 | app=item["name"] |
---|
281 | command="LANG=C LANGUAGE=en apt-cache policy %s"%app |
---|
282 | p=subprocess.Popen(command,shell=True, stdout=subprocess.PIPE) |
---|
283 | output=p.communicate() |
---|
284 | if str(output[0]) != '': |
---|
285 | if str(output[0]).split("\\n")[2].split(":")[1]=="": |
---|
286 | cmd="LANG=C LANGUAGE=en apt-get update; " |
---|
287 | return cmd |
---|
288 | |
---|
289 | else: |
---|
290 | cmd="LANG=C LANGUAGE=en apt-get update; " |
---|
291 | return cmd |
---|
292 | |
---|
293 | return cmd |
---|
294 | |
---|
295 | |
---|
296 | |
---|
297 | def check_arquitecture(self): |
---|
298 | |
---|
299 | self.force32=self.epi_conf['force32'] |
---|
300 | cmd="" |
---|
301 | |
---|
302 | if self.force32: |
---|
303 | if platform.architecture()[0]=='64bit': |
---|
304 | cmd='dpkg --add-architecture i386; ' |
---|
305 | |
---|
306 | self.arquitecture=True |
---|
307 | return cmd |
---|
308 | |
---|
309 | #def check_arquitecture |
---|
310 | |
---|
311 | def add_repository_keys(self,order): |
---|
312 | |
---|
313 | self.epi_conf=self.epiFiles[order] |
---|
314 | |
---|
315 | cmd="" |
---|
316 | self.type=self.epi_conf["type"] |
---|
317 | |
---|
318 | if self.type=="apt": |
---|
319 | |
---|
320 | repos_list=self.epi_conf["repository"] |
---|
321 | |
---|
322 | if len(repos_list)>0: |
---|
323 | f = open(self.epi_sources,'w') |
---|
324 | for item in repos_list: |
---|
325 | if item["url"]!="": |
---|
326 | f.write(item["url"]+'\n') |
---|
327 | try: |
---|
328 | key_cmd=item["key_cmd"] |
---|
329 | if key_cmd !="": |
---|
330 | cmd=cmd+key_cmd+';' |
---|
331 | except Exception as e: |
---|
332 | if len(self.epi_conf["script"])>0: |
---|
333 | try: |
---|
334 | if self.epi_conf["script"]["addRepoKeys"]: |
---|
335 | if os.path.exists(self.epi_conf["script"]["name"]): |
---|
336 | command=self.epi_conf["script"]["name"] + ' addRepoKeys;' |
---|
337 | cmd=cmd+command |
---|
338 | except Exception as e: |
---|
339 | print (str(e)) |
---|
340 | pass |
---|
341 | |
---|
342 | f.close() |
---|
343 | self.update=True |
---|
344 | |
---|
345 | |
---|
346 | return cmd |
---|
347 | |
---|
348 | #def add_repository_keys |
---|
349 | |
---|
350 | |
---|
351 | def get_app_version(self,item=None): |
---|
352 | |
---|
353 | self.force32=self.epi_conf["force32"] |
---|
354 | |
---|
355 | if self.force32: |
---|
356 | |
---|
357 | #if self.type=="deb": |
---|
358 | version=item["version"]["32b"] |
---|
359 | ''' |
---|
360 | else: |
---|
361 | version=self.epi_conf["version"]["32b"] |
---|
362 | ''' |
---|
363 | else: |
---|
364 | #if self.type=="deb": |
---|
365 | if item["version"]["all"]=="": |
---|
366 | version=item["version"]["64b"] |
---|
367 | else: |
---|
368 | version=item["version"]["all"] |
---|
369 | ''' |
---|
370 | else: |
---|
371 | if self.epi_conf["version"]["all"]=="": |
---|
372 | version=self.epi_conf["version"]["64b"] |
---|
373 | else: |
---|
374 | version=self.epi_conf["version"]["all"] |
---|
375 | ''' |
---|
376 | return version |
---|
377 | |
---|
378 | #def get_app_version |
---|
379 | |
---|
380 | def download_app(self): |
---|
381 | |
---|
382 | manage_download=True |
---|
383 | self.download_folder={} |
---|
384 | cmd="" |
---|
385 | |
---|
386 | self.type=self.epi_conf["type"] |
---|
387 | if self.type !='apt': |
---|
388 | |
---|
389 | self.token_result_download=tempfile.mkstemp("_result_download") |
---|
390 | |
---|
391 | |
---|
392 | if self.type=="file": |
---|
393 | if self.epi_conf["download_byscript"]: |
---|
394 | manage_download=False |
---|
395 | |
---|
396 | |
---|
397 | if manage_download: |
---|
398 | |
---|
399 | for item in self.epi_conf["pkg_list"]: |
---|
400 | version=self.get_app_version(item) |
---|
401 | if self.type=="deb": |
---|
402 | name=item["name"]+".deb" |
---|
403 | tmp_file=os.path.join(self.download_path,name) |
---|
404 | else: |
---|
405 | name=item["name"] |
---|
406 | tmp_file=os.path.join(self.download_path,version) |
---|
407 | |
---|
408 | url=item["url_download"] |
---|
409 | |
---|
410 | if os.path.exists(tmp_file): |
---|
411 | cmd=cmd+'rm -f '+ tmp_file +';' |
---|
412 | self.download_folder["name"]=tmp_file |
---|
413 | cmd=cmd+'wget ' +url+version + ' --progress=bar:force -O ' + tmp_file +'; ' |
---|
414 | #cmd=cmd+'curl -o ' + tmp_file +' -C - '+ url + version |
---|
415 | |
---|
416 | cmd=cmd + ' echo $? >' + self.token_result_download[1] +';' |
---|
417 | ''' |
---|
418 | if self.type=="deb": |
---|
419 | |
---|
420 | for item in self.epi_conf["pkg_list"]: |
---|
421 | name=item["name"]+".deb" |
---|
422 | version=self.get_app_version(item) |
---|
423 | url=item["url_download"] |
---|
424 | tmp_file=os.path.join(self.download_path,name) |
---|
425 | if os.path.exists(tmp_file): |
---|
426 | cmd=cmd+'rm -f '+ tmp_file +';' |
---|
427 | self.download_folder["name"]=tmp_file |
---|
428 | #cmd=cmd+'wget ' +url+version + ' --progress=bar:force -O ' + tmp_file |
---|
429 | cmd=cmd+'curl -o ' + tmp_file +' -C - '+ url + version |
---|
430 | |
---|
431 | cmd=cmd + '; echo $? >' + self.token_result_download[1] +';' |
---|
432 | |
---|
433 | else: |
---|
434 | if self.epi_conf["url_download"]!="": |
---|
435 | name=self.epi_conf["name"] |
---|
436 | version=self.get_app_version() |
---|
437 | url=self.epi_conf["url_download"] |
---|
438 | tmp_file=os.path.join(self.download_path,version) |
---|
439 | if os.path.exists(tmp_file): |
---|
440 | cmd=cmd+'rm -f '+ tmp_file +';' |
---|
441 | self.download_folder["name"]=tmp_file |
---|
442 | #cmd=cmd+'wget ' +url+version + ' --progress=bar:force -O ' + tmp_file + '; echo $? >' + self.token_result_download[1] +';' |
---|
443 | cmd=cmd+'curl -o ' + tmp_file +' -C - '+ url + version + '; echo $? >' + self.token_result_download[1] +';' |
---|
444 | |
---|
445 | ''' |
---|
446 | |
---|
447 | return cmd |
---|
448 | |
---|
449 | #def download_app |
---|
450 | |
---|
451 | |
---|
452 | def check_download(self): |
---|
453 | |
---|
454 | |
---|
455 | result=True |
---|
456 | |
---|
457 | if self.type !='apt': |
---|
458 | |
---|
459 | if os.path.exists(self.token_result_download[1]): |
---|
460 | file=open(self.token_result_download[1]) |
---|
461 | content=file.readline() |
---|
462 | if '0' not in content: |
---|
463 | result=False |
---|
464 | file.close() |
---|
465 | os.remove(self.token_result_download[1]) |
---|
466 | |
---|
467 | if result: |
---|
468 | |
---|
469 | pkgs_todownload=len(self.download_folder) |
---|
470 | cont=0 |
---|
471 | |
---|
472 | for item in self.download_folder: |
---|
473 | if os.path.exists(self.download_folder[item]): |
---|
474 | cont=cont+1 |
---|
475 | |
---|
476 | if cont != pkgs_todownload: |
---|
477 | result=False |
---|
478 | |
---|
479 | return result |
---|
480 | |
---|
481 | #def check_download |
---|
482 | |
---|
483 | def preinstall_app(self): |
---|
484 | |
---|
485 | |
---|
486 | cmd="" |
---|
487 | |
---|
488 | if len(self.epi_conf["script"])>0: |
---|
489 | self.token_result_preinstall=tempfile.mkstemp("_result_preinstall") |
---|
490 | script=self.epi_conf["script"]["name"] |
---|
491 | if os.path.exists(script): |
---|
492 | cmd=script +' preInstall; echo $? >' + self.token_result_preinstall[1] +';' |
---|
493 | |
---|
494 | return cmd |
---|
495 | |
---|
496 | |
---|
497 | def check_preinstall(self): |
---|
498 | |
---|
499 | result=True |
---|
500 | |
---|
501 | try: |
---|
502 | if os.path.exists(self.token_result_preinstall[1]): |
---|
503 | file=open(self.token_result_preinstall[1]) |
---|
504 | content=file.readline() |
---|
505 | if '0' not in content: |
---|
506 | result=False |
---|
507 | file.close() |
---|
508 | os.remove(self.token_result_preinstall[1]) |
---|
509 | |
---|
510 | except: |
---|
511 | pass |
---|
512 | |
---|
513 | return result |
---|
514 | |
---|
515 | |
---|
516 | #def preinstall_app |
---|
517 | |
---|
518 | def install_app(self): |
---|
519 | |
---|
520 | add_i386="" |
---|
521 | |
---|
522 | if not self.arquitecture: |
---|
523 | add_i386=self.check_arquitecture() |
---|
524 | |
---|
525 | |
---|
526 | cmd="" |
---|
527 | |
---|
528 | if self.type=="apt": |
---|
529 | |
---|
530 | update_repos=self.check_update_repos() |
---|
531 | cmd=update_repos+add_i386 + "LANG=C LANGUAGE=en DEBIAN_FRONTEND=noninteractive apt-get install --reinstall --allow-downgrades --allow-remove-essential --allow-change-held-packages --yes " |
---|
532 | for item in self.epi_conf["pkg_list"]: |
---|
533 | app=item["name"] |
---|
534 | cmd=cmd + app +";" |
---|
535 | |
---|
536 | |
---|
537 | |
---|
538 | elif self.type=="deb": |
---|
539 | |
---|
540 | cmd=add_i386 + "dpkg -i " |
---|
541 | for item in self.epi_conf["pkg_list"]: |
---|
542 | name=item["name"]+".deb" |
---|
543 | pkg=self.download_folder["name"] |
---|
544 | cmd=cmd+pkg +";" |
---|
545 | |
---|
546 | |
---|
547 | else: |
---|
548 | self.token_result_install=tempfile.mkstemp("_result") |
---|
549 | script=self.epi_conf["script"]["name"] |
---|
550 | if os.path.exists(script): |
---|
551 | cmd=script + ' install; echo $? >' + self.token_result_install[1] +';' |
---|
552 | |
---|
553 | |
---|
554 | return cmd |
---|
555 | |
---|
556 | #def install_app |
---|
557 | |
---|
558 | |
---|
559 | def check_install_remove(self,action): |
---|
560 | |
---|
561 | dpkg_status={} |
---|
562 | cont=0 |
---|
563 | token="" |
---|
564 | |
---|
565 | if action=="install": |
---|
566 | |
---|
567 | if self.type !="file": |
---|
568 | pkgs=self.epi_conf["pkg_list"] |
---|
569 | |
---|
570 | for item in pkgs: |
---|
571 | status=self.check_pkg_status(item["name"]) |
---|
572 | |
---|
573 | if status=="installed": |
---|
574 | cont=cont+1 |
---|
575 | |
---|
576 | dpkg_status[item["name"]]=status |
---|
577 | |
---|
578 | if cont==len(pkgs): |
---|
579 | result=True |
---|
580 | |
---|
581 | else: |
---|
582 | result=False |
---|
583 | |
---|
584 | else: |
---|
585 | token=self.token_result_install[1] |
---|
586 | if os.path.exists(token): |
---|
587 | file=open(token) |
---|
588 | content=file.readline() |
---|
589 | if '0' not in content: |
---|
590 | result=False |
---|
591 | else: |
---|
592 | result=True |
---|
593 | |
---|
594 | file.close() |
---|
595 | os.remove(token) |
---|
596 | |
---|
597 | else: |
---|
598 | |
---|
599 | if self.epiFiles[0]["type"] !="file": |
---|
600 | pkgs=self.epiFiles[0]["pkg_list"] |
---|
601 | for item in pkgs: |
---|
602 | status=self.check_pkg_status(item["name"]) |
---|
603 | if status!="installed": |
---|
604 | cont=cont+1 |
---|
605 | dpkg_status[item["name"]]=status |
---|
606 | |
---|
607 | |
---|
608 | token=self.token_result_remove[1] |
---|
609 | if os.path.exists(token): |
---|
610 | file=open(token) |
---|
611 | content=file.readline() |
---|
612 | if '0' not in content: |
---|
613 | result=False |
---|
614 | else: |
---|
615 | result=True |
---|
616 | |
---|
617 | file.close() |
---|
618 | os.remove(token) |
---|
619 | |
---|
620 | return dpkg_status,result |
---|
621 | |
---|
622 | |
---|
623 | |
---|
624 | #def check_install_remove |
---|
625 | |
---|
626 | def postinstall_app(self): |
---|
627 | |
---|
628 | |
---|
629 | cmd="" |
---|
630 | |
---|
631 | if len(self.epi_conf["script"])>0: |
---|
632 | self.token_result_postinstall=tempfile.mkstemp("_result_postinstall") |
---|
633 | script=self.epi_conf["script"]["name"] |
---|
634 | if os.path.exists(script): |
---|
635 | cmd=script + ' postInstall; echo $? >' + self.token_result_postinstall[1] +';' |
---|
636 | |
---|
637 | return cmd |
---|
638 | |
---|
639 | #def postinstall_app |
---|
640 | |
---|
641 | def check_postinstall(self): |
---|
642 | |
---|
643 | result=True |
---|
644 | |
---|
645 | try: |
---|
646 | if os.path.exists(self.token_result_postinstall[1]): |
---|
647 | file=open(self.token_result_postinstall[1]) |
---|
648 | content=file.readline() |
---|
649 | if '0' not in content: |
---|
650 | result=False |
---|
651 | file.close() |
---|
652 | os.remove(self.token_result_postinstall[1]) |
---|
653 | except: |
---|
654 | pass |
---|
655 | |
---|
656 | return result |
---|
657 | |
---|
658 | #def check_postinstall |
---|
659 | |
---|
660 | def remove_repo_keys(self): |
---|
661 | |
---|
662 | if os.path.exists(self.epi_sources): |
---|
663 | os.remove(self.epi_sources) |
---|
664 | |
---|
665 | if os.path.exists(self.epi_keyring): |
---|
666 | os.remove(self.epi_keyring) |
---|
667 | |
---|
668 | #def remove_repo_keys |
---|
669 | |
---|
670 | def unistall_app(self,order): |
---|
671 | |
---|
672 | cmd="" |
---|
673 | |
---|
674 | if self.epiFiles[order]["script"]["remove"]: |
---|
675 | self.token_result_remove=tempfile.mkstemp("_result_remove") |
---|
676 | script=self.epiFiles[order]["script"]["name"] |
---|
677 | if os.path.exists(script): |
---|
678 | cmd=script + ' Remove; echo $? >' + self.token_result_remove[1] + ';' |
---|
679 | |
---|
680 | return cmd |
---|
681 | |
---|
682 | def zerocenter_feedback(self,order,action,result=None): |
---|
683 | |
---|
684 | zomando_name=self.zomando_name[order] |
---|
685 | |
---|
686 | if zomando_name!="": |
---|
687 | if action=="init": |
---|
688 | cmd="zero-center add-pulsating-color " +zomando_name |
---|
689 | elif action=="install": |
---|
690 | if result: |
---|
691 | cmd="zero-center remove-pulsating-color "+zomando_name + " ;zero-center set-configured " +zomando_name |
---|
692 | |
---|
693 | else: |
---|
694 | cmd="zero-center remove-pulsating-color "+zomando_name + " ;zero-center set-failed " +zomando_name |
---|
695 | elif action=="uninstall": |
---|
696 | if result: |
---|
697 | cmd="zero-center remove-pulsating-color "+zomando_name + " ;zero-center set-non-configured " +zomando_name |
---|
698 | else: |
---|
699 | cmd="zero-center remove-pulsating-color "+zomando_name + " ;zero-center set-failed " +zomando_name |
---|
700 | |
---|
701 | os.system(cmd) |
---|
702 | |
---|
703 | #def zero-center_feedback |
---|
704 | |
---|
705 | |
---|
706 | #class ApplicationInstallerManager |
---|
707 | |
---|
708 | |
---|
709 | if __name__=="__main__": |
---|
710 | |
---|
711 | epi=EpiManager() |
---|