Changeset 7471 for lliurex-store
- Timestamp:
- Jun 15, 2018, 10:20:49 AM (3 years ago)
- Location:
- lliurex-store/trunk/fuentes
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
lliurex-store/trunk/fuentes/lliurex-store-cli/usr/share/lliurex-store/lliurex-store-cli.py
r7143 r7471 28 28 results=store.get_result(action) 29 29 status=store.get_status(action) 30 print("ST: %s"%status) 30 31 if not 'status' in status.keys(): 31 32 status['status']=1 … … 101 102 print(data['package']+" "+ _(u"removed")+" "+color.BOLD+ _(u"succesfully")+color.END) 102 103 else: 103 print( data)104 print("RESULT:\n%s"%data) 104 105 else: 105 106 msg=_(u"Unable to")+' '+_(action) … … 141 142 actions.append('remove') 142 143 parms['remove']=args.remove 144 # if args.random: 145 # actions.append('random') 146 # parms['random']=args.random 143 147 # if args.list: 144 148 # actions.append('list') 145 149 # parms['list']=args.list 146 150 147 actionList={'search':False,'info':False,'pkgInfo':False,'install':False,'remove':False,'list':False,'list-sections':False }151 actionList={'search':False,'info':False,'pkgInfo':False,'install':False,'remove':False,'list':False,'list-sections':False,'random':False} 148 152 start_time=time.time() 149 153 store=storeManager.StoreManager(appimage=appimage,snap=snap,dbg=dbg,cli=True) … … 172 176 print (CURSOR_UP + ERASE_LINE) 173 177 actionList[key]=print_results(key) 174 print_results()178 # print_results('random') 175 179 176 180 def process_Args(args): … … 180 184 parser.add_argument('-i','--install',metavar='Package',help=(_(u"Install a package"))) 181 185 parser.add_argument('-r','--remove',metavar='Package',help=(_(u"Remove a package"))) 186 # parser.add_argument('--random',metavar='Results',help=(_(u"List random packages"))) 182 187 # parser.add_argument('--debug',action='store_true',help=(_(u"Prints debug information"))) 183 188 parser.add_argument('--appimage',action='store_true',help=(_(u"Load appimage catalog"))) -
lliurex-store/trunk/fuentes/python3-lliurex-store.install/usr/share/lliurexstore/storeManager.py
r7435 r7471 7 7 import lliurexstore.plugins as plugins 8 8 import json 9 import random 9 10 ###### 10 11 #Ver. 1.0 of storeManager.py … … 17 18 class StoreManager(): 18 19 def __init__(self,*args,**kwargs): 19 self.dbg=False20 20 if 'dbg' in kwargs.keys(): 21 21 self.dbg=kwargs['dbg'] 22 self.dbg=True 22 23 self._propagate_dbg=False 23 24 self.store=None … … 34 35 self.cli_mode=[] #List that controls cli_mode for plugins 35 36 self.threads={} #Dict with the functions that must execute each action 37 self.static={} #Dict with the functions that must execute each action 36 38 self.threads_progress={} #"" "" "" the progress for each launched thread 37 39 self.running_threads={} #"" "" "" the running threads … … 84 86 #Time to check if plugin is disabled or enabled by parm 85 87 #Values for the plugins_registered dict must be the same as the parm name that enables the plugin 86 for key,value in class_actions.items():87 val=value88 for class_action,class_plugin_name in class_actions.items(): 89 class_plugin=class_plugin_name 88 90 break 89 if valin kwargs.keys():90 if kwargs[ val]==True:91 if class_plugin in kwargs.keys(): 92 if kwargs[class_plugin]==True: 91 93 if target_class.disabled: 92 94 self._debug("Disabling plugin %s"%plugin_name) … … 141 143 self.threads['pkginfo']="threading.Thread(target=self._get_Extended_App_Info,args=args,kwargs=kwargs)" 142 144 self.threads['search']='threading.Thread(target=self._search_Store,args=args,kwargs=kwargs)' 143 self.threads['list']='threading.Thread(target=self._search_Store,args=args,kwargs=kwargs)' 145 # self.threads['list']='threading.Thread(target=self._search_Store,args=args,kwargs=kwargs)' 146 # self.threads['list']='threading.Thread(target=self._get_editors_pick,args=args,kwargs=kwargs)' 144 147 self.threads['info']='threading.Thread(target=self._search_Store,args=args,kwargs=kwargs)' 145 148 self.threads['install']='threading.Thread(target=self._install_remove_App,args=args,kwargs=kwargs)' 146 149 self.threads['remove']='threading.Thread(target=self._install_remove_App,args=args,kwargs=kwargs)' 147 150 self.threads['list_sections']='threading.Thread(target=self._list_sections,args=args,kwargs=kwargs)' 151 self.static['random']='self._get_editors_pick(kwargs=kwargs)' 148 152 #def _define_functions_for_threads 149 153 … … 195 199 self._debug("Reason: %s"%e) 196 200 pass 201 elif action in self.static.keys(): 202 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':''} 206 self.action_progress[action]=100 207 197 208 else: 198 209 self._debug("No function associated with action %s"%action) … … 243 254 244 255 for action in action_list: 256 if action in self.static.keys(): 257 if self.action_progress[action]!=100: 258 status=True 245 259 if action in self.running_threads.keys(): 246 260 if self.running_threads[action].is_alive(): … … 307 321 progress={'search':0,'list':0,'install':0,'remove':0,'load':0,'list_sections':0} 308 322 action_list=[] 309 if action in self.register_action_progress.keys(): 310 action_list=[action] 311 else: 312 action_list=self.register_action_progress.keys() 313 self.lock.acquire() #prevent that any thread attempts to change the iterator 314 for parent_action in self.related_actions.keys(): 315 if self.is_action_running(parent_action): 316 for action in action_list: 317 if parent_action in self.threads_progress.keys(): 318 acum_progress=0 319 for threadfunction,function in self.threads_progress[parent_action].items(): 320 acum_progress=acum_progress+function.progress 321 322 count=len(self.related_actions[parent_action]) 323 self.action_progress[parent_action]=round(acum_progress/count,0) 324 progress[parent_action]=self.action_progress[parent_action] 323 if action in self.static.keys(): 324 pass 325 else: 326 if action in self.register_action_progress.keys(): 327 action_list=[action] 325 328 else: 326 #put a 100% just in case 327 if parent_action in self.action_progress.keys(): 328 self.action_progress[parent_action]=100 329 self.lock.release() 329 action_list=self.register_action_progress.keys() 330 self.lock.acquire() #prevent that any thread attempts to change the iterator 331 for parent_action in self.related_actions.keys(): 332 if self.is_action_running(parent_action): 333 for action in action_list: 334 if parent_action in self.threads_progress.keys(): 335 acum_progress=0 336 for threadfunction,function in self.threads_progress[parent_action].items(): 337 acum_progress=acum_progress+function.progress 338 339 count=len(self.related_actions[parent_action]) 340 self.action_progress[parent_action]=round(acum_progress/count,0) 341 progress[parent_action]=self.action_progress[parent_action] 342 else: 343 #put a 100% just in case 344 if parent_action in self.action_progress.keys(): 345 self.action_progress[parent_action]=100 346 self.lock.release() 330 347 return(self.action_progress) 331 348 #def get_progress … … 388 405 result['msg']=u"Unknown error" 389 406 self.lock.release() 407 print("RESULT %s: %s"%(action,result)) 390 408 return(result) 391 409 #def get_status … … 407 425 #def _load_Store 408 426 427 def _get_editors_pick(self,*args,**kwargs): 428 429 def load_applist(): 430 attempts=0 431 tmp_app=random.choice(tmp_applist) 432 while tmp_app in applist or tmp_app.get_state()==1: 433 tmp_app=random.choice(tmp_applist) 434 attempts+=1 435 if attempts==9: 436 tmp_app=None 437 break 438 return(tmp_app) 439 440 def select_applist(): 441 start_point=random.randint(0,total_apps) 442 end_point=start_point+10 443 if end_point>total_apps: 444 diff=end_point-total_apps 445 end_point=total_apps 446 start_point-=diff 447 tmp_applist=apps_in_store[start_point:end_point] 448 return(tmp_applist) 449 exclude_sections=[] 450 only_sections=[] 451 if 'exclude_sections' in kwargs.keys(): 452 exclude_sections=kwargs['exclude_sections'] 453 if 'only_sections' in kwargs.keys(): 454 only_sections=kwargs['only_sections'] 455 applist=[] 456 apps_in_store=self.store.get_apps() 457 cont=0 458 total_apps=len(apps_in_store)-1 459 tmp_applist=select_applist() 460 max_results=10 461 while cont<max_results: 462 tmp_app=load_applist() 463 while tmp_app==None: 464 tmp_applist=select_applist() 465 tmp_app=load_applist() 466 applist.append(tmp_app) 467 cont+=1 468 #Now transform applist into an app_info list 469 appinfo=self._get_App_Info(applist) 470 return(appinfo) 471 409 472 #### 410 473 #Loads the info related to one app … … 418 481 info_function=self._execute_class_method(action,None,launchedby=launchedby) 419 482 info_applist=info_function.execute_action(self.store,action,applist) 483 self._debug("Info collected") 420 484 return(info_applist) 421 485 #def _get_App_Info
Note: See TracChangeset
for help on using the changeset viewer.