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 gettext |
---|
9 | es = gettext.translation('es', localedir='locale', languages=['es']) |
---|
10 | es.install() |
---|
11 | import html2text |
---|
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 | print(_(u'Categories')+': '+','.join(data['categories'])) |
---|
46 | msg='' |
---|
47 | if data['state']=='installed': |
---|
48 | msg=_('installed') |
---|
49 | else: |
---|
50 | msg=_('available') |
---|
51 | print(_(u'Status')+': '+msg) |
---|
52 | print(_(u'Summary')+': '+data['summary']) |
---|
53 | desc=(html2text.html2text(data['description'],"lxml")) |
---|
54 | # print(u'Description'+': '+data['description']) |
---|
55 | print(_(u'Description')+': '+desc) |
---|
56 | pkgString=[] |
---|
57 | for dependency in data['depends']: |
---|
58 | pkgName=dependency.split(';')[0] |
---|
59 | pkgString.append(pkgName) |
---|
60 | print(_(u'Depends')+': '+', '.join(pkgString)) |
---|
61 | print("") |
---|
62 | except Exception as e: |
---|
63 | print(e) |
---|
64 | pass |
---|
65 | elif action=='search': |
---|
66 | #Only print name and summary |
---|
67 | if data['package'] not in data['id'] or data['package'] in processed: |
---|
68 | print(color.DARKCYAN+data['package']+color.END+" ("+data['id']+"): "+data['summary']) |
---|
69 | else: |
---|
70 | print(color.DARKCYAN+data['package']+color.END+": "+data['summary']) |
---|
71 | processed.append(data['package']) |
---|
72 | |
---|
73 | elif action=='list': |
---|
74 | #Print package, summary and status |
---|
75 | try: |
---|
76 | if data['package']: |
---|
77 | package=data['package'] |
---|
78 | else: |
---|
79 | package=data['name'] |
---|
80 | if data['state']=='installed': |
---|
81 | msg=_('installed') |
---|
82 | else: |
---|
83 | msg=_('available') |
---|
84 | print(color.DARKCYAN+package+color.END+": "+data['summary']+' ('+','.join(data['categories'])+')'+' ('+msg+')') |
---|
85 | except Exception as e: |
---|
86 | print(_(u'Error listing :')+str(e)) |
---|
87 | pass |
---|
88 | elif action=='install': |
---|
89 | print(data['package']+" "+ _(u"installed")+" "+color.BOLD+ _(u"succesfully")+color.END) |
---|
90 | elif action=='remove': |
---|
91 | print(data['package']+" "+ _(u"removed")+" "+color.BOLD+ _(u"succesfully")+color.END) |
---|
92 | else: |
---|
93 | print(data) |
---|
94 | else: |
---|
95 | msg=_(u"Unable to")+' '+_(action) |
---|
96 | failed=parms[action] |
---|
97 | if (action=='search' or action=='info'): |
---|
98 | msg=_(u"Unable to show") |
---|
99 | if action=='list': |
---|
100 | # msg=_(u"Category") |
---|
101 | failed=', '.join(failed) |
---|
102 | |
---|
103 | print (color.RED+_(u"Error")+": "+color.END+msg+' '+failed+' ('+_(status['msg'])+')') |
---|
104 | printed=True |
---|
105 | return(printed) |
---|
106 | #def print_results |
---|
107 | |
---|
108 | CURSOR_UP='\033[F' |
---|
109 | ERASE_LINE='\033[K' |
---|
110 | actions=[] |
---|
111 | parms={} |
---|
112 | args=process_Args(sys.argv) |
---|
113 | if 'debug' in args: |
---|
114 | dbg=1 |
---|
115 | else: |
---|
116 | dbg=None |
---|
117 | store=storeManager.StoreManager(dbg) |
---|
118 | |
---|
119 | ''' if args.debug: |
---|
120 | actions.append('debug') |
---|
121 | store.set_debug(args.debug) |
---|
122 | parms['debug']=args.debug''' |
---|
123 | if args.info: |
---|
124 | actions.append('info') |
---|
125 | parms['info']=args.info |
---|
126 | if args.search: |
---|
127 | actions.append('search') |
---|
128 | parms['search']=args.search |
---|
129 | if args.install: |
---|
130 | actions.append('install') |
---|
131 | parms['install']=args.install |
---|
132 | if args.remove: |
---|
133 | actions.append('remove') |
---|
134 | parms['remove']=args.remove |
---|
135 | # if args.list: |
---|
136 | # actions.append('list') |
---|
137 | # parms['list']=args.list |
---|
138 | # if args.list_sections: |
---|
139 | # actions.append('list_sections') |
---|
140 | # parms['list_sections']=args.list_sections |
---|
141 | |
---|
142 | actionList={'search':False,'info':False,'pkgInfo':False,'install':False,'remove':False,'list':False,'list-sections':False} |
---|
143 | start_time=time.time() |
---|
144 | for action in actions: |
---|
145 | # print(u"Launching: "+action) |
---|
146 | store.execute_action(action,parms[action]) |
---|
147 | actionList[action]=False |
---|
148 | |
---|
149 | # print ("All actions launched: " +str(actions)) |
---|
150 | while store.is_action_running(): |
---|
151 | progressDic=store.get_progress() |
---|
152 | progressArray=[] |
---|
153 | for progress in progressDic: |
---|
154 | if progress!='load': |
---|
155 | progressArray.append(progress+': '+str(int(progressDic[progress]))+'%') |
---|
156 | print(','.join(progressArray),end="\r") |
---|
157 | time.sleep(0.1) |
---|
158 | for key in actionList: |
---|
159 | progressDic=store.get_progress(key) |
---|
160 | if key in progressDic: |
---|
161 | if progressDic[key]==100 and not actionList[key]: |
---|
162 | progressDic=store.get_progress(key) |
---|
163 | progressArray=[] |
---|
164 | for progress in progressDic: |
---|
165 | if progress!='load': |
---|
166 | progressArray.append(progress+': '+str(progressDic[progress])+'%') |
---|
167 | print(','.join(progressArray)) |
---|
168 | print (CURSOR_UP + ERASE_LINE) |
---|
169 | actionList[key]=print_results(key) |
---|
170 | print_results() |
---|
171 | |
---|
172 | def process_Args(args): |
---|
173 | parser=argparse.ArgumentParser(description=(u'Lliurex Software Center')) |
---|
174 | # parser.add_argument('--list',metavar="Category",action='append',nargs='?',help=(_(u"List all packages, optionally list packages from a given category"))) |
---|
175 | # parser.add_argument('--list-sections',action='store_true',help=(_(u"List all sections from the store"))) |
---|
176 | parser.add_argument('--search',metavar='Name',nargs='?',help=(_(u"Search a package"))) |
---|
177 | parser.add_argument('--info',metavar='Name',nargs='?',help=(_(u"Show all info from a package"))) |
---|
178 | parser.add_argument('--install',metavar='Package',help=(_(u"Install a package"))) |
---|
179 | parser.add_argument('--remove',metavar='Package',help=(_(u"Remove a package"))) |
---|
180 | # parser.add_argument('--debug',action='store_true',help=(_(u"Prints debug information"))) |
---|
181 | |
---|
182 | args=parser.parse_args() |
---|
183 | return args |
---|
184 | |
---|
185 | main() |
---|