#!/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_base_dir="/usr/share/llx-pool/actions/" self.actions_dir=self.actions_base_dir+"/%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.select_distro_step() #self.welcome_step() def select_distro_step(self): available_actions={} count=1 print("") print(colored("llx-pool> ","green",attrs=["bold"]) + "Select distribution to work on:") for x in sorted(os.listdir(self.actions_base_dir)): available_actions[str(count)]=x count+=1 available_actions["e"]=False available_actions["q"]=False action=None while action not in available_actions: print("") for action in available_actions: if available_actions[action]!=False: print("\t[%s] %s"%(action,available_actions[action])) print("") print("\t[e/q] Exit") print("") action=raw_input(colored("llx-pool> ","green",attrs=["bold"])) if action=="e" or action=="q": print("") sys.exit(0) self.actions_dir=self.actions_base_dir+"/%s/*"%available_actions[action] self.parse_actions(self.actions_dir) self.welcome_step() #def select_distro_step def welcome_step(self): available_options=["0","1","2","3","e","q","c"] 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[c] Change distro") 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=="c": self.select_distro_step() 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","c"] actions=[] if section in self.actions_dir: for w in sorted(self.actions_dir[section]): actions.append(self.actions_dir[section][w]) available_options.append(str(count)) count+=1 i=None while i 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[c] Change distro") print("\t[e/q] Exit LliureX Pool") print("") i=raw_input(colored("llx-pool> ","green",attrs=["bold"])) if i=="e" or i=="q": sys.exit(0) if i=="c": self.select_distro_step() if i=="g": self.welcome_step() cmd=actions[int(i)-1][1] os.system(cmd) self.welcome_step() #def show_ #class LP if __name__=="__main__": lp=LliurexPool() lp.run()