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