1 | #!/usr/bin/python3 |
---|
2 | import sys |
---|
3 | import argparse |
---|
4 | #sys.path.append('/usr/share/lliurex-store') |
---|
5 | #sys.path.append('/home/lliurex/lliurex-store/trunk/fuentes/lliurex-appstore.install/usr/share/lliurex-store') |
---|
6 | import lliurexstore.storeManager as storeManager |
---|
7 | import time |
---|
8 | |
---|
9 | class color: |
---|
10 | PURPLE = '\033[95m' |
---|
11 | CYAN = '\033[96m' |
---|
12 | DARKCYAN = '\033[36m' |
---|
13 | BLUE = '\033[94m' |
---|
14 | GREEN = '\033[92m' |
---|
15 | YELLOW = '\033[93m' |
---|
16 | RED = '\033[91m' |
---|
17 | BOLD = '\033[1m' |
---|
18 | UNDERLINE = '\033[4m' |
---|
19 | END = '\033[0m' |
---|
20 | |
---|
21 | def main(): |
---|
22 | def print_results(action=None): |
---|
23 | printed=False |
---|
24 | results=store.get_result(action) |
---|
25 | status=store.get_status(action) |
---|
26 | print ("") |
---|
27 | for action in results.keys(): |
---|
28 | if action in actions and not actionList[action]: |
---|
29 | print (u"Results for "+action) |
---|
30 | if status['status']==0: |
---|
31 | for data in results[action]: |
---|
32 | if action=='search': |
---|
33 | if args.info: |
---|
34 | try: |
---|
35 | print(color.BOLD+u'Package: '+color.END + data['package']) |
---|
36 | print(u'Version: '+data['version']) |
---|
37 | print(u'Categories: '+','.join(data['categories'])) |
---|
38 | print(u'Status: '+data['state']) |
---|
39 | print(u'Summary: '+data['summary']) |
---|
40 | print(u'Description: '+data['description']) |
---|
41 | pkgString=[] |
---|
42 | for dependency in data['depends']: |
---|
43 | pkgName=dependency.split(';')[0] |
---|
44 | pkgString.append(pkgName) |
---|
45 | print(u'Depends: '+' '+','.join(pkgString)) |
---|
46 | print("") |
---|
47 | except: |
---|
48 | pass |
---|
49 | else: |
---|
50 | #Only print name and summary |
---|
51 | print(color.BOLD+data['package']+color.END+": "+data['summary']) |
---|
52 | elif action=='list': |
---|
53 | #Print package, summary and status |
---|
54 | try: |
---|
55 | if data['package']: |
---|
56 | package=data['package'] |
---|
57 | else: |
---|
58 | package=data['name'] |
---|
59 | print(color.BOLD+package+color.END+": "+data['summary']+' ('+','.join(data['categories'])+')'+' ('+data['state']+')') |
---|
60 | except Exception as e: |
---|
61 | print('Error listing :'+str(e)) |
---|
62 | pass |
---|
63 | elif action=='install': |
---|
64 | for app in data: |
---|
65 | print(app+' '+data[app]) |
---|
66 | else: |
---|
67 | print(data) |
---|
68 | else: |
---|
69 | print (u"Error: "+str(status['status'])) |
---|
70 | printed=True |
---|
71 | return(printed) |
---|
72 | #def print_results |
---|
73 | |
---|
74 | CURSOR_UP='\033[F' |
---|
75 | ERASE_LINE='\033[K' |
---|
76 | actions=[] |
---|
77 | parms={} |
---|
78 | args=process_Args(sys.argv) |
---|
79 | store=storeManager.StoreManager(args.debug) |
---|
80 | |
---|
81 | ''' if args.debug: |
---|
82 | actions.append('debug') |
---|
83 | store.set_debug(args.debug) |
---|
84 | parms['debug']=args.debug''' |
---|
85 | if (args.search or args.info): |
---|
86 | actions.append('search') |
---|
87 | if args.info: |
---|
88 | args.search=args.info |
---|
89 | parms['search']=args.search |
---|
90 | if args.install: |
---|
91 | actions.append('install') |
---|
92 | parms['install']=args.install |
---|
93 | if args.remove: |
---|
94 | actions.append('remove') |
---|
95 | parms['remove']=args.remove |
---|
96 | if args.list: |
---|
97 | actions.append('list') |
---|
98 | parms['list']=args.list |
---|
99 | if args.list_sections: |
---|
100 | actions.append('list_sections') |
---|
101 | parms['list_sections']=args.list_sections |
---|
102 | |
---|
103 | actionList={'search':False,'info':False,'pkgInfo':False,'install':False,'remove':False} |
---|
104 | start_time=time.time() |
---|
105 | for action in actions: |
---|
106 | # print(u"Launching: "+action) |
---|
107 | store.execute_action(action,parms[action]) |
---|
108 | actionList[action]=False |
---|
109 | |
---|
110 | # print ("All actions launched: " +str(actions)) |
---|
111 | while store.is_action_running(): |
---|
112 | progressDic=store.get_progress() |
---|
113 | progressArray=[] |
---|
114 | for progress in progressDic: |
---|
115 | if progress!='load': |
---|
116 | progressArray.append(progress+': '+str(int(progressDic[progress]))+'%') |
---|
117 | print(','.join(progressArray),end="\r") |
---|
118 | time.sleep(0.1) |
---|
119 | for key in actionList: |
---|
120 | progressDic=store.get_progress(key) |
---|
121 | if key in progressDic: |
---|
122 | if progressDic[key]==100 and not actionList[key]: |
---|
123 | progressDic=store.get_progress(key) |
---|
124 | progressArray=[] |
---|
125 | for progress in progressDic: |
---|
126 | if progress!='load': |
---|
127 | progressArray.append(progress+': '+str(progressDic[progress])+'%') |
---|
128 | print(','.join(progressArray)) |
---|
129 | print (CURSOR_UP + ERASE_LINE) |
---|
130 | actionList[key]=print_results(key) |
---|
131 | print_results() |
---|
132 | |
---|
133 | def process_Args(args): |
---|
134 | parser=argparse.ArgumentParser(description=(u'Lliurex Software Center')) |
---|
135 | parser.add_argument('--list',metavar="Category",action='append',nargs='?',help=(u"List all packages, optionally list packages from a given category")) |
---|
136 | parser.add_argument('--list-sections',action='store_true',help=(u"List all sections from the store")) |
---|
137 | parser.add_argument('--search',metavar='Name',nargs='?',help=(u"Search a package")) |
---|
138 | parser.add_argument('--info',metavar='Name',nargs='?',help=(u"Show all info from a package")) |
---|
139 | parser.add_argument('--install',metavar='Package',help=(u"Install a package")) |
---|
140 | parser.add_argument('--remove',metavar='Package',help=(u"Remove a package")) |
---|
141 | parser.add_argument('--debug',action='store_true',help=(u"Prints debug information")) |
---|
142 | |
---|
143 | args=parser.parse_args() |
---|
144 | return args |
---|
145 | |
---|
146 | main() |
---|