def findmedia(destination): def avail(path): if not (SystemInfo["HasMMC"] and '/mmc' in path): statvfs = os.statvfs(path) return (statvfs.f_bavail * statvfs.f_frsize) / (1 << 20) >= 500 and path for path in [destination] + getNonNetworkMediaMounts(): if avail(path): return path
def findmedia(destination): def avail(path): if not(SystemInfo["HasMMC"] and '/mmc' in path) and not os.path.islink(path): try: statvfs = os.statvfs(path) return (statvfs.f_bavail * statvfs.f_frsize) / (1 << 20) >= 500 and path except: pass for path in [destination] + getNonNetworkMediaMounts(): if avail(path): return path
def getImagesList(self): def getImages(path, files): for file in [x for x in files if x.endswith('.zip') and model in x]: try: if checkimagefiles([x.split(os.sep)[-1] for x in zipfile.ZipFile(file).namelist()]): medium = path.split(os.sep)[-1] if medium not in self.imagesList: self.imagesList[medium] = {} self.imagesList[medium][file] = { 'link': file, 'name': file.split(os.sep)[-1]} except: pass model = HardwareInfo().get_device_model() if not self.imagesList: if not self.jsonlist: try: self.jsonlist = json.load(urllib2.urlopen('https://openpli.org/download/json/%s' % model)) except: pass self.imagesList = dict(self.jsonlist) if self.jsonlist else {} for media in getNonNetworkMediaMounts(): if not(SystemInfo['HasMMC'] and "/mmc" in media): getImages(media, ["%s/%s" % (media, x) for x in os.listdir(media) if x.endswith('.zip') and model in x]) if "downloaded_images" in os.listdir(media): media = "%s/downloaded_images" % media if os.path.isdir(media) and not os.path.islink(media) and not os.path.ismount(media): getImages(media, ["%s/%s" % (media, x) for x in os.listdir(media) if x.endswith('.zip') and model in x]) list = [] for catagorie in reversed(sorted(self.imagesList.keys())): if catagorie in self.expanded: list.append(ChoiceEntryComponent('expanded',((str(catagorie)), "Expander"))) for image in reversed(sorted(self.imagesList[catagorie].keys())): list.append(ChoiceEntryComponent('verticalline',((str(self.imagesList[catagorie][image]['name'])), str(self.imagesList[catagorie][image]['link'])))) else: for image in self.imagesList[catagorie].keys(): list.append(ChoiceEntryComponent('expandable',((str(catagorie)), "Expander"))) break if list: self["list"].setList(list) if self.setIndex: self["list"].moveToIndex(self.setIndex if self.setIndex < len(list) else len(list) - 1) if self["list"].l.getCurrentSelection()[0][1] == "Expander": self.setIndex -= 1 if self.setIndex: self["list"].moveToIndex(self.setIndex if self.setIndex < len(list) else len(list) - 1) self.setIndex = 0 self.selectionChanged() else: self.session.openWithCallback(self.close, MessageBox, _("Cannot find images - please try later"), type=MessageBox.TYPE_ERROR, timeout=3)
def getImagesList(self): def getImages(path, files): for file in [x for x in files if x.endswith('.zip') and model in x]: try: if checkimagefiles([x.split(os.sep)[-1] for x in zipfile.ZipFile(file).namelist()]): medium = path.split(os.sep)[-1] if medium not in self.imagesList: self.imagesList[medium] = {} self.imagesList[medium][file] = { 'link': file, 'name': file.split(os.sep)[-1]} except: pass model = HardwareInfo().get_machine_name() if not self.imagesList: if not self.jsonlist: try: self.jsonlist = json.load(urllib2.urlopen('https://openpli.org/download/json/%s' % model)) except: pass self.imagesList = dict(self.jsonlist) if self.jsonlist else {} for media in getNonNetworkMediaMounts(): if not(SystemInfo['HasMMC'] and "/mmc" in media): getImages(media, ["%s/%s" % (media, x) for x in os.listdir(media) if x.endswith('.zip') and model in x]) if "downloaded_images" in os.listdir(media): media = "%s/downloaded_images" % media if os.path.isdir(media) and not os.path.islink(media) and not os.path.ismount(media): getImages(media, ["%s/%s" % (media, x) for x in os.listdir(media) if x.endswith('.zip') and model in x]) list = [] for catagorie in reversed(sorted(self.imagesList.keys())): if catagorie in self.expanded: list.append(ChoiceEntryComponent('expanded',((str(catagorie)), "Expander"))) for image in reversed(sorted(self.imagesList[catagorie].keys())): list.append(ChoiceEntryComponent('verticalline',((str(self.imagesList[catagorie][image]['name'])), str(self.imagesList[catagorie][image]['link'])))) else: for image in self.imagesList[catagorie].keys(): list.append(ChoiceEntryComponent('expandable',((str(catagorie)), "Expander"))) break if list: self["list"].setList(list) if self.setIndex: self["list"].moveToIndex(self.setIndex if self.setIndex < len(list) else len(list) - 1) if self["list"].l.getCurrentSelection()[0][1] == "Expander": self.setIndex -= 1 if self.setIndex: self["list"].moveToIndex(self.setIndex if self.setIndex < len(list) else len(list) - 1) self.setIndex = 0 self.selectionChanged() else: self.session.openWithCallback(self.close, MessageBox, _("Cannot find images - please try later"), type=MessageBox.TYPE_ERROR, timeout=3)