1 | import locale |
---|
2 | |
---|
3 | class infomanager: |
---|
4 | def __init__(self): |
---|
5 | self.dbg=1 |
---|
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 | |
---|
26 | def execute_action(self,appstream,action,applist): |
---|
27 | self.appstream=appstream |
---|
28 | count=len(applist) |
---|
29 | if action=='info' and count>0: |
---|
30 | inc=100.0/count |
---|
31 | self._get_info(applist) |
---|
32 | self.progress=100 |
---|
33 | return(self.applistInfo) |
---|
34 | |
---|
35 | def _callback_progress(self): |
---|
36 | self.progress=self.progress+self.inc |
---|
37 | |
---|
38 | def _set_locale(self): |
---|
39 | if locale.getdefaultlocale()[0]=="ca_ES": |
---|
40 | self.locale=['ca_ES@valencia','ca@valencia','ca','ca_ES','es_ES','es','en_US','en','C'] |
---|
41 | else: |
---|
42 | if locale.getdefaultlocale()[0]=="es_ES": |
---|
43 | self.locale=['es_ES','es','ca_ES@valencia','ca@valencia','ca','ca_ES','en_US','en','C'] |
---|
44 | else: |
---|
45 | self.locale=[locale.getlocale()[0],'en_US','en','ca_ES@valencia','ca@valencia','ca','es_ES','es','C'] |
---|
46 | |
---|
47 | def _get_info(self,applist): |
---|
48 | applistInfo=[] |
---|
49 | for app in applist: |
---|
50 | appInfo=self._init_appInfo() |
---|
51 | self._debug("Gathering package info for "+app.get_id()) |
---|
52 | if app.get_id(): |
---|
53 | appInfo['id']=app.get_id() |
---|
54 | for localeItem in self.locale: |
---|
55 | if app.get_name(localeItem): |
---|
56 | appInfo['name']=app.get_name(localeItem) |
---|
57 | break |
---|
58 | for localeItem in self.locale: |
---|
59 | if app.get_comment(localeItem): |
---|
60 | appInfo['summary']=app.get_comment(localeItem) |
---|
61 | break |
---|
62 | for localeItem in self.locale: |
---|
63 | if app.get_description(localeItem): |
---|
64 | appInfo['description']=app.get_description(localeItem) |
---|
65 | break |
---|
66 | if app.get_release_default(): |
---|
67 | appInfo['version']=app.get_release_default().get_version() |
---|
68 | if app.get_pkgname_default(): |
---|
69 | appInfo['package']=app.get_pkgname_default() |
---|
70 | if app.get_metadata_license(): |
---|
71 | appInfo['license']=app.get_metadata_license() |
---|
72 | else: |
---|
73 | orig=app.get_origin() |
---|
74 | print (orig) |
---|
75 | if orig: |
---|
76 | if '-main' in orig or '-universe' in orig: |
---|
77 | appInfo['license']='open source' |
---|
78 | else: |
---|
79 | appInfo['license']='propietary/restricted' |
---|
80 | if app.get_categories(): |
---|
81 | appInfo['categories']=str(app.get_categories()) |
---|
82 | if app.get_icon_default(): |
---|
83 | appInfo['icon']=app.get_icon_default().get_name() |
---|
84 | # if app.get_icon_default(): |
---|
85 | # appInfo['icon']=appInfo['icon']+'/'+app.get_icon_default().get_name() |
---|
86 | if app.get_screenshots(): |
---|
87 | thumbnails_list=[] |
---|
88 | for screenshot in app.get_screenshots(): |
---|
89 | for img in screenshot.get_images(): |
---|
90 | #The values are the values of appstream.ImageKind. 1=Source, 2=Thumbnail, 0=UNKNOWN |
---|
91 | if img.get_kind()==1: #2=Default;1=normal;0=unknown |
---|
92 | default_screenshot=img.get_url() |
---|
93 | if img.get_kind()==2: |
---|
94 | thumbnails_list.append(img.get_url()) |
---|
95 | if img.get_kind()==0: |
---|
96 | appInfo['video']=img.get_url() |
---|
97 | #Modify the url and create the url embed code |
---|
98 | if 'embed' not in appInfo['video']: |
---|
99 | appInfo['video']=appInfo['video'].replace('watch?v=','embed/') |
---|
100 | appInfo['thumbnails']=thumbnails_list |
---|
101 | appInfo['screenshot']=default_screenshot |
---|
102 | #The values are the values of appstream.UrlKind. 1=HOMEPAGE, 0=UNKNOWN |
---|
103 | if app.get_url_item(1): |
---|
104 | appInfo['homepage']=app.get_url_item(1).strip() |
---|
105 | if app.get_url_item(0): |
---|
106 | appInfo['installerUrl']=app.get_url_item(0).strip() |
---|
107 | if app.get_state()==1: #1=Installed |
---|
108 | appInfo['status']='installed' |
---|
109 | else: |
---|
110 | appInfo['status']='available' |
---|
111 | applistInfo.append(appInfo) |
---|
112 | self._callback_progress() |
---|
113 | self.applistInfo=applistInfo |
---|
114 | return(applistInfo) |
---|
115 | |
---|
116 | def _init_appInfo(self): |
---|
117 | appInfo={'name':'',\ |
---|
118 | 'summary':'',\ |
---|
119 | 'description':'',\ |
---|
120 | 'categories':[],\ |
---|
121 | 'icon':'',\ |
---|
122 | 'screenshot':'',\ |
---|
123 | 'version':'',\ |
---|
124 | 'package':'',\ |
---|
125 | 'homepage':'',\ |
---|
126 | 'installerUrl':'',\ |
---|
127 | 'extraInfo':'',\ |
---|
128 | 'status':'',\ |
---|
129 | 'license':''\ |
---|
130 | } |
---|
131 | return(appInfo) |
---|
132 | #def _init_appInfo |
---|
133 | |
---|
134 | #class infomanager |
---|