def add_appdata_file(self): # do we have an AppData file? filename = './tmp/usr/share/appdata/' + self.app_id + '.appdata.xml' fn_extra = '../appdata-extra/' + self.type_id + '/' + self.app_id + '.appdata.xml' if os.path.exists(filename) and os.path.exists(fn_extra): self.log.write(LoggerItem.INFO, "deleting %s as upstream AppData file exists" % fn_extra) os.remove(fn_extra) # just use the extra file in places of the missing upstream one if os.path.exists(fn_extra): filename = fn_extra # need to extract details if not os.path.exists(filename): return False data = AppData() if not data.extract(filename): self.log.write(LoggerItem.WARNING, "AppData file '%s' could not be parsed" % filename) return False # check AppData file validates enable_validation = self.type_id != 'font' if enable_validation and os.path.exists('/usr/bin/appdata-validate'): env = os.environ p = subprocess.Popen(['/usr/bin/appdata-validate', '--relax', filename], cwd='.', env=env, stdout=subprocess.PIPE) p.wait() if p.returncode: for line in p.stdout: line = line.replace('\n', '').decode('utf-8') self.log.write(LoggerItem.WARNING, "AppData did not validate: %s" % line) # check the id matches if data.get_id() != self.app_id and data.get_id() != self.app_id_full: self.log.write(LoggerItem.WARNING, "The AppData id does not match: " + self.app_id) return False # check the licence is okay if data.get_licence() not in self.cfg.get_content_licences(): self.log.write(LoggerItem.WARNING, "The AppData licence is not okay for " + self.app_id + ': \'' + data.get_licence() + '\'') return False # if we have an override, use it for all languages tmp = data.get_names() if tmp: self.names = tmp # if we have an override, use it for all languages tmp = data.get_summaries() if tmp: self.comments = tmp # get metadata tmp = data.get_metadata() if tmp: # and extra packages we want to add in? if 'ExtraPackages' in tmp: for pkg in tmp['ExtraPackages'].split(','): if pkg not in self.pkgnames: self.pkgnames.append(pkg) del tmp['ExtraPackages'] self.metadata.update(tmp) # get optional bits tmp = data.get_urls() if tmp: for key in tmp: self.urls[key] = tmp[key] tmp = data.get_project_group() if tmp: self.project_group = tmp try: self.descriptions = data.get_descriptions() except StandardError, e: self.log.write(LoggerItem.WARNING, "failed to add description: %s" % str(e))