Skip to content

Commit

Permalink
Minor tweaks
Browse files Browse the repository at this point in the history
installerhelperpage's functions have been moved to toolhelper.py in modules
  • Loading branch information
Andrew committed Jun 5, 2019
1 parent ca22e7b commit 14013d6
Show file tree
Hide file tree
Showing 10 changed files with 174 additions and 227 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
/titledb/*
/conf/*
/tools/*
/titles/*
user_repos.json
fluffy.conf
fluffy.log
Expand Down
3 changes: 1 addition & 2 deletions HBUpdaterGUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ def __init__(self, *args, **kwargs):
import pages.mainpage as mp
import pages.settingspage as sp
import pages.addrepopage as ar
import pages.installerhelperpage as hp
import pages.pythonnxpage as py
import pages.cfwpage as fw
import pages.errorpage as ep
Expand All @@ -65,7 +64,7 @@ def __init__(self, *args, **kwargs):

self.frames = {}
#Add frames to dict, with keyword being the name of the frame
for F in (mp.mainPage,ip.injectorScreen,sp.settingsPage,ar.addRepoScreen,hp.installerHelperPage,py.pynxPage,fw.cfwPage,ep.errorPage,lp.homePage,gp.gamesPage,cp.serialPage):
for F in (mp.mainPage,ip.injectorScreen,sp.settingsPage,ar.addRepoScreen,py.pynxPage,fw.cfwPage,ep.errorPage,lp.homePage,gp.gamesPage,cp.serialPage):
page_name = F.__name__
frame = F(parent=container, controller=self,back_command = lambda: self.show_frame("homePage"))
self.frames[page_name] = frame
Expand Down
Binary file added assets/github.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions modules/customwidgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,11 +347,11 @@ def __init__(self,frame,label_text,anchor="w",background=dark_color):

#themed nav button
class navbutton(tk.Button):
def __init__(self,frame,command_name=None,image_object= None,text_string=None):
def __init__(self,frame,command_name=None,image_object= None,text_string=None,background=dark_color):
tk.Button.__init__(self,frame,
background=dark_color,
background=background,
borderwidth=0,
activebackground=dark_color,
activebackground=background,
#pady="0",
image=image_object,
command=command_name,
Expand Down
143 changes: 143 additions & 0 deletions modules/toolhelper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
from modules.format import *
import modules.customwidgets as cw
import modules.guicore as guicore
import modules.HBUpdater as HBUpdater
import modules.locations as locations
import modules.webhandler as webhandler
import json, os, shutil, subprocess, sys, threading
from zipfile import ZipFile

fluffylist = []

def getnut():
downloadNUTandinstalldependencies()
starthelper("nut")

def getfluffy():
downloadFLUFFYandinstalldependencies()
starthelper("fluffy")


def checkifhelperdownloaded(helper):
if guicore.checkguisetting(helper, "version") == "not installed" or guicore.checkguisetting(helper, "version") == None:
return False
else:
print(guicore.checkguisetting(helper, "version"))
return True
return False

def starthelper(helper):
if not checkifhelperdownloaded(helper):
nutnotdownloadedwarningframe.tkraise()
print("not installed")
return
script_path = guicore.checkguisetting(helper, "location")
print("starting {} server at {}".format(helper,script_path))
if script_path == None:
print("invalid path")
return
subprocess.Popen([sys.executable,script_path])

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) 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 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) 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)



6 changes: 3 additions & 3 deletions pages/errorpage.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ def __init__(self, parent, controller,back_command):
self.backbuttonframe = cw.themedframe(self,background_color=dark_color)
self.backbuttonframe.place(relx=0.5,rely=0.5,y=+(3*navbuttonheight + separatorwidth),width=300,x=-150,height=navbuttonheight)

self.backbutton = cw.navbutton(self.backbuttonframe, command_name=self.back_command,text_string="RIP. Take me back to the app.")
self.backbutton = cw.navbutton(self.backbuttonframe, command_name=self.back_command,text_string="RIP. Take me back to the app.",background=light_color)
self.backbutton.place(relwidth=1,relheight=1)

self.yesnobuttonframe = cw.themedframe(self,background_color=dark_color)
self.yesnobuttonframe.place(relx=0.5,rely=0.5,y=+(3*navbuttonheight + separatorwidth),width=300,x=-150,height=navbuttonheight)

self.yesbutton = cw.navbutton(self.yesnobuttonframe, command_name=self.on_yes,text_string="Yes")
self.yesbutton = cw.navbutton(self.yesnobuttonframe, command_name=self.on_yes,text_string="Yes",background=light_color)
self.yesbutton.place(relx=0,relwidth=0.33,relheight=1)

self.nobutton = cw.navbutton(self.yesnobuttonframe, command_name=self.on_no,text_string="No")
self.nobutton = cw.navbutton(self.yesnobuttonframe, command_name=self.on_no,text_string="No",background=light_color)
self.nobutton.place(relx=0.67,relwidth=0.33,relheight=1)

self.backbuttonframe.tkraise()
Expand Down
38 changes: 21 additions & 17 deletions pages/homepage.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import tkinter as tk
from tkinter.constants import *

import pages.installerhelperpage as installerhelperpage
import modules.toolhelper as toolhelper
import pages.serialpage as serialpage
import pages.errorpage as errorpage
homebuttonwidth = 120
Expand Down Expand Up @@ -49,6 +49,7 @@ def __init__(self, parent, controller,back_command):
self.betaimage = tk.PhotoImage(file=os.path.join(locations.assetfolder, "beta.png"))
self.homebrewimage = tk.PhotoImage(file=os.path.join(locations.assetfolder, "homebrew.png"))
self.gameimage = tk.PhotoImage(file=os.path.join(locations.assetfolder, "games.png"))
self.githubimage = tk.PhotoImage(file=os.path.join(locations.assetfolder, "github.png"))

homebrewbuttonlist = [
{
Expand Down Expand Up @@ -113,20 +114,19 @@ def __init__(self, parent, controller,back_command):


otherbuttonlist = [
{
"image" : self.betaimage,
"callback" : lambda: self.controller.show_frame("errorPage"),
"tooltip" : "Whatever is in beta",
"shorttip" : "In beta"
},


{
"image" : self.settingsimage,
"callback" : lambda: self.controller.show_frame("settingsPage"),
"tooltip" : "Open settings page",
"shorttip" : "Settings"
},

{
"image" : self.githubimage,
"callback" : lambda: webhandler.opentab(),
"tooltip" : "Open HBUpdater Github",
"shorttip" : "HBU Github"
},
]


Expand All @@ -149,18 +149,22 @@ def __init__(self, parent, controller,back_command):
separator.place(relx=0,rely=0.65,relwidth=1,height=separatorwidth)

def checknutandstart(self):
if not installerhelperpage.checkifhelperdownloaded("nut"):
installerhelperpage.seterrorstate("nut")
self.controller.show_frame("installerHelperPage")
if not toolhelper.checkifhelperdownloaded("nut"):
self.controller.show_frame("errorPage")
self.controller.frames["errorPage"].getanswer("homePage","It looks like you don't have nut installed yet,\nwould you like to install it and its dependencies?\nThis can take up to a minute",toolhelper.getnut)
return
installerhelperpage.starthelper("nut")
else:
toolhelper.starthelper("nut")


def checkfluffyandstart(self):
if not installerhelperpage.checkifhelperdownloaded("fluffy"):
installerhelperpage.seterrorstate("fluffy")
self.controller.show_frame("installerHelperPage")
if not toolhelper.checkifhelperdownloaded("fluffy"):
self.controller.show_frame("errorPage")
self.controller.frames["errorPage"].getanswer("homePage","It looks like you don't have fluffy installed yet,\nwould you like to install it and its dependencies?\nThis can take up to a minute",toolhelper.getfluffy)
return
installerhelperpage.starthelper("fluffy")
else:
toolhelper.starthelper("fluffy")


def checkserialandstart(self):
status = serialpage.checkifSSNCinstalled()
Expand Down
Loading

0 comments on commit 14013d6

Please sign in to comment.