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