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