def downloadFLUFFYandinstalldependencies(): if not os.path.isdir(locations.fluffyfolder): os.mkdir(locations.fluffyfolder) print("initializing fluffy folder") global fluffylist if fluffylist == []: fluffydict = locations.fluffydict fluffylist = [fluffydict] fluffylist = webhandler.getUpdatedSoftwareLinks(fluffylist) fluffyjson = fluffylist[0]["githubjson"] with open(fluffyjson, encoding="utf-8" ) as json_file: #jsonfile is path, json_file is file obj jfile = json.load(json_file) if jfile == [] or jfile == None: print("Error: empty json nut file") return version = jfile[0]["tag_name"] version = version.strip("v") if float(version) > 2.8: asset = 1 else: asset = 0 scripturl = jfile[0]["assets"][asset]["browser_download_url"] licenseurl = jfile[0]["assets"][asset + 1]["browser_download_url"] #download and move fluffy and license script = webhandler.download(scripturl) license = webhandler.download(licenseurl) scriptpath = os.path.join(locations.downloadsfolder, script) licensepath = os.path.join(locations.downloadsfolder, license) newscriptpath = os.path.join(locations.fluffyfolder, script) newlicensepath = os.path.join(locations.fluffyfolder, license) shutil.move(scriptpath, newscriptpath) shutil.move(licensepath, newlicensepath) newentry = { "fluffy": { "version": version, "location": newscriptpath, } } guicore.setguisetting(newentry) print("checking and installing fluffy dependencies") threads = [] dependencies = locations.fluffydict["dependencies"] webhandler.installmodulelist(dependencies)
def injectpayload(self, payload): if not os.path.isdir(locations.injectorfolder): print("initializing folder {}".format(locations.injectorfolder)) os.mkdir(locations.injectorfolder) fuseestatus = guicore.checkguisetting("fusee-launcher", "version") if fuseestatus == "not installed" or fuseestatus == "none" or fuseestatus == None: with open(self.pjlist[0]["githubjson"] ) as json_file: #jsonfile is path, json_file is file obj jfile = json.load(json_file) downloadurl = jfile[0]["zipball_url"] file = webhandler.download(downloadurl) file = os.path.join(locations.downloadsfolder, file) version = jfile[0]["tag_name"] with ZipFile(file, 'r') as zipObj: zipObj.extractall(locations.injectorfolder) self.printtoboth( "Sucessfully extracted {} to payloads folder".format(file)) files = zipObj.namelist() injector = None for possiblepayloadfile in files: if possiblepayloadfile.startswith(files[0] + "fusee"): injector = possiblepayloadfile if injector == None: self.printtoboth( "Could not find injector in extracted files") return newentry = { "fusee-launcher": { "version": version, "location": injector, } } guicore.setguisetting(newentry) script_file = guicore.checkguisetting("fusee-launcher", "location") script_file = os.path.join(locations.injectorfolder, script_file) if payload: p = subprocess.Popen( [sys.executable, '-u', script_file, payload], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, bufsize=1, ) with p.stdout: for line in iter(p.stdout.readline, b''): self.printtoboth(line) p.wait() else: print("failed to find payload")
def downloadNUTandinstalldependencies(): if not os.path.isdir(locations.nutfolder): os.mkdir(locations.nutfolder) print("initializing nut folder") nutjson = webhandler.getJson("nut", locations.nutserverdict["githubapi"]) with open(nutjson, encoding="utf-8" ) as json_file: #jsonfile is path, json_file is file obj jfile = json.load(json_file) if jfile == [] or jfile == None: print("Error: empty json nut file") return zipurl = jfile[0]["zipball_url"] version = jfile[0]["tag_name"] if zipurl == None: print("zip file url invalid, can't download nut assets") nutzip = webhandler.download(zipurl) nutzip = os.path.join(locations.downloadsfolder, nutzip) with ZipFile(nutzip, 'r') as zipObj: zipObj.extractall(locations.nutfolder) print("Sucessfully extracted {} to nut folder\n".format(nutzip)) extractedfiles = zipObj.namelist() serverfile = None for possibleserverfile in extractedfiles: if possibleserverfile == extractedfiles[0] + "server.py": serverfile = possibleserverfile if serverfile == None: print("Could not find server file in extracted files") return serverfile = os.path.join(locations.nutfolder, serverfile) newentry = { "nut": { "version": version, "location": serverfile, } } guicore.setguisetting(newentry) print("checking nut dependencies") dependencies = locations.nutserverdict["dependencies"] webhandler.installmodulelist(dependencies)
def getordownloadpayload(self, force_update=False): if not os.path.isdir(locations.payloadsfolder): os.mkdir(locations.payloadsfolder) #Get the current software chunk sc = self.softwarelist[self.currentselection] softwarename = sc["software"] #Check if payload already download, if not set it to download status = guicore.checkguisetting(softwarename, "version") if status == None or status == "not installed": pass #If it's already downloaded, get it, unless force_update is set else: if not force_update: payload = guicore.checkguisetting(softwarename, "location") return payload softwarename = sc["software"] try: with open(sc["githubjson"] ) as json_file: #jsonfile is path, json_file is file obj jfile = json.load(json_file) version = jfile[self.currenttagselection]["tag_name"] except: self.printtoboth( "Failed to find repo json file, can't download payload.") return assets = jfile[self.currenttagselection]["assets"] #Find the correct asset using HBUpdater core method for finding assets downloadurl = HBUpdater.findasset(sc["pattern"], assets) self.printtoboth("downloading payload from {}".format(downloadurl)) #file yielded by the download file = webhandler.download(downloadurl) file = os.path.join(locations.downloadsfolder, file) #get absolute path to it #if downloaded file is already .bin, set the payload path to it. if file.endswith(".bin"): payload = file elif file.endswith(".zip"): #if file is zip, unzip it and find the payload based on the pattern set in its entry in #locations with ZipFile(file, 'r') as zipObj: zipObj.extractall(locations.payloadsfolder) self.printtoboth( "Sucessfully extracted {} to payloads folder\n\n".format( file)) files = zipObj.namelist() payload = None pattern = sc["zip_items"] for possiblepayloadfile in files: for fp in pattern[0]: if fp.lower() in possiblepayloadfile.lower(): if possiblepayloadfile.endswith( pattern[1].lower()): payload = possiblepayloadfile break if payload == None: self.printtoboth( "Could not find payload in extracted files") return payload = os.path.join(locations.payloadsfolder, payload) else: self.printtoboth("file handling method not found") return #prep new entry to the gui log newentry = { softwarename: { "version": version, "location": payload, } } guicore.setguisetting(newentry) self.updatetable(None) return payload
def installitem(sc, suboption): global sdpathset global chosensdpath if not sdpathset: return if not chosensdpath: return name = sc["software"] print("Installing {}".format(name)) #parse api link to a github project releases link url = parse_api_to_standard_github(sc["githubapi"]) url = url.strip("/") + "/releases" #Create empty appstore entry and populate it entry = appstore.appstore_entry() entry["title"] = name entry["author"] = sc["author"] entry["category"] = sc["group"] entry["license"] = None entry["description"] = sc["description"] entry["url"] = url package = sc["store_equivalent"] #open the repo file with open(sc["githubjson"], encoding="utf-8") as repo_file: repo = json.load(repo_file) ver = repo[suboption]["tag_name"] entry["details"] = repo[suboption]["body"] assets = repo[suboption]["assets"] if assets == None: print("Could not find asset data for selected software") return if sc["pattern"] == None: print("no asset pattern specified for repo") return #Find the correct asset in the list of assets pulled from the repo json downloadlink = findasset(sc["pattern"], assets) if not downloadlink: return downloadedfile = webhandler.download(downloadlink) #If download failed return if downloadedfile == None: print("Asset download failed, not installing") return print("Download successful, proceeding...") filestoremove = appstore.get_package_manifest(chosensdpath, package) if filestoremove: if 'str' in str(type(filestoremove)): file = os.path.join(chosensdpath, filestoremove) if os.path.isfile(file): os.remove(file) print("removed {}".format(file)) else: #Go through the previous ziplist in reverse, this way folders get cleaned up for path in reversed(filestoremove): file = os.path.join(chosensdpath, path) if os.path.isfile(file): os.remove(file) print("removed {}".format(file)) elif os.path.isdir(file): if not os.listdir(file): os.rmdir(file) print("removed empty directory {}".format(file)) #Move software to sd card #Handles data differently depending on file type installlocation = installfiletosd(downloadedfile, sc["install_subfolder"]) #Convert github version to store version entry["version"] = appstore.parse_version_to_store_equivalent(ver, package) appstore.create_store_entry(chosensdpath, entry, installlocation, package)