Skip to content

Commit

Permalink
stuff
Browse files Browse the repository at this point in the history
make updater actually wait for main application to exit instead of using a timeout

minor edits to dockerfiles
  • Loading branch information
shinrax2 committed Aug 21, 2023
1 parent 0b58a59 commit 78e41a6
Show file tree
Hide file tree
Showing 9 changed files with 114 additions and 32 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
- bugfix

future release (aka current master branch):
+ make updater actually wait for main application to exit instead of using a timeout
+ add dockerfile for linux amd64


v012:
+ added european spanish translation thanks to https://github.com/IlDucci
Expand Down
66 changes: 53 additions & 13 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import subprocess
import datetime
import shlex
import stat

#local files
import utils
Expand Down Expand Up @@ -110,14 +111,23 @@ def copyData(builddir, locdirname, imagedirname, debug=False, source=False):

def copySource(builddir):
sourcedir = os.path.join(builddir, "src")
files = ["build.py", "buildrequirements.txt", "CHANGELOG", "gui.py", "LICENSE", "main.py", "missingstrings.py", "PS3GUD.py", "README.md", "release.debug.json", "release.debug.json", "release.json", "requirements.txt", "sony.pem", "titledb.json", "titledb.debug.json", "updater.py", "utils.py", "dockerfile-amd64", "docker_build.sh"]
files = ["build.py", "buildrequirements.txt", "CHANGELOG", "gui.py", "LICENSE", "main_ps3gud.py", "missingstrings.py", "PS3GUD.py", "README.md", "release.debug.json", "release.debug.json", "release.json", "requirements.txt", "sony.pem", "titledb.json", "titledb.debug.json", "updater.py", "utils.py", "docker_build.sh", ".gitignore", ".gitattributes"]
dirs = {
"images": {
"ignore": []
},
"loc": {
"ignore": []
}
},
"dockerfiles": {
"ignore": []
},
".git": {
"ignore": []
},
".github": {
"ignore": []
},
}
#copy files
os.mkdir(sourcedir)
Expand All @@ -134,6 +144,10 @@ def saveCommitId(release, builddir):
with open(os.path.join(builddir, "release.json"), "w", encoding="utf8") as f:
f.write(json.dumps(data, sort_keys=True, ensure_ascii=False, indent=4))

def remove_readonly(func, path, _):
os.chmod(path, stat.S_IWRITE)
func(path)

class Upx():
def __init__(self, build_config="build_config.json"):
self.upx = {}
Expand Down Expand Up @@ -212,6 +226,8 @@ def __exit__(self, type, value, traceback):
parser.add_argument("-z", "--zip", action="store_true", help="pack the build to a .zip file")
parser.add_argument("-u", "--upx", action="store_true", help="use UPX to shrink executables")
parser.add_argument("-up", "--upxpath", action="store", help="path to upx directory")
parser.add_argument("--docker", action="store_true", help='copy build zip to "./docker_output", requires --zip')

args = parser.parse_args()
#constants
builddir = "dist/PS3GameUpdateDownloader"
Expand All @@ -222,6 +238,9 @@ def __exit__(self, type, value, traceback):
iconpath = os.path.abspath(os.path.join(imagedirname, "icon.ico"))
NOW = datetime.datetime.now()
ARCHIVEFORMAT = "zip"
dockerdir = "./docker_output"
mainpyifile = "main_ps3gud.py"
updaterpyifile = "updater.py"
#get data from release.json
with open("release.json", "r", encoding="utf8") as f:
release = json.loads(f.read())
Expand All @@ -232,6 +251,7 @@ def __exit__(self, type, value, traceback):
zip_check = False
upx_check = False
upx_pathstr = ""
docker = False
if args.compiled == True and args.source == True:
print("You cant pass \"-c\" and \"-s\" to the buildscript.")
sys.exit()
Expand Down Expand Up @@ -265,6 +285,10 @@ def __exit__(self, type, value, traceback):
if args.zip == True:
zip_check = True
zipname = "dist/PS3GameUpdateDownloader-"+release["version"]
if args.docker == True:
docker = True
if os.path.exists(dockerdir) == False:
os.makedirs(dockerdir)

#auto config for build

Expand Down Expand Up @@ -295,13 +319,13 @@ def __exit__(self, type, value, traceback):
if action == "":
print("use '-h' for help")
else:
print(f"build options:\nmode: {action}\narch: {arch}\n git commit: {release['commitid']}\nupx: {upx_check}{upx_pathstr}\nzip: {zip_check}")
print(f"build options:\nmode: {action}\narch: {arch}\ngit commit: {release['commitid']}\nupx: {upx_check} {upx_pathstr}\nzip: {zip_check}\ndocker: {docker}")

if action == "sourcerelease":
#release running from source
if os.path.exists(builddir):
#delete old build
shutil.rmtree(builddir)
shutil.rmtree(builddir, onerror=remove_readonly)
os.makedirs(builddir)
else:
os.makedirs(builddir)
Expand All @@ -310,7 +334,7 @@ def __exit__(self, type, value, traceback):
buildheader(release, buildlog)
#copy scripts
print(f"copying scripts to '{builddir}'")
shutil.copy2("main.py", os.path.join(builddir, "main.py"))
shutil.copy2("main_ps3gud.py", os.path.join(builddir, "main_ps3gud.py"))
shutil.copy2("utils.py", os.path.join(builddir, "utils.py"))
shutil.copy2("updater.py", os.path.join(builddir, "updater.py"))
shutil.copy2("PS3GUD.py", os.path.join(builddir, "PS3GUD.py"))
Expand All @@ -331,14 +355,18 @@ def __exit__(self, type, value, traceback):
print(f"calculating checksum for archive '{zipname}.{ARCHIVEFORMAT}'")
digest = createDigest(zipname+"."+ARCHIVEFORMAT)
print(f"checksum written to '{zipname}.{ARCHIVEFORMAT}.sha256'\nchecksum: '{digest}'")
if docker == True:
print(f'copied build zip to "{dockerdir}"')
shutil.copy2(zipname+"."+ARCHIVEFORMAT, os.path.join(dockerdir, os.path.basename(zipname)+"."+ARCHIVEFORMAT))
shutil.copy2(zipname+"."+ARCHIVEFORMAT+".sha256", os.path.join(dockerdir, os.path.basename(zipname)+"."+ARCHIVEFORMAT+".sha256"))

if action == "sourcedebug":
#debug running from source
builddir += "Debug"
buildlog = os.path.join(builddir, "build.log")
if os.path.exists(builddir):
#delete old build
shutil.rmtree(builddir)
shutil.rmtree(builddir, onerror=remove_readonly)
os.makedirs(builddir)
else:
os.makedirs(builddir)
Expand All @@ -347,7 +375,7 @@ def __exit__(self, type, value, traceback):
buildheader(release, buildlog)
#copy scripts
print(f"copying scripts to '{builddir}'")
shutil.copy2("main.py", os.path.join(builddir, "main.py"))
shutil.copy2("main_ps3gud.py", os.path.join(builddir, "main_ps3gud.py"))
shutil.copy2("utils.py", os.path.join(builddir, "utils.py"))
shutil.copy2("updater.py", os.path.join(builddir, "updater.py"))
shutil.copy2("PS3GUD.py", os.path.join(builddir, "PS3GUD.py"))
Expand All @@ -369,12 +397,16 @@ def __exit__(self, type, value, traceback):
print(f"calculating checksum for archive '{zipname}.{ARCHIVEFORMAT}'")
digest = createDigest(zipname+"."+ARCHIVEFORMAT)
print(f"checksum written to '{zipname}.{ARCHIVEFORMAT}.sha256'\nchecksum: '{digest}'")
if docker == True:
print(f'copied build zip to "{dockerdir}"')
shutil.copy2(zipname+"."+ARCHIVEFORMAT, os.path.join(dockerdir, os.path.basename(zipname)+"."+ARCHIVEFORMAT))
shutil.copy2(zipname+"."+ARCHIVEFORMAT+".sha256", os.path.join(dockerdir, os.path.basename(zipname)+"."+ARCHIVEFORMAT+".sha256"))

if action == "compilerelease":
#compiled release
#delete old build
if os.path.exists(builddir):
shutil.rmtree(builddir)
shutil.rmtree(builddir, onerror=remove_readonly)
os.makedirs(builddir)
else:
os.makedirs(builddir)
Expand All @@ -398,7 +430,7 @@ def __exit__(self, type, value, traceback):
arg_main.append("--upx-dir="+upx_paths.get_upx_dir())
if platform.system() == "Windows": # fix for UPX
arg_main.append("--upx-exclude=vcruntime140.dll")
arg_main.append("main.py")
arg_main.append(mainpyifile)
PyInstaller.__main__.run(arg_main)
#build updater executable
print("building updater executable")
Expand All @@ -413,7 +445,7 @@ def __exit__(self, type, value, traceback):
arg_updater.append("--upx-dir="+upx_paths.get_upx_dir())
if platform.system() == "Windows": # fix for UPX
arg_updater.append("--upx-exclude=vcruntime140.dll")
arg_updater.append("updater.py")
arg_updater.append(updaterpyifile)
PyInstaller.__main__.run(arg_updater)
#move executables to buildir
print(f"copying executables to '{builddir}'")
Expand All @@ -437,14 +469,18 @@ def __exit__(self, type, value, traceback):
print(f"calculating checksum for archive '{zipname}.{ARCHIVEFORMAT}'")
digest = createDigest(zipname+"."+ARCHIVEFORMAT)
print(f"checksum written to '{zipname}.{ARCHIVEFORMAT}.sha256'\nchecksum: '{digest}'")
if docker == True:
print(f'copied build zip to "{dockerdir}"')
shutil.copy2(zipname+"."+ARCHIVEFORMAT, os.path.join(dockerdir, os.path.basename(zipname)+"."+ARCHIVEFORMAT))
shutil.copy2(zipname+"."+ARCHIVEFORMAT+".sha256", os.path.join(dockerdir, os.path.basename(zipname)+"."+ARCHIVEFORMAT+".sha256"))

if action == "compiledebug":
#compiled debug
builddir += "Debug"
buildlog = os.path.join(builddir, "build.log")
#delete old build
if os.path.exists(builddir):
shutil.rmtree(builddir)
shutil.rmtree(builddir, onerror=remove_readonly)
os.makedirs(builddir)
else:
os.makedirs(builddir)
Expand All @@ -469,7 +505,7 @@ def __exit__(self, type, value, traceback):
arg_main.append("--upx-dir="+upx_paths.get_upx_dir())
if platform.system() == "Windows": # fix for UPXed executables not starting
arg_main.append("--upx-exclude=vcruntime140.dll")
arg_main.append("main.py")
arg_main.append(mainpyifile)
PyInstaller.__main__.run(arg_main)
#build updater executable
print("building updater executable")
Expand All @@ -483,7 +519,7 @@ def __exit__(self, type, value, traceback):
arg_updater.append("--upx-dir="+upx_paths.get_upx_dir())
if platform.system() == "Windows": # fix for UPXed executables not starting
arg_updater.append("--upx-exclude=vcruntime140.dll")
arg_updater.append("updater.py")
arg_updater.append(updaterpyifile)
PyInstaller.__main__.run(arg_updater)
#move executables to buildir
print(f"copying executables to '{builddir}'")
Expand All @@ -508,3 +544,7 @@ def __exit__(self, type, value, traceback):
print(f"calculating checksum for archive '{zipname}.{ARCHIVEFORMAT}'")
digest = createDigest(zipname+"."+ARCHIVEFORMAT)
print(f"checksum written to '{zipname}.{ARCHIVEFORMAT}.sha256'\nchecksum: '{digest}'")
if docker == True:
print(f'copied build zip to "{dockerdir}"')
shutil.copy2(zipname+"."+ARCHIVEFORMAT, os.path.join(dockerdir, os.path.basename(zipname)+"."+ARCHIVEFORMAT))
shutil.copy2(zipname+"."+ARCHIVEFORMAT+".sha256", os.path.join(dockerdir, os.path.basename(zipname)+"."+ARCHIVEFORMAT+".sha256"))
6 changes: 3 additions & 3 deletions docker_build.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
echo "building amd64"
sudo docker build . -t ps3gud-amd64 -f dockerfile-amd64
sudo docker run -it --rm -v ${PWD}/docker_output:/dist -u $(id -u) ps3gud-amd64
echo "building linux amd64"
sudo docker build . -t ps3gud-linux-amd64 -f dockerfiles/dockerfile-linux-amd64
sudo docker run -it --rm -v ${PWD}/docker_output:/docker_output -u $(id -u) ps3gud-linux-amd64
#fix up permisions
sudo chown -hR $(whoami) docker_output
4 changes: 2 additions & 2 deletions dockerfile-amd64 → dockerfiles/dockerfile-linux-amd64
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM amd64/python:3.11-bookworm

WORKDIR ./
VOLUME /dist
VOLUME /docker_output
#setup requirements
RUN apt update -y

Expand All @@ -16,4 +16,4 @@ RUN pip install --disable-pip-version-check --no-cache-dir -r requirements.txt
RUN pip install --disable-pip-version-check --no-cache-dir -r buildrequirements.txt

COPY . .
CMD [ "python", "./build.py", "-c", "-r", "-z" ]
CMD [ "python", "./build.py", "-c", "-r", "-z", "--docker" ]
2 changes: 1 addition & 1 deletion gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def mainWin(self):
[sg.Text(self.loc.getKey("window_main_titleid_label"), key="window_main_titleid_label", size=(50,1))],
[sg.Input(key="titleid"),sg.Button(self.loc.getKey("window_main_enter_btn"), key="Enter", bind_return_key=True), sg.Button(self.loc.getKey("window_main_queue_btn"), key="Queue"), sg.Button(self.loc.getKey("window_main_config_btn") ,key="Config")],
[sg.Text("", size=(30, 3), key="window_main_progress_label")],
[sg.ProgressBar(100, orientation="h", size=(52.85, 20), key="window_main_progress_bar")],
[sg.ProgressBar(0, orientation="h", size=(52.85, 20), key="window_main_progress_bar")],
[sg.Output(size=(80,20), key="Out")],
[sg.Button(self.loc.getKey("window_main_exit_btn"), key="Exit")]
]
Expand Down
2 changes: 1 addition & 1 deletion main.py → main_ps3gud.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ def run():
g.mainWin()

if __name__ == "__main__":
run()
run()
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ PySimpleGUI==4.60.5
keyring==24.2.0
requests[socks]==2.31.0
setuptools==68.0.0
psutil==5.9.5
18 changes: 9 additions & 9 deletions updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,41 +11,41 @@
import json
import subprocess
import shlex
import sys

#local files
import utils

#pip packages
import PySimpleGUI as sg


time.sleep(1) #wait 1 seconds to ensure main application has closed
if os.path.exists(os.path.join(tempfile.gettempdir(), "PS3GUDUpdate.json")) and os.path.isfile(os.path.join(tempfile.gettempdir(), "PS3GUDUpdate.json")):
with open(os.path.join(tempfile.gettempdir(), "PS3GUDUpdate.json"), "r", encoding="utf8") as f:
data = json.loads(f.read())

sg.change_look_and_feel("DarkAmber")
layout = [
[sg.Text("Checking for updates", size=(40, 3), key="updater_text")],
[sg.Text("Waiting for main application to exit", size=(40, 3), key="updater_text")],
[sg.ProgressBar(100, orientation="h", size=(40, 20), key="updater_progressbar")]
]
window = sg.Window("PS3GUD Updater", layout)
window.finalize()
window.Refresh()
text = window["updater_text"]
bar = window["updater_progressbar"]
utils.waitForMainAppExit(pid = data["pid"], window = window)
text.Update("Checking for updates")
window.Refresh()
rel = utils.UpdaterGithubRelease(os.path.join(data["dir"], "release.json"))
resp = rel.checkForNewRelease()
if isinstance(resp, dict):
text.Update("Found new release!")
rel.downloadNewRelease(data["dir"], window)
suffix = utils.getExecutableSuffix()
exename = utils.getMainExecutableBasename()+utils.getExecutableSuffix()
if utils.isAppFrozen():
file = os.path.join(data["dir"], "ps3gud"+suffix)
file = os.path.join(data["dir"], exename)
else:
if platform.system() == "Windows":
file = "py "+os.path.join(data["dir"], "main"+suffix)
file = "python3 "+os.path.join(data["dir"], exename)
if platform.system() == "Linux":
file = shlex.split("python3 "+os.path.join(data["dir"], "main"+suffix))
file = shlex.split(file)
subprocess.Popen(file)
window.close()
Loading

0 comments on commit 78e41a6

Please sign in to comment.