#!/usr/bin/env python import os import glob import sys import signal signal.signal(signal.SIGINT, signal.SIG_DFL) from termcolor import colored CURRENT_DISTRO="trusty" class LliurexPool: def __init__(self): self.actions_dir="/usr/share/llx-pool/actions/%s/*"%CURRENT_DISTRO self.parse_actions(self.actions_dir) #def init def check_root(self): try: f=open("/run/llx-pool.pid","w") f.write(str(os.getpid())) f.close() return True except: return False #def check_root def parse_actions(self,actions_dir): actions=glob.glob(actions_dir) self.actions_dir={} for action in actions: f=open(action) lines=f.readlines() f.close() section="UNKOWN" weight=999 comment="" for line in lines: if "SECTION" in line: section=line.split("=")[1].strip("\n").replace('"',"") if "WEIGHT" in line: weight=int(line.split("=")[1].strip("\n")) if "COMMENT" in line: comment=line.split("=")[1].strip("\n").replace('"',"") break if section not in self.actions_dir: self.actions_dir[section]={} while weight in self.actions_dir[section]: weight+=1 self.actions_dir[section][weight]=(comment,action) #def parse_actions def run(self): if not self.check_root(): print("You need administration privileges to run this program. Exiting...") sys.exit(1) print("") print( colored("# LliureX Pool ","blue")) print(colored("===============","cyan")) self.welcome_step() def welcome_step(self): available_options=["0","1","2","3","e","q"] i=None while i not in available_options: print("") print(colored("llx-pool> ","green",attrs=["bold"]) + "What do you want to do?") print("") print("\t[0] Update lists operations") print("") print("\t[1] Check possible updates operations") print("\t[2] Pool operations") print("\t[3] Synchronization operations") print("") print("\t[e/q] Exit") print("") i=raw_input(colored("llx-pool> ","green",attrs=["bold"])) if i=="e" or i=="q": sys.exit(0) if i=="1": self.show_operations("check") if i=="2": self.show_operations("update") if i=="3": self.show_operations("sync") if i=="0": self.show_operations("lists") #def step0 def show_operations(self,section): count=1 available_options=["e","g","q"] actions=[] for w in sorted(self.actions_dir[section]): actions.append(self.actions_dir[section][w]) available_options.append(str(count)) count+=1 input=None while input not in available_options: print("") count=0 for action in actions: print("\t[%s] %s"%(count+1,actions[count][0])) count+=1 print("") print("\t[g] Go back") print("\t[e/q] Exit LliureX Pool") print("") input=raw_input(colored("llx-pool> ","green",attrs=["bold"])) if input=="e" or input=="q": sys.exit(0) if input=="g": self.welcome_step() cmd=actions[int(input)-1][1] os.system(cmd) self.welcome_step() #def show_ #class LP if __name__=="__main__": lp=LliurexPool() lp.run()