Changeset 8223 for lliurex-store/trunk/fuentes
- Timestamp:
- Nov 2, 2018, 9:15:56 AM (2 years ago)
- Location:
- lliurex-store/trunk/fuentes
- Files:
-
- 1 added
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
lliurex-store/trunk/fuentes/debian/changelog
r8186 r8223 1 lliurex-store (0.7) xenial; urgency=medium 2 3 * Implemented cache for package info 4 5 -- Juanma Navarro Mañez <juanma1980@gmail.com> Fri, 02 Nov 2018 09:15:13 +0100 6 1 7 lliurex-store (0.6.2) xenial; urgency=medium 2 8 -
lliurex-store/trunk/fuentes/lliurex-store-cli/usr/share/lliurex-store/lliurex-store-cli.py
r8182 r8223 130 130 appimage=False 131 131 snap=False 132 autostart=True 132 133 args=process_Args(sys.argv) 133 134 # if args.debug: … … 137 138 if args.snap: 138 139 snap=True 140 if args.update: 141 actions.append('cache') 142 parms['cache']=None 143 autostart=False 139 144 if args.view: 140 145 actions.append('info') … … 152 157 # actions.append('random') 153 158 # parms['random']=args.random 154 if args.list:155 actions.append('list')156 parms['list']=args.list157 158 actionList={'search':False,'info':False,'pkgInfo':False,'install':False,'remove':False,'list':False,'list-sections':False,'random':False }159 # if args.list: 160 # actions.append('list') 161 # parms['list']=args.list 162 163 actionList={'search':False,'info':False,'pkgInfo':False,'install':False,'remove':False,'list':False,'list-sections':False,'random':False,'cache':False} 159 164 start_time=time.time() 160 store=storeManager.StoreManager(appimage=appimage,snap=snap,dbg=dbg, cli=True)165 store=storeManager.StoreManager(appimage=appimage,snap=snap,dbg=dbg,autostart=autostart,cli=True) 161 166 for action in actions: 162 167 th=threading.Thread(target=store.execute_action, args = (action,parms[action])) … … 200 205 parser.add_argument('--appimage',action='store_true',help=(_(u"Load appimage catalog"))) 201 206 parser.add_argument('--snap',action='store_true',help=(_(u"Load snap catalog"))) 202 parser.add_argument('--list',metavar='list',nargs='?',help=(_(u"List category"))) 207 parser.add_argument('--update',action='store_true',help=(_(u"Update cache"))) 208 # parser.add_argument('--list',metavar='list',nargs='?',help=(_(u"List category"))) 203 209 204 210 args=parser.parse_args() -
lliurex-store/trunk/fuentes/python3-lliurex-store.install/usr/share/lliurexstore/plugins/appImageManager.py
r8185 r8223 48 48 def set_debug(self,dbg=True): 49 49 self.dbg=dbg 50 self._debug ("Debug enabled")50 #self._debug ("Debug enabled") 51 51 #def set_debug 52 52 … … 58 58 def register(self): 59 59 return(self.plugin_actions) 60 #def register 60 61 61 62 def enable(self,state=False): 62 63 self.disable=state 64 #def enable 63 65 64 66 def execute_action(self,action,applist=None,store=None): … … 80 82 if action=='load': 81 83 self._load_appimage_store(self.store) 82 #wait till threads end (if any) 83 self._debug("Ending threads...") 84 for th in threading.enumerate(): 85 if th.is_alive(): 86 try: 87 th.join(5) 88 except: 89 pass 84 #self._debug("Ending threads...") 90 85 while not self.apps_for_store.empty(): 91 86 app=self.apps_for_store.get() … … 105 100 self.progress=100 106 101 return(self.result) 102 #def execute_action 107 103 108 104 def _set_status(self,status,msg=''): … … 122 118 if (self.progress>limit): 123 119 self.progress=limit 120 #def _callback 124 121 125 122 def _chk_installDir(self): … … 131 128 msg_status=False 132 129 return msg_status 130 #def _chk_installDir 133 131 134 132 def _install_appimage(self,app_info): 135 app_info=self._get_info(app_info )136 self._debug("Installing %s"%app_info)133 app_info=self._get_info(app_info,force=True) 134 #self._debug("Installing %s"%app_info) 137 135 if app_info['state']=='installed': 138 136 self._set_status(4) … … 140 138 if 'appimage' in app_info['channel_releases'].keys(): 141 139 appimage_url=app_info['channel_releases']['appimage'][0] 142 self._debug("Downloading "+appimage_url) 140 else: 141 #self._debug("No url in: %s"%app_info['channel_releases']) 142 #self._debug("Downloading "+appimage_url) 143 143 dest_path=self.appimage_dir+'/'+app_info['package'] 144 144 if appimage_url: … … 167 167 168 168 def _remove_appimage(self,app_info): 169 self._debug("Removing "+app_info['package'])169 #self._debug("Removing "+app_info['package']) 170 170 if os.path.isfile(self.appimage_dir+'/'+app_info['package']): 171 171 try: … … 192 192 if int(epoch_time)-int(fcache_update)<86400: 193 193 if os.listdir(os.path.dirname(self.cache_xmls)): 194 self._debug("Loading appimage from cache")194 #self._debug("Loading appimage from cache") 195 195 sw_update_cache=False 196 196 if sw_update_cache: … … 200 200 fcache.write(str(int(time.time()))) 201 201 if os.path.exists(self.cache_xmls): 202 self._debug("Loading appimage catalog")202 #self._debug("Loading appimage catalog") 203 203 store=self._generic_file_load(self.cache_xmls,store) 204 204 return(store) … … 213 213 if target_file.endswith('.xml'): 214 214 store_path=Gio.File.new_for_path(target_path+'/'+target_file) 215 self._debug("Adding file "+target_path+'/'+target_file)215 #self._debug("Adding file "+target_path+'/'+target_file) 216 216 try: 217 217 store.from_file(store_path,icon_path,None) 218 218 except Exception as e: 219 self._debug("Couldn't add file "+target_file+" to store") 220 self._debug("Reason: "+str(e)) 219 #self._debug("Couldn't add file "+target_file+" to store") 220 #self._debug("Reason: "+str(e)) 221 pass 221 222 return(store) 222 223 #def _generic_file_load … … 233 234 os.makedirs(self.cache_xmls) 234 235 except: 235 self._debug("appImage catalogue could not be fetched: Permission denied") 236 self._debug("Fetching repo %s"%repo_info['url']) 236 #self._debug("appImage catalogue could not be fetched: Permission denied") 237 pass 238 #self._debug("Fetching repo %s"%repo_info['url']) 237 239 if repo_info['type']=='json': 238 240 applist=self._process_appimage_json(self._fetch_repo(repo_info['url']),repo_name) 239 241 240 self._debug("Fetched repo "+repo_info['url'])242 #self._debug("Fetched repo "+repo_info['url']) 241 243 self._th_generate_xml_catalog(applist,outdir,repo_info['url_info'],repo_info['url'],repo_name) 242 244 all_apps.extend(applist) … … 273 275 if 'version' in app_info.keys(): 274 276 appinfo['reywords']=app_info['keywords'] 275 self._debug("Fetching external appimage %s"%app_info['url'])277 #self._debug("Fetching external appimage %s"%app_info['url']) 276 278 appinfo['bundle']='appimage' 277 self._debug("External:\n%s\n-------"%appinfo)279 #self._debug("External:\n%s\n-------"%appinfo) 278 280 applist.append(appinfo) 279 281 else: 280 self._debug("External appImage could not be fetched: Permission denied") 282 #self._debug("External appImage could not be fetched: Permission denied") 283 pass 281 284 self._th_generate_xml_catalog(applist,outdir,app_info['url_info'],app_info['url'],app_name) 282 self._debug("Fetched appimage "+app_info['url'])285 #self._debug("Fetched appimage "+app_info['url']) 283 286 all_apps.extend(applist) 284 self._debug("Removing old entries...")287 #self._debug("Removing old entries...") 285 288 # self._clean_bundle_catalogue(all_apps,outdir) 286 289 return(True) … … 302 305 external_appimages=json.load(appimages) 303 306 except: 304 self._debug("Can't load %s"%self.external_appimages) 307 #self._debug("Can't load %s"%self.external_appimages) 308 pass 305 309 return external_appimages 306 310 #def _get_external_appimages … … 327 331 328 332 def load_json_appinfo(self,appimage): 329 self._debug(appimage)333 #self._debug(appimage) 330 334 appinfo=self._init_appinfo() 331 335 appinfo['name']=appimage['name'] … … 345 349 appinfo['icon']=appimage['icon'] 346 350 if 'icons' in appimage.keys(): 347 self._debug("Loading icon %s"%appimage['icons'])351 #self._debug("Loading icon %s"%appimage['icons']) 348 352 if appimage['icons']: 349 self._debug("Loading icon %s"%appimage['icons'][0])353 #self._debug("Loading icon %s"%appimage['icons'][0]) 350 354 appinfo['icon']=appimage['icons'][0] 351 355 if 'screenshots' in appimage.keys(): … … 360 364 for author in appimage['authors']: 361 365 if 'url' in author.keys(): 362 self._debug("Author: %s"%author['url'])366 #self._debug("Author: %s"%author['url']) 363 367 appinfo['homepage']=author['url'] 364 368 else: … … 378 382 threads.append(th) 379 383 th.start() 384 for thread in threads: 385 thread.join() 380 386 #def _th_generate_xml_catalog 381 387 … … 388 394 def _add_appimage(self,appinfo): 389 395 #Search in local store for the app 390 sw_new= False396 sw_new=True 391 397 app=appstream.App() 392 398 app_orig=self.store.get_app_by_pkgname(appinfo['name'].lower()) … … 394 400 app_orig=self.store.get_app_by_id(appinfo['name'].lower()+".desktop") 395 401 if app_orig: 396 self._debug("Extending app %s"%appinfo['package']) 397 app=self._copy_app_from_appstream(app_orig,app) 398 else: 399 self._debug("Generating new %s"%appinfo['package']) 402 #self._debug("Extending app %s"%appinfo['package']) 403 if appinfo['icon']: 404 #self._debug("Icon: %s"%appinfo['icon']) 405 app=self._copy_app_from_appstream(app_orig,app,copy_icon=False) 406 else: 407 app=self._copy_app_from_appstream(app_orig,app,copy_icon=True) 408 sw_new=False 409 else: 410 #self._debug("Generating new %s"%appinfo['package']) 411 pass 400 412 if appinfo['name'].endswith('.appimage'): 401 413 app.set_id("appimagehub.%s"%appinfo['name'].lower()) … … 409 421 app.add_pkgname(appinfo['package'].lower()+".appimage") 410 422 app.set_id_kind=appstream.IdKind.DESKTOP 411 sw_new=True412 423 413 424 if appinfo['license']: … … 433 444 if not appinfo['name'].endswith('.appimage'): 434 445 app.set_name("C",appinfo['name']+".appimage") 446 desc_header="This is an AppImage bundle of app %s. It hasn't been tested by our developers and comes from a 3rd party dev team. Please use it carefully."%appinfo['name'] 435 447 if appinfo['description']: 436 448 for lang,desc in appinfo['description'].items(): 437 description="This is an AppImage bundle of app %s. It hasn't been tested by our developers and comes from a 3rd party dev team. Please use it carefully.\n%s"%(appinfo['name'],desc) 438 summary=' '.join(list(description.split(' ')[:8])) 449 desc=desc.replace('&','&') 450 description="<p>%s</p><p>%s</p>"%(desc_header,desc) 451 summary=' '.join(list(desc.split(' ')[:10])) 439 452 app.set_description(lang,description) 440 453 app.set_comment(lang,summary) 441 454 else: 442 description=" This is an AppImage bundle of app %s. It hasn't been tested by our developers and comes from a 3rd party dev team. Please use it carefully"%(appinfo['name'])443 summary=' '.join(list(desc ription.split(' ')[:8]))455 description="<p>%s</p>"%(desc_header) 456 summary=' '.join(list(desc_header.split(' ')[:8])) 444 457 app.set_description("C",description) 445 458 app.set_comment("C",summary) … … 483 496 xml_data=xml_file.readlines() 484 497 xml_file.close() 485 self._debug("fixing %s"%xml_path)498 #self._debug("fixing %s"%xml_path) 486 499 try: 487 xml_data[0]=xml_data[0]+"<components >\n"500 xml_data[0]=xml_data[0]+"<components origin=\"%s\">\n"%app.get_origin() 488 501 xml_data[-1]=xml_data[-1]+"\n"+"</components>" 489 502 except: … … 492 505 xml_file.writelines(xml_data) 493 506 xml_file.close() 494 495 507 #def _add_appimage 496 508 497 def _copy_app_from_appstream(self,app_orig,app): 509 def _copy_app_from_appstream(self,app_orig,app,copy_icon=True): 510 desc_header="This is an AppImage bundle of app %s. It hasn't been tested by our developers and comes from a 3rd party dev team. Please use it carefully."%app_orig.get_pkgnames()[0] 498 511 app.set_id("appimage."+app_orig.get_id()) 499 512 for category in app_orig.get_categories(): 500 513 app.add_category(category) 514 app.add_category("appimage") 501 515 for screenshot in app_orig.get_screenshots(): 502 516 app.add_screenshot(screenshot) 503 for icon in app_orig.get_icons(): 504 app.add_icon(icon) 517 if copy_icon: 518 for icon in app_orig.get_icons(): 519 app.add_icon(icon) 505 520 for localeItem in self.locale: 506 521 if app_orig.get_name(localeItem): 507 522 app.set_name(localeItem,app_orig.get_name(localeItem)+".appimage") 508 523 if app_orig.get_description(localeItem): 509 app.set_description(localeItem, app_orig.get_description(localeItem))524 app.set_description(localeItem,"<p>%s</p><p>%s</p>"%(desc_header,app_orig.get_description(localeItem))) 510 525 if app_orig.get_comment(localeItem): 511 526 app.set_comment(localeItem,app_orig.get_comment(localeItem)) 512 527 app.set_origin(app_orig.get_origin()) 513 528 return app 529 #def _copy_app_from_appstream 514 530 515 531 def _clean_bundle_catalogue(self,applist,outdir): … … 532 548 if not os.path.isfile(target_file): 533 549 if not os.path.isfile(target_file): 534 self._debug("Downloading %s to %s"%(url,target_file))550 #self._debug("Downloading %s to %s"%(url,target_file)) 535 551 try: 536 552 with urllib.request.urlopen(url) as response, open(target_file, 'wb') as out_file: … … 545 561 st = os.stat(target_file) 546 562 except Exception as e: 547 self._debug("Unable to download %s"%url)548 self._debug("Reason: %s"%e)563 #self._debug("Unable to download %s"%url) 564 #self._debug("Reason: %s"%e) 549 565 target_file='' 550 566 return(target_file) … … 592 608 #def _init_appinfo 593 609 594 def _get_info(self,app_info): 595 if app_info['installerUrl']: 596 self._debug("installer: %s"%app_info['installerUrl']) 597 app_info['channel_releases']={'appimage':[]} 598 app_info['channel_releases']['appimage']=self._get_releases(app_info) 610 def _get_info(self,app_info,force=False): 611 #self._debug("Searching for %s in %s"%(app_info['package'],self.appimage_dir)) 599 612 app_info['state']='available' 600 613 if os.path.isfile(self.appimage_dir+'/'+app_info['package']): 601 614 app_info['state']='installed' 602 #Get size 603 if 'appimage' in app_info['channel_releases'].keys(): 604 if app_info['channel_releases']['appimage'][0]: 605 appimage_url=app_info['channel_releases']['appimage'][0] 606 dest_path=self.appimage_dir+'/'+app_info['package'] 607 if appimage_url: 608 try: 609 with urllib.request.urlopen(appimage_url) as response: 610 app_info['size']=(response.info()['Content-Length']) 611 except: 612 app_info['size']=0 613 else: 614 app_info['size']=0 615 #Version (unaccurate aprox) 616 app_info['version']=app_info['channel_releases']['appimage'][0].split('/')[-2] 615 if not app_info['size'] or force: 616 if app_info['installerUrl']: 617 #self._debug("installer: %s"%app_info['installerUrl']) 618 app_info['channel_releases']={'appimage':[]} 619 app_info['channel_releases']['appimage']=self._get_releases(app_info) 620 #Get size 621 app_info['size']=0 622 app_info['version']='unknown' 623 if 'appimage' in app_info['channel_releases'].keys(): 624 if len(app_info['channel_releases']['appimage'])>0: 625 if app_info['channel_releases']['appimage'][0]: 626 appimage_url=app_info['channel_releases']['appimage'][0] 627 dest_path=self.appimage_dir+'/'+app_info['package'] 628 if appimage_url: 629 try: 630 with urllib.request.urlopen(appimage_url) as response: 631 app_info['size']=(response.info()['Content-Length']) 632 except: 633 app_info['size']=0 634 #Version (unaccurate aprox) 635 app_info['version']=app_info['channel_releases']['appimage'][0].split('/')[-2] 617 636 618 637 self._set_status(0) … … 624 643 releases=[] 625 644 releases_page='' 626 self._debug("Info url: %s"%app_info['installerUrl'])645 #self._debug("Info url: %s"%app_info['installerUrl']) 627 646 url_source="" 628 647 try: … … 651 670 package_link=releases_page+package_link 652 671 releases.append(package_link) 653 self._debug("Link: %s"%package_link)672 #self._debug("Link: %s"%package_link) 654 673 else: 655 674 releases=[app_info['installerUrl']] 656 675 except Exception as e: 657 676 print(e) 658 self._debug(releases)677 #self._debug(releases) 659 678 return releases 660 679 #def _get_releases -
lliurex-store/trunk/fuentes/python3-lliurex-store.install/usr/share/lliurexstore/plugins/debManager.py
r8180 r8223 4 4 from gi.repository import PackageKitGlib as packagekit 5 5 import threading 6 import time 6 7 from queue import Queue as pool 7 8 class debmanager: … … 12 13 self.progress=0 13 14 self.partial_progress=0 14 self.plugin_actions={'install':'deb','remove':'deb','pkginfo':'deb' }15 self.plugin_actions={'install':'deb','remove':'deb','pkginfo':'deb','policy':'deb'} 15 16 self.result={} 16 17 self.result['data']={} … … 21 22 def set_debug(self,dbg=True): 22 23 self.dbg=dbg 23 self._debug ("Debug enabled")24 #self._debug ("Debug enabled") 24 25 #def set_debug 25 26 … … 28 29 print ('DEBUG Deb: %s'%msg) 29 30 #def debug 30 31 def _log(self,msg=None):32 if msg:33 syslog.openlog('lliurex-store')34 syslog.syslog(msg)35 31 36 32 def register(self): … … 41 37 #filter=2 -> only installed app installed 42 38 def execute_action(self,action,applist,filters=1): 43 self._debug("Executing action %s"%action)39 #self._debug("Executing action %s"%action) 44 40 self.progress=0 45 41 self.installer=packagekit.Client() … … 57 53 if app: 58 54 if action=='install': 59 self._log("Installing "+app_info['package'])60 55 self._install_App(app) 61 56 self.result['data'].append({'package':app_info['package']}) 62 57 if action=='remove': 63 self._log("Removing "+app_info['package'])64 58 self._remove_App(app) 65 59 self.result['data'].append({'package':app_info['package']}) 66 60 if action=='pkginfo': 67 self.result['data'].append(self._get_App_Extended_Info(app_info,app)) 61 res=self._get_info(app_info,app) 62 self.result['data'].append(res) 68 63 if action=='policy': 69 64 self._set_status(0) … … 76 71 def _set_status(self,status,msg=''): 77 72 self.result['status']={'status':status,'msg':msg} 73 #def _set_status 78 74 79 75 def _fake_callback(self,*args): … … 88 84 def _install_App(self,app): 89 85 self.return_msg=False 90 self._debug("Installing %s"%app.get_id())86 #self._debug("Installing %s"%app.get_id()) 91 87 err=0 92 88 try: … … 95 91 except Exception as e: 96 92 print(str(e)) 97 self._debug("Install error: %s"%e.code)93 #self._debug("Install error: %s"%e.code) 98 94 err=e.code 99 95 finally: … … 108 104 self._set_status(0) 109 105 except Exception as e: 110 self._debug("Remove error: %s"%e.code)111 self._debug("Remove error: %s"%e)106 #self._debug("Remove error: %s"%e.code) 107 #self._debug("Remove error: %s"%e) 112 108 self._set_status(e.code) 113 109 finally: … … 116 112 117 113 def _th_get_details(self,pkTask,app_info_pool,app): 118 self._debug("Getting details for %s"%app.get_id())114 #self._debug("Getting details for %s"%app.get_id()) 119 115 results=pkTask.get_details([app.get_id(),],None,self._fake_callback,None) 120 116 for app_detail in results.get_details_array(): … … 124 120 125 121 def _th_get_depends(self,pkTask,app_info_pool,app): 126 self._debug("Getting dependencies for %s"%app.get_id())122 #self._debug("Getting dependencies for %s"%app.get_id()) 127 123 results=pkTask.get_depends(1,[app.get_id(),],False,None,self._fake_callback,None) 128 124 dependsList=[] … … 132 128 #def _th_get_depends 133 129 134 def _get_ App_Extended_Info(self,app_info,app):130 def _get_info(self,app_info,app): 135 131 app_info['version']=app.get_version() 136 132 app_info['arch']=app.get_id().split(';')[2] … … 138 134 results=[] 139 135 self._set_status(0) 140 app_info_pool=pool() 141 threads=[] 142 th=threading.Thread(target=self._th_get_details, args = (pkTask,app_info_pool,app)) 143 threads.append(th) 144 th.start() 145 #Get depends disabled per time-costing 146 #th=threading.Thread(target=self._th_get_depends, args = (pkTask,app_info_pool,app)) 147 #threads.append(th) 148 #th.start() 136 #Only get size and depends if we don't have the data 137 if not app_info['size']: 138 app_info_pool=pool() 139 threads=[] 140 th=threading.Thread(target=self._th_get_details, args = (pkTask,app_info_pool,app)) 141 threads.append(th) 142 th.start() 143 #Get depends disabled per time-costing 144 #th=threading.Thread(target=self._th_get_depends, args = (pkTask,app_info_pool,app)) 145 #threads.append(th) 146 #th.start() 147 for thread in threads: 148 try: 149 thread.join() 150 except: 151 pass 152 while app_info_pool.qsize(): 153 data=app_info_pool.get() 154 app_info.update(data) 155 #Get status 149 156 try: 150 157 info=app.get_info() 151 158 state=info.to_string(info) 152 if state!=app_info['state'] and app_info['state']=='installed':159 if state!=app_info['state'] and state!='available' and app_info['state']=='installed': 153 160 app_info['updatable']=1 154 161 else: 155 162 app_info['state']=state 156 self._debug("State: "+app_info['state']) 157 except Exception as e: 158 self._debug("State: not available (%s)"%e) 159 160 for thread in threads: 161 try: 162 thread.join() 163 except: 163 #self._debug("State: %s"%state) 164 except Exception as e: 165 #self._debug("State: not available (%s)"%e) 166 pass 167 #self._debug("INFO: %s"%app_info) 168 return(app_info) 169 #def _get_info 170 171 def _resolve_App(self,app_name,filters=1): 172 #self._debug("Resolving %s"%app_name) 173 def _pk_resolve(filters,app_name): 174 app=None 175 #self._debug("Filter for resolver: %s"%filters) 176 result=self.installer.resolve(filters,[app_name,],None,self._fake_callback, None) 177 resolvelist=result.get_package_array() 178 #resolver bug: filters not work so if we want to remove an app first we must get the installed version... 179 app_resolved=None 180 if filters==1: 181 app_resolved=resolvelist[0] 182 elif filters==2: 183 for app in resolvelist: 184 if (str(app.get_info()).find('PK_INFO_ENUM_INSTALLED')!=-1): 185 app_resolved=app 186 break 187 if app_resolved: 188 #self._debug("Application %s resolved succesfully"%app_resolved.get_name()) 189 app=app_resolved 190 else: 191 #self._debug("Application %s NOT resolved"%app_resolved.get_name()) 164 192 pass 165 166 while app_info_pool.qsize(): 167 data=app_info_pool.get() 168 app_info.update(data) 169 170 return(app_info) 171 #def _get_App_Extended_Info 172 173 def _resolve_App(self,app_name,filters=1): 174 self._debug("Resolving %s"%app_name) 193 return app 194 175 195 app=None 176 196 resolvelist=[] 177 197 self.return_msg=False 178 198 try: 179 self._debug("Filter for resolver: %s"%filters) 180 result=self.installer.resolve(filters,[app_name,],None,self._fake_callback, None) 181 resolvelist=result.get_package_array() 182 app_resolved=resolvelist[0] 183 #resolver bug: filters not work so if we want to remove an app first we must get the installed version... 184 if filters==2: 185 for app in resolvelist: 186 if (str(app.get_info()).find('PK_INFO_ENUM_INSTALLED')!=-1): 187 app_resolved=app 188 if app_resolved: 189 self._debug("Application %s resolved succesfully"%app_resolved.get_name()) 190 app=app_resolved 191 except Exception as e: 192 self._debug("Couldn't resolve %s"%app_name) 193 self._debug("Reason: %s"%e) 199 app=_pk_resolve(filters,app_name) 200 except Exception as e: 201 #self._debug("Couldn't resolve %s"%app_name) 202 #self._debug("Reason: %s"%e) 203 #self._debug("2nd attempt") 204 time.sleep(0.5) 205 try: 206 app=_pk_resolve(filters,app_name) 207 except Exception as e: 208 #self._debug("Couldn't resolve %s"%app_name) 209 #self._debug("Reason: %s"%e) 210 pass 194 211 finally: 195 212 self.partial_progress=100 -
lliurex-store/trunk/fuentes/python3-lliurex-store.install/usr/share/lliurexstore/plugins/example.py
r7432 r8223 21 21 #This example plugin is disabled by default 22 22 self.disabled=True 23 #A plugin must declare autostart actions thar must be invoked when storemanager registers the plugin 24 #The dict's key is the action's name and the value is the parameter (or None) needed for launch the action 25 self.autostart_actions={'example':'store=self.store'} #The parameter list refers to 'stringfieds' storeManager members !! 26 #This dict registers actions to be launched after storemanager registered actions. 27 #In this example the action 'install' of the plugin is launched after storemanager does any 'install' action. As in autostart_actions the parameter referes to storemanager members 28 self.postaction_actions={'install':'app','remove':'app'} 29 #If an action requires some parameter to be launched you could declare here. 30 self.requires={'cache':'store=self.store'} 23 31 #def __init__ 24 32 -
lliurex-store/trunk/fuentes/python3-lliurex-store.install/usr/share/lliurexstore/plugins/infoManager.py
r7433 r8223 15 15 def set_debug(self,dbg=True): 16 16 self.dbg=dbg 17 self._debug ("Debug enabled")17 #self._debug ("Debug enabled") 18 18 #def set__debug 19 19 … … 27 27 #def register 28 28 29 def execute_action(self,a ppstream,action,applist,match=False):29 def execute_action(self,action,applist,match=False): 30 30 self.progress=0 31 self.appstream=appstream32 31 count=len(applist) 33 32 if (action=='get_info' or action=='info') and count>0: … … 40 39 def _set_status(self,status,msg=''): 41 40 self.result['status']={'status':status,'msg':msg} 41 #def _set_status 42 42 43 43 def _callback_progress(self): … … 59 59 for app in applist: 60 60 appInfo=self._init_appInfo() 61 #self._debug("Gathering package info for "+app.get_id())61 #self._debug("Gathering package info for "+app.get_id()) 62 62 #Earlier versions stored the appstream_id as the memory dir of the metadata 63 63 #Changes in python3.6 and pickle module forces us to disable this feature... … … 90 90 if app.get_comment(localeItem): 91 91 appInfo['summary']=app.get_comment(localeItem) 92 appInfo['summary']=appInfo['summary'].replace('&','&') 93 appInfo['summary']=appInfo['summary'].replace('<p>','') 92 94 break 93 95 for localeItem in self.locale: … … 137 139 screenshots_list.append("/home/lliurex/.cache/lliurex-store/images/"+img.get_basename()) 138 140 139 140 141 appInfo['thumbnails']=thumbnails_list 141 142 appInfo['screenshot']=default_screenshot 142 143 appInfo["screenshots"]=screenshots_list 143 144 #The values are the values of appstream.UrlKind. 1=HOMEPAGE, 0=UNKNOWN 144 # self._debug(app.get_url_item(0))145 # #self._debug(app.get_url_item(0)) 145 146 if app.get_url_item(1): 146 147 appInfo['homepage']=app.get_url_item(1).strip() -
lliurex-store/trunk/fuentes/python3-lliurex-store.install/usr/share/lliurexstore/plugins/loadStore.py
r7432 r8223 30 30 def set_debug(self,dbg=True): 31 31 self.dbg=dbg 32 self._debug ("Debug enabled")32 #self._debug ("Debug enabled") 33 33 #def set_debug 34 34 … … 66 66 for flag in flags: 67 67 try: 68 self._debug("Loading "+str(flag))68 #self._debug("Loading "+str(flag)) 69 69 store.load(flag) 70 70 except: 71 71 print ("Failed to load"+str(flag)) 72 72 pass 73 #Zomandos are now available from appstream74 # store=self.load_zmds_catalog(store)75 73 store=self._sanitize_store(store) 76 74 self.store=store … … 90 88 if target_file.endswith('appdata.xml'): 91 89 store_file=Gio.File.new_for_path(target_dir+'/'+target_file) 92 self._debug("Adding file %s/%s"%(target_dir,target_file))90 #self._debug("Adding file %s/%s"%(target_dir,target_file)) 93 91 try: 94 92 store.from_file(store_file,icon_dir,None) 95 93 except Exception as e: 96 self._debug("Couldn't add file %s to store"%target_file) 97 self._debug("Reason: %s"%e) 94 #self._debug("Couldn't add file %s to store"%target_file) 95 #self._debug("Reason: %s"%e) 96 pass 98 97 return(store) 99 98 … … 110 109 a.remove_veto(veto) 111 110 store.add_app(a) 112 self._debug("Adding app from desktop %s"%desktop_file)111 #self._debug("Adding app from desktop %s"%desktop_file) 113 112 except: 114 113 pass … … 124 123 #Zomandos get max priority 125 124 if app.has_category('Zomando'): 126 self._debug("Prioritize zmd %s"%app.get_id())125 #self._debug("Prioritize zmd %s"%app.get_id()) 127 126 app.set_priority(400) 128 127 lliurex_apps.update({app.get_id_filename():app}) … … 131 130 #Prioritize Lliurex apps 132 131 elif app.has_category('Lliurex'): 133 self._debug("Prioritize app %s"%app.get_id())132 #self._debug("Prioritize app %s"%app.get_id()) 134 133 app.set_priority(200) 135 134 lliurex_apps.update({app.get_id_filename():app}) 136 135 elif str(app.get_origin()).find('lliurex')>=0: 137 self._debug("Prioritize app %s"%app.get_id())136 #self._debug("Prioritize app %s"%app.get_id()) 138 137 app.set_priority(100) 139 138 lliurex_apps.update({app.get_id_filename():app}) … … 141 140 app.set_priority(0) 142 141 if app.get_id_filename() in lliurex_apps.keys(): 143 self._debug("Mergin app %s as is in LliureX"%app.get_id())142 #self._debug("Mergin app %s as is in LliureX"%app.get_id()) 144 143 lliurex_apps[app.get_id_filename()].subsume_full(app,appstream.AppSubsumeFlags.BOTH_WAYS) 145 144 # store.add_app(lliurex_apps[app.get_id_filename()]) … … 149 148 #Remove add-on apps (as are included in the main packages) 150 149 if app.get_kind()==appstream.AppKind.ADDON: 151 self._debug("Removed addon %s"%app.get_pkgnames())150 #self._debug("Removed addon %s"%app.get_pkgnames()) 152 151 store.remove_app(app) 153 152 #Remove duplicated apps … … 156 155 if pkg in tmp_store_apps.keys(): 157 156 fn=app.get_id_no_prefix() 158 self._debug("Comparing %s with %s"%(fn,tmp_store_apps[pkg]['fn']))157 #self._debug("Comparing %s with %s"%(fn,tmp_store_apps[pkg]['fn'])) 159 158 if fn != tmp_store_apps[pkg]['fn']: 160 159 if fn != pkg and ".desktop" not in fn: 161 self._debug("Removed duplicated %s"%app.get_id())160 #self._debug("Removed duplicated %s"%app.get_id()) 162 161 store.remove_app(app) 163 162 else: 164 self._debug("Removed duplicated %s"%tmp_store_apps[pkg]['app'].get_id())163 #self._debug("Removed duplicated %s"%tmp_store_apps[pkg]['app'].get_id()) 165 164 store.remove_app(tmp_store_apps[pkg]['app']) 166 165 tmp_store_apps.update({pkg:{'fn':app.get_id_no_prefix(),'app':app}}) 167 166 elif pkg: 168 # self._debug("Adding "+app.get_id_filename()+" to uniq dict")167 # #self._debug("Adding "+app.get_id_filename()+" to uniq dict") 169 168 tmp_store_apps.update({pkg:{'fn':app.get_id_filename(),'app':app}}) 170 169 #Delete zomando-related debs … … 177 176 def _purge_zomandos(self,zmd_apps,store): 178 177 for zmd_id in zmd_apps: 179 self._debug("Searching debs related to %s"%zmd_id)178 #self._debug("Searching debs related to %s"%zmd_id) 180 179 purge_list=store.get_apps_by_id(zmd_id) 181 180 purge_list.extend(store.get_apps_by_id(zmd_id+".desktop")) … … 183 182 if purge_app: 184 183 if not purge_app.has_category('Zomando'): 185 self._debug("Removed related zomando app %s"%purge_app.get_id())184 #self._debug("Removed related zomando app %s"%purge_app.get_id()) 186 185 store.remove_app(purge_app) 187 186 return(store) … … 193 192 flavour=flavour.decode("utf-8") 194 193 if flavour=='None': 195 self._debug("Unknown flavour. Switching to desktop")194 #self._debug("Unknown flavour. Switching to desktop") 196 195 flavour='desktop' 197 196 except (subprocess.CalledProcessError,FileNotFoundError) as e: 198 self._debug("Running on a non Lliurex host")197 #self._debug("Running on a non Lliurex host") 199 198 flavour='desktop' 200 199 try: … … 209 208 blacklist_re=[] 210 209 for blacklist_app in blacklist_apps: 211 self._debug("Blacklisted app: "+blacklist_app)210 #self._debug("Blacklisted app: "+blacklist_app) 212 211 re_result=re.search('([^a-zA-Z0-9_-])',blacklist_app) 213 212 if re_result: … … 218 217 app=store.get_app_by_pkgname(blacklist_app) 219 218 if app: 220 self._debug("Removed "+str(app))219 #self._debug("Removed "+str(app)) 221 220 store.remove_app(app) 222 221 else: 223 self._debug("App %s from blacklist not found in store. Assigned to RE blacklist"%blacklist_app)222 #self._debug("App %s from blacklist not found in store. Assigned to RE blacklist"%blacklist_app) 224 223 blacklist_re.append("("+blacklist_app+")") 225 224 if blacklist_re: 226 self._debug("Attempting to remove apps by RE match")225 #self._debug("Attempting to remove apps by RE match") 227 226 for app in store.get_apps(): 228 227 for blacklist_app in blacklist_re: … … 230 229 if re_result: 231 230 store.remove_app(app) 232 self._debug("Removed %s as matches with %s"%(app.get_id(),blacklist_app))231 #self._debug("Removed %s as matches with %s"%(app.get_id(),blacklist_app)) 233 232 else: 234 self._debug('No blacklist to check') 233 #self._debug('No blacklist to check') 234 pass 235 235 except Exception as e: 236 self._debug("Error processing blacklist: %s"%e) 236 #self._debug("Error processing blacklist: %s"%e) 237 pass 237 238 finally: 238 239 return(store) -
lliurex-store/trunk/fuentes/python3-lliurex-store.install/usr/share/lliurexstore/plugins/searchManager.py
r8182 r8223 20 20 def __call__(self): 21 21 return (self.applist) 22 #def __call__ 22 23 23 24 def set_debug(self,dbg=True): 24 25 self.dbg=dbg 25 self._debug ("Debug enabled")26 #self._debug ("Debug enabled") 26 27 #def set__debug 27 28 … … 33 34 def register(self): 34 35 return(self.plugin_actions) 36 #def register 35 37 36 38 def execute_action(self,appstreamStore,action,tokens,exact_match_for_search=False,max_results=0): 37 self._debug("Executing action %s"%action)38 self._debug("Tokens: %s"%tokens)39 #self._debug("Executing action %s"%action) 40 #self._debug("Tokens: %s"%tokens) 39 41 self.progress=0 40 42 if type(tokens)==type([]): … … 46 48 if len(tokens.split(' '))>1: 47 49 if action=='search': 48 self._debug("Tokenizing search items")50 #self._debug("Tokenizing search items") 49 51 tokens=appstream.utils_search_tokenize(tokens) 50 52 else: … … 67 69 self._search_app(tokens,exact_match_for_search) 68 70 else: 69 self._debug("Search needs a store") 71 #self._debug("Search needs a store") 72 pass 70 73 self.progress=100 71 74 return(self.result) 75 #def execute_action 72 76 73 77 def _set_status(self,status,msg=''): 74 78 self.result['status']={'status':status,'msg':msg} 79 #def _set_status 75 80 76 81 def set_precision(self,precision): 77 82 self.precision=precision 83 #def set_precision 78 84 79 85 def _search_app(self,tokens,exact_match): 80 self._debug("Searching app "+str(tokens)+ " with exact_match="+str(exact_match))86 #self._debug("Searching app "+str(tokens)+ " with exact_match="+str(exact_match)) 81 87 applist=[] 82 88 app=None 83 # if len(tokens)==1:84 89 if exact_match: 85 90 app=self._app_exists(tokens[0]) … … 89 94 else: 90 95 applist.append(app) 91 # self._debug("App direct match found: "+app.get_id())96 # #self._debug("App direct match found: "+app.get_id()) 92 97 if not exact_match: 93 98 applist.extend(self._get_apps_by_match(tokens,applist)) 94 # if len(applist):95 # self._set_status(0)96 # else:97 99 applist.extend(self._get_app_by_pkgname(tokens,applist)) 98 100 applist=set(applist) … … 103 105 self.result['data']=applist 104 106 return(applist) 107 #def _search_app 105 108 106 109 def _list_sections(self): … … 121 124 self._set_status(1) 122 125 return(applist) 126 #def _list_sections 123 127 124 128 def _list_category(self,tokens=[],max_results=0): 125 129 applist=[] 126 self._debug("tokens: "+str(tokens))127 self._debug("Max results: %s"%max_results)130 #self._debug("tokens: "+str(tokens)) 131 #self._debug("Max results: %s"%max_results) 128 132 if len(tokens)>=1: 129 self._debug("Searching category "+str(tokens))133 #self._debug("Searching category "+str(tokens)) 130 134 categories_set=set(tokens) 131 135 apps_in_store=self.store.get_apps() … … 142 146 app_categories_set=set(app_categories) 143 147 if categories_set.issubset(app_categories_set): 144 self._debug("Found "+app.get_id())148 #self._debug("Found "+app.get_id()) 145 149 applist.append(app) 146 150 if max_results and len(applist)==max_results: 147 151 break 148 152 else: 149 self._debug("Loading all apps in store")153 #self._debug("Loading all apps in store") 150 154 applist=self.store.get_apps() 151 155 categories_set=set(['snap','appimage']) … … 163 167 print("Removing %s"%app.get_pkgname()) 164 168 applist=applist_2 165 # for app in applist:166 # self._debug("Added "+app.get_id())167 169 if max_results: 168 170 applist=applist[0:max_results] … … 175 177 self._set_status(1) 176 178 return(applist) 179 #def _list_category 177 180 178 181 def _app_exists(self,app_name): 179 self._debug("Trying direct match for "+app_name)182 #self._debug("Trying direct match for "+app_name) 180 183 #id_matches defines how to search for an app 181 184 # %s -> app_name; zero-lliurex-%s -> app_name with zero-lliurex- prefix and so on... … … 187 190 if app: 188 191 break 189 190 191 #1.- Try exact match192 # app=self.store.get_apps_by_id(app_name)193 # if not app:194 # #2.- Try exact match with zero-lliurex- for the zomandos195 # app=self.store.get_app_by_id("zero-lliurex-"+app_name)196 # if not app:197 # #3.- Try exact match with .desktop198 # app=self.store.get_apps_by_id(app_name+".desktop")199 192 if not app: 200 # 4.- Try exact match by pkgname193 #2.- Try exact match by pkgname 201 194 app=self.store.get_app_by_pkgname(app_name) 202 # if not app: 203 # app=self.store.get_app_by_id_ignore_prefix(app_name) 204 self._debug("App found %s"%app) 195 #self._debug("App found %s"%app) 205 196 return(app) 197 #def _app_exists 206 198 207 199 def _get_apps_by_match(self,tokens,applist=[]): 208 200 #Add items with match >= self.precision 209 self._debug("Searching app by fuzzy match")201 #self._debug("Searching app by fuzzy match") 210 202 if not applist: 211 203 position=1 … … 224 216 score=app.search_matches(token) 225 217 if score>=self.precision: 226 # if "appimage" in app.get_id().lower():227 # score=1228 218 if score in tmp_app_dict: 229 219 tmp_app_dict[score].append(app) … … 234 224 for app in tmp_app_dict[match]: 235 225 if app not in applist: 236 self._debug("Adding app "+app.get_id() + " with score: "+str(match))226 #self._debug("Adding app "+app.get_id() + " with score: "+str(match)) 237 227 applist.insert(0,app) 238 228 return(applist) 229 #def _get_apps_by_match 239 230 240 231 def _get_app_by_pkgname(self,tokens,applist=[]): … … 256 247 257 248 return(applist) 249 #def _get_app_by_pkgname -
lliurex-store/trunk/fuentes/python3-lliurex-store.install/usr/share/lliurexstore/plugins/shManager.py
r7080 r8223 23 23 def set_debug(self,dbg=True): 24 24 self.dbg=dbg 25 self._debug ("Debug enabled")25 #self._debug ("Debug enabled") 26 26 #def set_debug 27 27 … … 41 41 if (action): 42 42 for app_info in applist: 43 self._debug("Executing action "+action+" for "+str(app_info))43 #self._debug("Executing action "+action+" for "+str(app_info)) 44 44 if action=='install': 45 45 self.result['data'].append(self._install_App(app_info)) … … 52 52 def _set_status(self,status,msg=''): 53 53 self.result['status']={'status':status,'msg':msg} 54 #def _set_status 54 55 55 56 def _callback(self,partial_size=0,total_size=0): … … 70 71 return_msg=False 71 72 app_url=app_info['installerUrl'] 72 self._debug("Checking availabilty for "+app_url)73 #self._debug("Checking availabilty for "+app_url) 73 74 tmp_dir=tempfile.mkdtemp(None,None,'/tmp') 74 75 file_name=app_url.split('/')[-1] … … 80 81 try: 81 82 sudo_cmd=['gksudo',dest_path] 82 self._debug("executing "+str(sudo_cmd))83 #self._debug("executing "+str(sudo_cmd)) 83 84 launched_cmd=subprocess.Popen(sudo_cmd,stdout=subprocess.PIPE,stdin=subprocess.PIPE,stderr=subprocess.PIPE) 84 85 # launched_cmd=subprocess.check_output(sudo_cmd) … … 96 97 cmd_status=launched_cmd.stdout.read() 97 98 cmd_err=launched_cmd.stderr.read() 98 self._debug("Error: "+str(cmd_err))99 self._debug("Result: "+str(cmd_status))99 #self._debug("Error: "+str(cmd_err)) 100 #self._debug("Result: "+str(cmd_status)) 100 101 except subprocess.CalledProcessError as callError: 101 102 # err=callError.returncode … … 103 104 err=303 104 105 except Exception as e: 105 self._debug(str(e))106 #self._debug(str(e)) 106 107 err=12 107 108 else: … … 116 117 tmp_dir=tempfile.mkdtemp(None,None,'/tmp') 117 118 dest_path=tmp_dir+'/'+app_url.split('/')[-1] 118 self._debug("Downloading "+app_url+" to "+dest_path)119 #self._debug("Downloading "+app_url+" to "+dest_path) 119 120 try: 120 121 # urllib.request.urlretrieve(app_url,dest_path) … … 131 132 return_msg=True 132 133 except Exception as e: 133 self._debug(str(e))134 #self._debug(str(e)) 134 135 return_msg=False 135 136 return return_msg … … 138 139 def _get_Sh_Info(self,app_info): 139 140 app_url=app_info['installerUrl'] 140 self._debug("Connecting to "+app_url)141 #self._debug("Connecting to "+app_url) 141 142 app_url.strip() 142 143 try: … … 148 149 self._set_status(err) 149 150 return(app_info) 151 #def _get_Sh_Info 150 152 151 153 #def _get_info -
lliurex-store/trunk/fuentes/python3-lliurex-store.install/usr/share/lliurexstore/plugins/snapManager.py
r8185 r8223 39 39 except: 40 40 self.icon_cache_enabled=False 41 self._debug("Icon cache disabled")41 #self._debug("Icon cache disabled") 42 42 if not os.path.isdir(self.images_folder): 43 43 try: … … 45 45 except: 46 46 self.image_cache_enabled=False 47 self._debug("Image cache disabled")47 #self._debug("Image cache disabled") 48 48 #def __init__ 49 49 50 50 def set_debug(self,dbg=True): 51 51 self.dbg=dbg 52 self._debug ("Debug enabled")52 #self._debug ("Debug enabled") 53 53 #def set_debug 54 54 … … 60 60 def register(self): 61 61 return(self.plugin_actions) 62 #def register 62 63 63 64 def enable(self,state=False): 64 65 self.disabled=state 66 #def enable 65 67 66 68 def execute_action(self,action,applist=None,store=None,results=0): … … 73 75 self.result['data']='' 74 76 77 self.snap_client=Snapd.Client() 78 try: 79 self.snap_client.connect_sync(None) 80 except Exception as e: 81 self.disabled=True 82 #self._debug("Disabling snap %s"%e) 75 83 76 84 if self.disabled==True: … … 79 87 else: 80 88 self._check_dirs() 81 self.snap_client=Snapd.Client()82 self.snap_client.connect_sync(None)83 89 dataList=[] 84 90 if action=='load': … … 99 105 self.progress=100 100 106 return(self.result) 107 #def execute_action 101 108 102 109 def _set_status(self,status,msg=''): … … 117 124 if not os.path.isdir(self.cache_xmls): 118 125 os.makedirs(self.cache_xmls) 126 #def _check_dirs 119 127 120 128 def _load_snap_store(self,store): … … 129 137 if int(epoch_time)-int(fcache_update)<86400: 130 138 if os.listdir(os.path.dirname(self.cache_xmls)): 131 self._debug("Loading snap from cache")139 #self._debug("Loading snap from cache") 132 140 store=self._load_from_cache(store) 133 141 return store … … 153 161 store.add_app(store_pool.get()) 154 162 return(store) 163 #def _load_snap_store 155 164 156 165 def _th_load_store(self,store,pkg,semaphore): … … 158 167 app=self.store.get_app_by_pkgname(pkg.get_name()) 159 168 if not app: 160 self._debug("Searching for %s"%pkg.get_name())169 #self._debug("Searching for %s"%pkg.get_name()) 161 170 app=self.store.get_app_by_id(pkg.get_name().lower()+".desktop") 162 171 if app: … … 170 179 store.put(self._generate_appstream_app_from_snap(pkg)) 171 180 semaphore.release() 181 #def _th_load_store 172 182 173 183 def _load_from_cache(self,store): … … 175 185 if target_file.endswith('.xml'): 176 186 store_file=Gio.File.new_for_path(self.cache_xmls+'/'+target_file) 177 self._debug("Adding file %s/%s"%(self.cache_xmls,target_file))187 #self._debug("Adding file %s/%s"%(self.cache_xmls,target_file)) 178 188 try: 179 189 store.from_file(store_file,'',None) 180 190 except Exception as e: 181 self._debug("Couldn't add file %s to store"%target_file) 182 self._debug("Reason: %s"%e) 191 #self._debug("Couldn't add file %s to store"%target_file) 192 #self._debug("Reason: %s"%e) 193 pass 183 194 return store 195 #def _load_from_cache 184 196 185 197 def _generate_appstream_app_from_snap(self,pkg): … … 243 255 xml_data=xml_file.readlines() 244 256 xml_file.close() 245 self._debug("fixing %s"%xml_path)257 #self._debug("fixing %s"%xml_path) 246 258 try: 247 259 xml_data[0]=xml_data[0]+"<components>\n" … … 253 265 xml_file.close() 254 266 return(app) 267 #def _generate_appstream_app_from_snap 255 268 256 269 def _search_cb(self,obj,request,*args): 257 270 global wrap 258 271 wrap=request 272 #def _search_cb 259 273 260 274 def _load_sections(self): … … 266 280 stable_pkgs.append(pkg) 267 281 return(stable_pkgs) 282 #def _load_sections 268 283 269 284 def _search_snap_async(self,tokens,force_stable=True): 270 self._debug("Async Searching %s"%tokens)285 #self._debug("Async Searching %s"%tokens) 271 286 pkgs=None 272 287 global wrap … … 288 303 stable_pkgs.append(pkg) 289 304 else: 290 self._debug(pkg.get_channel()) 305 #self._debug(pkg.get_channel()) 306 pass 291 307 else: 292 308 stable_pkgs.append(pkg) 293 309 return(stable_pkgs) 310 #def _search_snap_async 294 311 295 312 def _search_snap(self,tokens,force_stable=True): 296 self._debug("Searching %s"%tokens)313 #self._debug("Searching %s"%tokens) 297 314 pkg=None 298 315 pkgs=None … … 308 325 stable_pkgs.append(pkg) 309 326 else: 310 self._debug(pkg.get_channel()) 327 #self._debug(pkg.get_channel()) 328 pass 311 329 else: 312 330 stable_pkgs.append(pkg) 313 self._debug("Done")331 #self._debug("Done") 314 332 return(stable_pkgs) 315 333 #def _search_snap … … 319 337 if not os.path.isfile(target_file): 320 338 if not os.path.isfile(target_file): 321 self._debug("Downloading %s to %s"%(url,target_file))339 #self._debug("Downloading %s to %s"%(url,target_file)) 322 340 try: 323 341 with urllib.request.urlopen(url) as response, open(target_file, 'wb') as out_file: … … 332 350 st = os.stat(target_file) 333 351 except Exception as e: 334 self._debug("Unable to download %s"%url)335 self._debug("Reason: %s"%e)352 #self._debug("Unable to download %s"%url) 353 #self._debug("Reason: %s"%e) 336 354 target_file='' 337 355 return(target_file) … … 341 359 def _get_info(self,app_info): 342 360 #switch to launch async method when running under a gui 343 # For an unknown reason request will block when sync mode under a gui and asyncblocks when on cli (really funny)344 self._debug("Getting info for %s"%app_info)361 #Request will block when in sync mode under a gui and async mode blocks when on cli (really funny) 362 #self._debug("Getting info for %s"%app_info) 345 363 pkg=None 346 364 try: … … 350 368 except: 351 369 app_info['state']='available' 370 if not app_info['size']: 352 371 if self.cli_mode: 353 372 pkgs=self._search_snap(app_info['package'].replace('.snap',''),force_stable=False) 354 373 else: 355 374 pkgs=self._search_snap_async(app_info['package'].replace('.snap',''),force_stable=False) 356 self._debug("Getting extended info for %s %s"%(app_info['package'],pkgs))357 if type(pkgs)==type([]):358 for pkg in pkgs:359 self._debug("Getting extended info for %s"%app_info['name'])360 if pkg.get_download_size():361 app_info['size']=str(pkg.get_download_size())362 elif pkg.get_installed_size():363 app_info['size']=str(pkg.get_installed_size())364 else:365 app_info['size']="-1"366 break367 else:368 app_info['size']='0'369 self._debug("Info for %s"%app_info)375 #self._debug("Getting extended info for %s %s"%(app_info['package'],pkgs)) 376 if type(pkgs)==type([]): 377 for pkg in pkgs: 378 #self._debug("Getting extended info for %s"%app_info['name']) 379 if pkg.get_download_size(): 380 app_info['size']=str(pkg.get_download_size()) 381 elif pkg.get_installed_size(): 382 app_info['size']=str(pkg.get_installed_size()) 383 else: 384 app_info['size']="-1" 385 break 386 else: 387 app_info['size']='0' 388 #self._debug("Info for %s"%app_info) 370 389 self.partial_progress=100 371 390 return(app_info) … … 373 392 374 393 def _install_snap(self,app_info): 375 self._debug("Installing %s"%app_info['name']) 394 #self._debug("Installing %s"%app_info['name']) 395 def install(app_name,flags): 396 self.snap_client.install2_sync(flags,app_name.replace('.snap',''), 397 None, # channel 398 None, #revision 399 self._callback, (None,), 400 None) # cancellable 401 app_info['state']='installed' 402 self._set_status(0) 403 376 404 if app_info['state']=='installed': 377 405 self._set_status(4) 378 406 else: 379 407 try: 380 self.snap_client.install_sync(app_info['name'].replace('.snap',''), 381 None, # channel 382 self._callback, (None,), 383 None) # cancellable 384 app_info['state']='installed' 385 self._set_status(0) 408 install(app_info['name'],Snapd.InstallFlags.NONE) 386 409 except Exception as e: 387 print("Install error %s"%e) 388 self._set_status(5) 389 390 self._debug("Installed %s"%app_info) 410 try: 411 if e.code==19: 412 install(app_info['name'],Snapd.InstallFlags.CLASSIC) 413 except Exception as e: 414 #self._debug("Install error %s"%e) 415 self._set_status(5) 416 #self._debug("Installed %s"%app_info) 391 417 return app_info 392 418 #def _install_snap -
lliurex-store/trunk/fuentes/python3-lliurex-store.install/usr/share/lliurexstore/plugins/zmdManager.py
r7432 r8223 20 20 if hasattr(sys,'last_value') or not (os.path.exists(self.zmd_folder)): 21 21 #If there's an error at this point it only could be an importError caused by xmlrpc 22 print(" ERROR!!!!")22 print("ZMD support disabled") 23 23 self.disabled=True 24 24 self.plugin_actions={'install':'zmd','pkginfo':'zmd','remove':'zmd'} … … 33 33 def set_debug(self,dbg=True): 34 34 self.dbg=dbg 35 self._debug ("Debug enabled")35 #self._debug ("Debug enabled") 36 36 #def set__debug 37 37 … … 75 75 def _set_status(self,status,msg=''): 76 76 self.result['status']={'status':status,'msg':msg} 77 #def _set_status 77 78 78 79 def _callback(self,zmd_launcher): … … 89 90 def _install_Zmd(self,app_info): 90 91 zmd=self.zmd_folder+'/'+app_info['package']+'.zmd' 91 self._debug("Installing "+str(zmd))92 #self._debug("Installing "+str(zmd)) 92 93 app_info=self._get_Zmd_Info(app_info) 93 94 if app_info['state']=='installed': … … 98 99 try: 99 100 zmd_sudo=['pe',zmd] 100 self._debug("executing "+str(zmd_sudo))101 #self._debug("executing "+str(zmd_sudo)) 101 102 launched_zmd=subprocess.Popen(zmd_sudo,stdout=subprocess.PIPE,stdin=subprocess.PIPE,stderr=subprocess.PIPE) 102 103 zmd_launcher=os.path.basename(zmd) … … 107 108 zmd_status=launched_zmd.stdout.read() 108 109 zmd_err=launched_zmd.stderr.read() 109 self._debug("Error: "+str(zmd_err))110 self._debug("Result: "+str(zmd_status))110 #self._debug("Error: "+str(zmd_err)) 111 #self._debug("Result: "+str(zmd_status)) 111 112 except Exception as e: 112 self._debug(str(e)) 113 #self._debug(str(e)) 114 pass 113 115 finally: 114 116 app_info=self._get_Zmd_Info(app_info) … … 123 125 def _remove_Zmd(self,app_info): 124 126 zmd=app_info['package']+'.zmd' 125 self._debug("Removing "+str(zmd))127 #self._debug("Removing "+str(zmd)) 126 128 os.chdir(self.zmd_folder) 127 129 sw_continue=False … … 137 139 packagelist=packagelist[:-1] 138 140 #We've the file with the packagelist, now it's time to read the list 139 self._debug("Obtaining packages in : "+packagelist)141 #self._debug("Obtaining packages in : "+packagelist) 140 142 f2=open (packagelist,'r') 141 143 for line2 in f2: … … 143 145 pkg=pkg.split("\t")[0] 144 146 pkg=pkg.replace('"','') 145 self._debug("Append to remove list: "+pkg)147 #self._debug("Append to remove list: "+pkg) 146 148 remove_packages.append(pkg) 147 149 f2.close() … … 161 163 zmd_sudo=['gksudo',zmd_script] 162 164 try: 163 self._debug("Executing "+str(zmd_sudo))165 #self._debug("Executing "+str(zmd_sudo)) 164 166 zmd_launcher=os.path.basename(zmd) 165 167 zmd_launcher=os.path.splitext(zmd_launcher)[0] 166 168 launched_zmd=subprocess.Popen(zmd_sudo,stdout=subprocess.PIPE,stdin=subprocess.PIPE,stderr=subprocess.PIPE) 167 self._debug("Launched")169 #self._debug("Launched") 168 170 while launched_zmd.poll() is None: 169 171 self._callback(zmd_launcher) … … 173 175 except Exception as e: 174 176 err=6 175 self._debug(str(e))176 self._debug("Error: "+str(zmd_err))177 self._debug("Result: "+str(zmd_status))177 #self._debug(str(e)) 178 #self._debug("Error: "+str(zmd_err)) 179 #self._debug("Result: "+str(zmd_status)) 178 180 app_info=self._get_Zmd_Info(app_info) 179 181 if app_info['state']=='installed': -
lliurex-store/trunk/fuentes/python3-lliurex-store.install/usr/share/lliurexstore/storeManager.py
r8182 r8223 8 8 import json 9 9 import random 10 import time 11 from queue import Queue as pool 10 12 ###### 11 13 #Ver. 1.0 of storeManager.py … … 19 21 def __init__(self,*args,**kwargs): 20 22 self.dbg=False 21 if 'dbg' in kwargs.keys() :23 if 'dbg' in kwargs.keys() and self.dbg==False: 22 24 self.dbg=kwargs['dbg'] 25 self.autostart=True 26 if 'autostart' in kwargs.keys(): 27 self.autostart=kwargs['autostart'] 28 self._debug("Autostart actions: %s"%self.autostart) 23 29 self._propagate_dbg=False 24 30 self.store=None … … 34 40 } 35 41 self.cli_mode=[] #List that controls cli_mode for plugins 42 self.autostart_actions=[] #List with actions marked as autostart by plugins 43 self.postaction_actions=[] #List with actions that will be launched after other actions 44 self.required_parms={} 36 45 self.threads={} #Dict with the functions that must execute each action 37 46 self.static={} #Dict with the functions that must execute each action … … 51 60 self.__init_plugins__(**kwargs) #Function that loads the plugins 52 61 self.execute_action('load') #Initial load of the store 62 th=threading.Thread(target=self._autostart_actions) 63 th.start() 53 64 #def main 65 66 def _autostart_actions(self): 67 if self.autostart: 68 for autostart_action in self.autostart_actions: 69 self._debug("Autostart %s"%(autostart_action)) 70 self.execute_action(autostart_action) 54 71 55 72 #### … … 83 100 if target_class.disabled==None: 84 101 self._debug("Plugin %s will set its status"%plugin_name) 102 pass 85 103 else: 86 104 #Time to check if plugin is disabled or enabled by parm … … 104 122 sw_cli_mode=True 105 123 self._debug("Enabling cli mode for %s"%plugin_name) 124 if 'autostart_actions' in target_class.__dict__.keys(): 125 self.autostart_actions.append(target_class.__dict__['autostart_actions']) 126 if 'requires' in target_class.__dict__.keys(): 127 self.required_parms.update(target_class.__dict__['requires']) 128 if 'postaction_actions' in target_class.__dict__.keys(): 129 self.postaction_actions.append({target_class:target_class.__dict__['postaction_actions']}) 106 130 except Exception as e: 107 131 print ("Can't initialize %s %s"%(mod,target_class)) … … 140 164 def _define_functions_for_threads(self): 141 165 self.threads['load']="threading.Thread(target=self._load_Store)" 142 self.threads['get_info']="threading.Thread(target=self._get_App_Info, args=args,kwargs=kwargs)"143 self.threads['pkginfo']="threading.Thread(target=self._get_Extended_App_Info, args=args,kwargs=kwargs)"144 self.threads['search']='threading.Thread(target=self._search_Store, args=args,kwargs=kwargs)'145 self.threads['list']='threading.Thread(target=self._search_Store, args=args,kwargs=kwargs)'166 self.threads['get_info']="threading.Thread(target=self._get_App_Info,daemon=True,args=args,kwargs=kwargs)" 167 self.threads['pkginfo']="threading.Thread(target=self._get_Extended_App_Info,daemon=True,args=args,kwargs=kwargs)" 168 self.threads['search']='threading.Thread(target=self._search_Store,daemon=True,args=args,kwargs=kwargs)' 169 self.threads['list']='threading.Thread(target=self._search_Store,daemon=True,args=args,kwargs=kwargs)' 146 170 # self.threads['list']='threading.Thread(target=self._get_editors_pick,args=args,kwargs=kwargs)' 147 self.threads['info']='threading.Thread(target=self._search_Store, args=args,kwargs=kwargs)'148 self.threads['install']='threading.Thread(target=self._install_remove_App, args=args,kwargs=kwargs)'149 self.threads['remove']='threading.Thread(target=self._install_remove_App, args=args,kwargs=kwargs)'150 self.threads['list_sections']='threading.Thread(target=self._list_sections, args=args,kwargs=kwargs)'171 self.threads['info']='threading.Thread(target=self._search_Store,daemon=True,args=args,kwargs=kwargs)' 172 self.threads['install']='threading.Thread(target=self._install_remove_App,daemon=True,args=args,kwargs=kwargs)' 173 self.threads['remove']='threading.Thread(target=self._install_remove_App,daemon=True,args=args,kwargs=kwargs)' 174 self.threads['list_sections']='threading.Thread(target=self._list_sections,daemon=True,args=args,kwargs=kwargs)' 151 175 self.static['random']='self._get_editors_pick(kwargs=kwargs)' 152 176 #def _define_functions_for_threads … … 157 181 # - action to be executed 158 182 # - parms for the action 183 #Action must be a kwarg but for retrocompatibility reasons we keep it as an arg 159 184 #### 160 185 def execute_action(self,action,*args,**kwargs): 161 #Action must be a kwarg but for retrocompatibility reasons we keep it as an arg 162 kwargs.update({"action":action}) 186 autostart_action=False 187 #Check for autolaunchable actions 188 if type(action)==type({}): 189 autostart_action=True 190 aux_action=list(action.keys())[0] 191 kwargs.update({"action":aux_action}) 192 (key,value)=action[aux_action].split('=') 193 kwargs.update({key:value}) 194 action=aux_action 195 else: 196 kwargs.update({"action":action}) 197 if action in self.required_parms.keys(): 198 (key,value)=self.required_parms[action].split('=') 199 kwargs.update({key:value}) 163 200 self._debug("Launching action: %s with args %s and kwargs %s"%(action,args,kwargs)) 164 201 if self.is_action_running('load'): 165 202 self._join_action('load') 203 self._debug("Total apps: %s"%str(len(self.store.get_apps()))) 166 204 self._debug("Resumed action %s"%action) 167 205 sw_track_status=False … … 172 210 for package_type,plugin in self.plugins_registered[action].items(): 173 211 self.action_progress[action]=0 174 self.threads[action]='threading.Thread(target=self._execute_class_method(action,package_type,action).execute_action,args=[action],kwargs={kwargs})' 212 if kwargs: 213 kargs={} 214 for arg_name in kwargs: 215 try: 216 kargs.update({arg_name:eval(kwargs[arg_name])}) 217 except: 218 kargs.update({arg_name:kwargs[arg_name]}) 219 kwargs=kargs.copy() 220 self.threads[action]='threading.Thread(target=self._execute_class_method(action,package_type).execute_action,daemon=True,args=[],kwargs=kwargs)' 175 221 break 176 222 self._debug('Plugin for %s found: %s'%(action,self.plugins_registered[action])) 177 self.related_actions.update({action:[action]}) 223 if not autostart_action: 224 self.related_actions.update({action:[action]}) 178 225 sw_track_status=True 179 226 if action in self.threads.keys(): … … 183 230 self.running_threads[action].join() 184 231 try: 185 if action in self.action_progress.keys():186 self.action_progress[action]=0187 232 self.action_progress[action]=0 188 233 self.result[action]={} 189 self.running_threads [action]=eval(self.threads[action])234 self.running_threads.update({action:eval(self.threads[action])}) 190 235 self.running_threads[action].start() 236 if not self.running_threads[action].is_alive(): 237 self._debug("Relaunching!!!!!!") 238 self.running_threads.update({action:eval(self.threads[action])}) 239 self.running_threads[action].start() 191 240 if sw_track_status: 192 241 self.result[action]['status']={'status':0,'msg':''} … … 194 243 self.result[action]['status']={'status':-1,'msg':''} 195 244 self._debug("Thread %s for action %s launched"%(self.running_threads[action],action)) 245 self._debug("Thread count: %s"%(threading.active_count())) 196 246 197 247 except Exception as e: … … 201 251 elif action in self.static.keys(): 202 252 self.action_progress[action]=0 203 self.result[action]={} 204 self.result[action]['data']=eval(self.static[action]) 205 self.result[action]['status']={'status':0,'msg':''} 253 self.result[action].update({'data':eval(self.static[action])}) 254 self.result[action].update({'status':{'status':0,'msg':''}}) 206 255 self.action_progress[action]=100 207 256 208 257 else: 209 258 self._debug("No function associated with action %s"%action) 259 pass 210 260 #def execute_action 211 261 212 ####213 #Launch the appropiate class function214 #Input:215 # - class action to be executed216 # - parms for the action217 # - parent action that demands the execution218 #Output219 # - The class method to execute220 ####221 262 def _execute_class_method(self,action,package_type,*args,launchedby=None,**kwargs): 222 263 exe_function=None 223 264 if not package_type: 224 265 package_type="*" 225 if action in self.plugins_registered :266 if action in self.plugins_registered.keys(): 226 267 self._debug("Plugin for %s: %s"%(action,self.plugins_registered[action][package_type])) 227 exe_function=eval(self.plugins_registered[action][package_type]+"("+','.join(args)+")") 268 try: 269 self._debug(self.plugins_registered[action][package_type]+"("+','.join(args)+")") 270 exe_function=eval(self.plugins_registered[action][package_type]+"("+','.join(args)+")") 271 except Exception as e: 272 self._debug("Can't launch execute_method for class %s"%e) 273 pass 228 274 if self._propagate_dbg: 229 275 exe_function.set_debug(self.dbg) … … 233 279 else: 234 280 self._debug("No plugin for action: %s"%action) 281 pass 235 282 if kwargs: 236 283 self._debug("Parms: %s"%kwargs) 284 pass 237 285 return (exe_function) 238 286 #def _execute_class_method … … 283 331 self._debug("Unable to join thread for: %s"%action) 284 332 self._debug("Reason: %s"%e) 333 pass 285 334 finally: 286 335 if action in self.running_threads.keys(): … … 368 417 if self.is_action_running(action): 369 418 self._join_action(action) 370 result[action]= None419 result[action]=[] 371 420 if action in self.result: 372 421 if 'data' in self.result[action]: 373 422 result[action]=self.result[action]['data'] 423 if len(self.result[action]['data'])<1: 424 self._debug("ERROR NO DATA") 425 self._debug("ERROR NO DATA") 426 self._debug("ERROR NO DATA") 427 self._debug("ERROR NO DATA") 428 result[action]=[""] 374 429 else: 375 result[action]=[ ]430 result[action]=[""] 376 431 self.lock.release() 377 432 if action in self.extra_actions.keys(): … … 418 473 self.store=load_function.execute_action(action=action,store=self.store)['data'] 419 474 #Once appstream is loaded load the appstream plugins for other package types (snap, appimage...) 475 store_pool=pool() 476 threads=[] 420 477 for package_type in self.plugins_registered[action]: 421 478 if package_type!='*': 422 load_function=self._execute_class_method(action,package_type,launchedby=None) 423 self.store=load_function.execute_action(action=action,store=self.store)['data'] 479 th=threading.Thread(target=self._th_load_store, args = (store_pool,action,package_type)) 480 threads.append(th) 481 th.start() 482 for thread in threads: 483 try: 484 thread.join() 485 except: 486 pass 487 while store_pool.qsize(): 488 self.store=store_pool.get() 424 489 #def _load_Store 490 491 def _th_load_store(self,store_pool,action,package_type): 492 load_function=self._execute_class_method(action,package_type,launchedby=None) 493 store_pool.put(load_function.execute_action(action=action,store=self.store)['data']) 425 494 426 495 #### … … 523 592 action='get_info' 524 593 info_function=self._execute_class_method(action,None,launchedby=launchedby) 525 info_applist=info_function.execute_action( self.store,action,applist)594 info_applist=info_function.execute_action(action,applist) 526 595 self._debug("Info collected") 527 596 return(info_applist) … … 544 613 processed=[] 545 614 for app_info in info_applist: 546 if channel: 547 types_dict[channel]=[app_info] 548 else: 549 available_channels=self._check_package_type(app_info) 550 for package_type in available_channels: 551 if app_info['component']!='': 552 if app_info['id'] in processed: 553 self._debug("App %s processed"%app_info['id']) 554 continue 555 556 if package_type in types_dict: 557 types_dict[package_type].append(app_info) 558 else: 559 types_dict[package_type]=[app_info] 560 processed.append(app_info['id']) 615 info_function=self._execute_class_method(action,'*',launchedby=launchedby) 616 info_result=info_function.execute_action(action,applist=[app_info]) 617 self._debug(info_result) 618 if info_result['status']['status']==0 and info_result['data'][0]['state']: 619 result['data'].extend(info_result['data']) 620 elif info_result['status']['status']==0: 621 app_info=info_result['data'][0] 622 #Get channel 623 available_channels=self._check_package_type(app_info) 624 for package_type in available_channels: 625 if app_info['component']!='': 626 if app_info['id'] in processed: 627 self._debug("App %s processed"%app_info['id']) 628 continue 629 630 if package_type in types_dict: 631 types_dict[package_type].append(app_info) 632 else: 633 types_dict[package_type]=[app_info] 634 processed.append(app_info['id']) 561 635 for package_type in types_dict: 562 636 self._debug("Checking plugin for %s %s"%(action,package_type)) … … 647 721 if fullsearch: 648 722 #2.- Get rest of metadata (slower) 649 subordinate_action='pkginfo'650 723 self._debug("Target channel: %s"%target_channel) 651 724 result=self._get_Extended_App_Info(result['data'],launchedby,fullsearch,target_channel) … … 658 731 result['status']['status']=0 659 732 else: 733 self._debug(result) 660 734 return_msg=False 661 735 else: … … 743 817 # app['appstream_id'].set_state(2) 744 818 # self._debug("App state changed to available") 819 for app in types_dict[package_type]: 820 self._execute_postactions(action,app['package']) 745 821 return_msg=True 746 822 self._log("Result %s: %s"%(action,self.result[action])) … … 773 849 return(return_msg) 774 850 #def _check_package_type 851 852 def _execute_postactions(self,action,app): 853 for postaction in self.postaction_actions: 854 for plugin,actions in postaction.items(): 855 for key,val in actions.items(): 856 if action==key: 857 self._debug("Application: %s"%app) 858 plugin.execute_action(key,applist=app)
Note: See TracChangeset
for help on using the changeset viewer.