1 | import locale |
---|
2 | import re |
---|
3 | class infomanager: |
---|
4 | def __init__(self): |
---|
5 | self.dbg=0 |
---|
6 | self.pluginInfo={'info':'*'} |
---|
7 | self.applistInfo=[] |
---|
8 | self.progress=0 |
---|
9 | self.inc=0 |
---|
10 | self._set_locale() |
---|
11 | #def __init__ |
---|
12 | |
---|
13 | def set_debug(self,dbg='1'): |
---|
14 | self.dbg=int(dbg) |
---|
15 | self._debug ("Debug enabled") |
---|
16 | #def set__debug |
---|
17 | |
---|
18 | def _debug(self,msg=''): |
---|
19 | if self.dbg==1: |
---|
20 | print ('DEBUG Info: '+str(msg)) |
---|
21 | #def _debug |
---|
22 | |
---|
23 | def register(self): |
---|
24 | return(self.pluginInfo) |
---|
25 | #def register |
---|
26 | |
---|
27 | def execute_action(self,appstream,action,applist): |
---|
28 | self.appstream=appstream |
---|
29 | count=len(applist) |
---|
30 | if action=='info' and count>0: |
---|
31 | inc=100.0/count |
---|
32 | self._get_info(applist) |
---|
33 | self.progress=100 |
---|
34 | return(self.applistInfo) |
---|
35 | #def execute_action |
---|
36 | |
---|
37 | def _callback_progress(self): |
---|
38 | self.progress=self.progress+self.inc |
---|
39 | #def _callback_progress |
---|
40 | |
---|
41 | def _set_locale(self): |
---|
42 | if locale.getdefaultlocale()[0]=="ca_ES": |
---|
43 | self.locale=['ca_ES@valencia','ca@valencia','ca','ca_ES','es_ES','es','en_US','en','C'] |
---|
44 | else: |
---|
45 | if locale.getdefaultlocale()[0]=="es_ES": |
---|
46 | self.locale=['es_ES','es','ca_ES@valencia','ca@valencia','ca','ca_ES','en_US','en','C'] |
---|
47 | else: |
---|
48 | self.locale=[locale.getlocale()[0],'en_US','en','ca_ES@valencia','ca@valencia','ca','es_ES','es','C'] |
---|
49 | #def _set_locale |
---|
50 | |
---|
51 | def _get_info(self,applist): |
---|
52 | applistInfo=[] |
---|
53 | for app in applist: |
---|
54 | appInfo=self._init_appInfo() |
---|
55 | self._debug("Gathering package info for "+app.get_id()) |
---|
56 | if app.get_id(): |
---|
57 | appInfo['id']=app.get_id() |
---|
58 | for localeItem in self.locale: |
---|
59 | if app.get_name(localeItem): |
---|
60 | appInfo['name']=app.get_name(localeItem) |
---|
61 | break |
---|
62 | if app.get_release_default(): |
---|
63 | appInfo['version']=app.get_release_default().get_version() |
---|
64 | if app.get_pkgname_default(): |
---|
65 | appInfo['package']=app.get_pkgname_default() |
---|
66 | if app.get_metadata_license(): |
---|
67 | appInfo['license']=app.get_metadata_license() |
---|
68 | else: |
---|
69 | orig=app.get_origin() |
---|
70 | if orig: |
---|
71 | if '-main' in orig or '-universe' in orig: |
---|
72 | appInfo['license']='open source' |
---|
73 | else: |
---|
74 | appInfo['license']='propietary/restricted' |
---|
75 | for localeItem in self.locale: |
---|
76 | if app.get_comment(localeItem): |
---|
77 | appInfo['summary']=app.get_comment(localeItem) |
---|
78 | break |
---|
79 | for localeItem in self.locale: |
---|
80 | if app.get_description(localeItem): |
---|
81 | appInfo['description']=app.get_description(localeItem) |
---|
82 | break |
---|
83 | if app.get_categories(): |
---|
84 | appInfo['categories']=str(app.get_categories()) |
---|
85 | if app.get_icon_default(): |
---|
86 | appInfo['icon']=app.get_icon_default().get_name() |
---|
87 | # if app.get_icon_default(): |
---|
88 | # appInfo['icon']=appInfo['icon']+'/'+app.get_icon_default().get_name() |
---|
89 | if app.get_screenshots(): |
---|
90 | thumbnails_list=[] |
---|
91 | default_screenshot='' |
---|
92 | for screenshot in app.get_screenshots(): |
---|
93 | for img in screenshot.get_images(): |
---|
94 | #The values are the values of appstream.ImageKind. 1=Source, 2=Thumbnail, 0=UNKNOWN |
---|
95 | #yml currently doen's support unkown images so we assign videos depending on file extension |
---|
96 | if not re.search(r'\.....?$',img.get_url()): |
---|
97 | appInfo['video']=img.get_url() |
---|
98 | continue |
---|
99 | if img.get_kind()==0: |
---|
100 | appInfo['video']=img.get_url() |
---|
101 | continue |
---|
102 | if img.get_kind()==1: #2=Default;1=normal;0=unknown |
---|
103 | default_screenshot=img.get_url() |
---|
104 | continue |
---|
105 | if img.get_kind()==2: |
---|
106 | thumbnails_list.append(img.get_url()) |
---|
107 | continue |
---|
108 | |
---|
109 | appInfo['thumbnails']=thumbnails_list |
---|
110 | appInfo['screenshot']=default_screenshot |
---|
111 | #The values are the values of appstream.UrlKind. 1=HOMEPAGE, 0=UNKNOWN |
---|
112 | if app.get_url_item(1): |
---|
113 | appInfo['homepage']=app.get_url_item(1).strip() |
---|
114 | if app.get_state()==1: #1=Installed |
---|
115 | appInfo['status']='installed' |
---|
116 | else: |
---|
117 | appInfo['status']='available' |
---|
118 | if app.get_kudos(): |
---|
119 | appInfo['kudos']=app.get_kudos() |
---|
120 | if app.get_metadata_item('x-zomando'): |
---|
121 | appInfo['installerUrl']=app.get_metadata_item('x-zomando') |
---|
122 | if app.get_metadata_item('x-video'): |
---|
123 | appInfo['video']=app.get_metadata_item('x-video') |
---|
124 | #Modify the url and create the url embed code |
---|
125 | if 'embed' not in appInfo['video']: |
---|
126 | appInfo['video']=appInfo['video'].replace('watch?v=','embed/') |
---|
127 | for bundle in app.get_bundles(): |
---|
128 | if bundle.get_kind()==0: |
---|
129 | appInfo['installerUrl']=bundle.get_id() |
---|
130 | applistInfo.append(appInfo) |
---|
131 | self._callback_progress() |
---|
132 | self.applistInfo=applistInfo |
---|
133 | return(applistInfo) |
---|
134 | #def _get_info |
---|
135 | |
---|
136 | def _init_appInfo(self): |
---|
137 | appInfo={'id':'',\ |
---|
138 | 'name':'',\ |
---|
139 | 'version':'',\ |
---|
140 | 'package':'',\ |
---|
141 | 'license':'',\ |
---|
142 | 'summary':'',\ |
---|
143 | 'description':'',\ |
---|
144 | 'categories':[],\ |
---|
145 | 'icon':'',\ |
---|
146 | 'screenshot':'',\ |
---|
147 | 'thumbnails':[],\ |
---|
148 | 'video':'',\ |
---|
149 | 'homepage':'',\ |
---|
150 | 'installerUrl':'',\ |
---|
151 | 'status':'',\ |
---|
152 | 'depends':'',\ |
---|
153 | 'kudos':'',\ |
---|
154 | 'suggests':'',\ |
---|
155 | 'extraInfo':'',\ |
---|
156 | } |
---|
157 | return(appInfo) |
---|
158 | #def _init_appInfo |
---|
159 | |
---|
160 | #class infomanager |
---|