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