1 | import locale |
---|
2 | import re |
---|
3 | class infomanager: |
---|
4 | def __init__(self): |
---|
5 | self.dbg=True |
---|
6 | self.plugin_actions={'get_info':'*'} |
---|
7 | self.result={} |
---|
8 | self.result['status']={'status':-1,'msg':''} |
---|
9 | self.result['data']=[] |
---|
10 | self.progress=0 |
---|
11 | self.inc=0 |
---|
12 | self._set_locale() |
---|
13 | #def __init__ |
---|
14 | |
---|
15 | def set_debug(self,dbg=True): |
---|
16 | self.dbg=dbg |
---|
17 | self._debug ("Debug enabled") |
---|
18 | #def set__debug |
---|
19 | |
---|
20 | def _debug(self,msg=''): |
---|
21 | if self.dbg: |
---|
22 | print ('DEBUG Info: %s'%msg) |
---|
23 | #def _debug |
---|
24 | |
---|
25 | def register(self): |
---|
26 | return(self.plugin_actions) |
---|
27 | #def register |
---|
28 | |
---|
29 | def execute_action(self,appstream,action,applist,match=False): |
---|
30 | self.progress=0 |
---|
31 | self.appstream=appstream |
---|
32 | count=len(applist) |
---|
33 | if (action=='get_info' or action=='info') and count>0: |
---|
34 | inc=100.0/count |
---|
35 | self.result['data']=self._get_info(applist) |
---|
36 | self.progress=100 |
---|
37 | return(self.result) |
---|
38 | #def execute_action |
---|
39 | |
---|
40 | def _set_status(self,status,msg=''): |
---|
41 | self.result['status']={'status':status,'msg':msg} |
---|
42 | |
---|
43 | def _callback_progress(self): |
---|
44 | self.progress=self.progress+self.inc |
---|
45 | #def _callback_progress |
---|
46 | |
---|
47 | def _set_locale(self): |
---|
48 | if locale.getdefaultlocale()[0]=="ca_ES": |
---|
49 | self.locale=['ca_ES@valencia','ca@valencia','qcv','ca','ca_ES','es_ES','es','en_US','en_GB','en','C'] |
---|
50 | else: |
---|
51 | if locale.getdefaultlocale()[0]=="es_ES": |
---|
52 | self.locale=['es_ES','es','ca_ES@valencia','ca@valencia','qcv','ca','ca_ES','en_US','en_GB','en','C'] |
---|
53 | else: |
---|
54 | self.locale=[locale.getlocale()[0],'en_US','en_GB','en','ca_ES@valencia','ca@valencia','qcv','ca','es_ES','es','C'] |
---|
55 | #def _set_locale |
---|
56 | |
---|
57 | def _get_info(self,applist): |
---|
58 | applistInfo=[] |
---|
59 | for app in applist: |
---|
60 | appInfo=self._init_appInfo() |
---|
61 | # self._debug("Gathering package info for "+app.get_id()) |
---|
62 | #Earlier versions stored the appstream_id as the memory dir of the metadata |
---|
63 | #Changes in python3.6 and pickle module forces us to disable this feature... |
---|
64 | # appInfo['appstream_id']=app |
---|
65 | if app.get_id(): |
---|
66 | appInfo['id']=app.get_id() |
---|
67 | for localeItem in self.locale: |
---|
68 | if app.get_name(localeItem): |
---|
69 | appInfo['name']=app.get_name(localeItem) |
---|
70 | break |
---|
71 | if app.get_release_default(): |
---|
72 | appInfo['version']=app.get_release_default().get_version() |
---|
73 | else: |
---|
74 | for release in app.get_releases(): |
---|
75 | appinfo['version']=release.get_version() |
---|
76 | break |
---|
77 | if app.get_pkgname_default(): |
---|
78 | appInfo['package']=app.get_pkgname_default() |
---|
79 | if len(app.get_pkgnames())>1: |
---|
80 | appInfo['packages']=app.get_pkgnames() |
---|
81 | if app.get_project_license(): |
---|
82 | appInfo['license']=app.get_project_license() |
---|
83 | else: |
---|
84 | appInfo['license']='other/restricted' |
---|
85 | orig=app.get_origin() |
---|
86 | if orig: |
---|
87 | if '-main' in orig or '-universe' in orig: |
---|
88 | appInfo['license']='open source' |
---|
89 | for localeItem in self.locale: |
---|
90 | if app.get_comment(localeItem): |
---|
91 | appInfo['summary']=app.get_comment(localeItem) |
---|
92 | break |
---|
93 | for localeItem in self.locale: |
---|
94 | if app.get_description(localeItem): |
---|
95 | appInfo['description']=app.get_description(localeItem) |
---|
96 | break |
---|
97 | if app.get_categories(): |
---|
98 | appInfo['categories']=app.get_categories() |
---|
99 | if app.get_icon_default(): |
---|
100 | if app.get_icon_default().get_filename(): |
---|
101 | appInfo['icon']=app.get_icon_default().get_filename() |
---|
102 | else: |
---|
103 | appInfo['icon']=app.get_icon_default().get_name() |
---|
104 | if appInfo['icon']==None: |
---|
105 | icons=app.get_icons() |
---|
106 | if icons: |
---|
107 | for icon in icons: |
---|
108 | appInfo['icon']=icon.get_name() |
---|
109 | break |
---|
110 | else: |
---|
111 | appInfo['icon']='' |
---|
112 | if appInfo['icon']==None: |
---|
113 | appInfo['icon']='' |
---|
114 | if app.get_screenshots(): |
---|
115 | thumbnails_list=[] |
---|
116 | default_screenshot='' |
---|
117 | screenshots_list=[] |
---|
118 | for screenshot in app.get_screenshots(): |
---|
119 | for img in screenshot.get_images(): |
---|
120 | #The values are the values of appstream.ImageKind. 1=Source, 2=Thumbnail, 0=UNKNOWN |
---|
121 | #yml currently doen's support unkown images so we assign videos depending on file extension |
---|
122 | if img.get_url(): |
---|
123 | if not re.search(r'\.....?$',img.get_url()): |
---|
124 | appInfo['video']=img.get_url() |
---|
125 | continue |
---|
126 | if img.get_kind()==0: |
---|
127 | appInfo['video']=img.get_url() |
---|
128 | continue |
---|
129 | if img.get_kind()==1: #2=Default;1=normal;0=unknown |
---|
130 | default_screenshot=img.get_url() |
---|
131 | screenshots_list.append(img.get_url()) |
---|
132 | continue |
---|
133 | if img.get_kind()==2: |
---|
134 | thumbnails_list.append(img.get_url()) |
---|
135 | continue |
---|
136 | elif img.get_basename(): |
---|
137 | screenshots_list.append("/home/lliurex/.cache/lliurex-store/images/"+img.get_basename()) |
---|
138 | |
---|
139 | |
---|
140 | appInfo['thumbnails']=thumbnails_list |
---|
141 | appInfo['screenshot']=default_screenshot |
---|
142 | appInfo["screenshots"]=screenshots_list |
---|
143 | #The values are the values of appstream.UrlKind. 1=HOMEPAGE, 0=UNKNOWN |
---|
144 | # self._debug(app.get_url_item(0)) |
---|
145 | if app.get_url_item(1): |
---|
146 | appInfo['homepage']=app.get_url_item(1).strip() |
---|
147 | if app.get_url_item(0): |
---|
148 | appInfo['installerUrl']=app.get_url_item(0).strip() |
---|
149 | if app.get_state()==1: #1=Installed |
---|
150 | appInfo['state']='installed' |
---|
151 | else: |
---|
152 | appInfo['state']='available' |
---|
153 | if app.get_kudos(): |
---|
154 | appInfo['kudos']=app.get_kudos() |
---|
155 | if app.get_metadata_item('x-zomando'): |
---|
156 | appInfo['installerUrl']=app.get_metadata_item('x-zomando') |
---|
157 | if app.get_origin(): |
---|
158 | appInfo['component']=app.get_origin() |
---|
159 | if app.get_metadata_item('x-video'): |
---|
160 | appInfo['video']=app.get_metadata_item('x-video') |
---|
161 | #Modify the url and create the url embed code |
---|
162 | if 'embed' not in appInfo['video']: |
---|
163 | appInfo['video']=appInfo['video'].replace('watch?v=','embed/') |
---|
164 | #This appstream version returns unknown for all the possible kinds |
---|
165 | # if app.get_bundle_default(): |
---|
166 | # appInfo['bundle']=app.get_bundle_default().get_kind() |
---|
167 | #This appstream version returns unknown for all the possible kinds |
---|
168 | #ID must contain bundle type as last field |
---|
169 | for bundle in app.get_bundles(): |
---|
170 | if bundle.get_kind()==0: |
---|
171 | kind=bundle.get_id().split('.')[-1] |
---|
172 | appInfo['bundle'].append(kind.lower()) |
---|
173 | if kind.lower=='sh': |
---|
174 | appInfo['installerUrl']=bundle.get_id() |
---|
175 | applistInfo.append(appInfo) |
---|
176 | self._callback_progress() |
---|
177 | self._set_status(0) |
---|
178 | return(applistInfo) |
---|
179 | #def _get_info |
---|
180 | |
---|
181 | def _init_appInfo(self): |
---|
182 | appInfo={'appstream_id':'',\ |
---|
183 | 'id':'',\ |
---|
184 | 'name':'',\ |
---|
185 | 'version':'',\ |
---|
186 | 'package':'',\ |
---|
187 | 'license':'',\ |
---|
188 | 'summary':'',\ |
---|
189 | 'description':'',\ |
---|
190 | 'categories':[],\ |
---|
191 | 'icon':'',\ |
---|
192 | 'screenshot':'',\ |
---|
193 | 'thumbnails':[],\ |
---|
194 | 'video':'',\ |
---|
195 | 'homepage':'',\ |
---|
196 | 'installerUrl':'',\ |
---|
197 | 'state':'',\ |
---|
198 | 'depends':'',\ |
---|
199 | 'kudos':'',\ |
---|
200 | 'suggests':'',\ |
---|
201 | 'extraInfo':'',\ |
---|
202 | 'size':'',\ |
---|
203 | 'bundle':[],\ |
---|
204 | 'updatable':'',\ |
---|
205 | 'component':'',\ |
---|
206 | 'channel_releases':{} |
---|
207 | } |
---|
208 | return(appInfo) |
---|
209 | #def _init_appInfo |
---|
210 | |
---|
211 | #class infomanager |
---|