From bfda08df41883b28201aa3b42a9b5ef3b2641f12 Mon Sep 17 00:00:00 2001 From: r58Playz <45221816+r58Playz@users.noreply.github.com> Date: Fri, 19 Apr 2019 10:10:51 -0700 Subject: [PATCH 01/14] Create update.py --- update.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 update.py diff --git a/update.py b/update.py new file mode 100644 index 00000000..2f0538fa --- /dev/null +++ b/update.py @@ -0,0 +1,25 @@ +from subprocess import check_call as run +import shutil +import os +import time +import sys + +def update(): + UPDATE_CMD = ( # base command + 'git clone ' + 'https://github.com/boskee/Minecraft.git pycraft_update --quiet' + ) + try: + run(UPDATE_CMD) + except: + print("An error occured. Exiting...") + time.sleep(3) + sys.exit() + files=os.listdir("pycraft_update") + for fle in files: + full_filename = os.path.join("pycraft_update", fle) + if os.path.isfile(full_filename): + if file != "update.py": + current_dir=os.path.basename(os.getcwd()) + shutil.copy(full_filename, current_dir) + run(('rm -rf','pycraft_update') #this should work. I haven't tested it. From bc7a6f71aa7ad6dddb68ed025f69d1addfd102ff Mon Sep 17 00:00:00 2001 From: r58Playz <45221816+r58Playz@users.noreply.github.com> Date: Fri, 19 Apr 2019 10:28:30 -0700 Subject: [PATCH 02/14] Add update button in main menu Adds a update button, so users do not have to manually run update.py --- views.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/views.py b/views.py index d9ed267b..fbae0933 100644 --- a/views.py +++ b/views.py @@ -22,6 +22,7 @@ button_disabled, resize_button_image from textures import TexturePackList from utils import image_sprite, load_image +from update import update as up __all__ = ( 'View', 'MainMenuView', 'OptionsView', 'ControlsView', 'TexturesView', 'MultiplayerView' @@ -256,6 +257,9 @@ def setup(self): button = self.Button(caption=G._("Exit game"),on_click=self.controller.exit_game) self.layout.add(button) self.buttons.append(button) + button = self.Button(caption=G._("Update game"), on_click=up) + self.layout.add(button) + self.buttons.append(button) # Splash text self.splash_text = 'Hello!' From b07d30c3eb1a563a85f357c683de753c9385f9ce Mon Sep 17 00:00:00 2001 From: r58Playz <45221816+r58Playz@users.noreply.github.com> Date: Fri, 19 Apr 2019 10:56:13 -0700 Subject: [PATCH 03/14] Update update.py --- update.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/update.py b/update.py index 2f0538fa..a220315f 100644 --- a/update.py +++ b/update.py @@ -22,4 +22,4 @@ def update(): if file != "update.py": current_dir=os.path.basename(os.getcwd()) shutil.copy(full_filename, current_dir) - run(('rm -rf','pycraft_update') #this should work. I haven't tested it. + shutil.rmtree("pycraft_update", ignore-errors=True) From 8ceada3dd0c5f818cf027f730e611d60e3c092cc Mon Sep 17 00:00:00 2001 From: r58Playz <45221816+r58Playz@users.noreply.github.com> Date: Fri, 19 Apr 2019 10:59:38 -0700 Subject: [PATCH 04/14] Create del.bat --- del.bat | 1 + 1 file changed, 1 insertion(+) create mode 100644 del.bat diff --git a/del.bat b/del.bat new file mode 100644 index 00000000..c7d1b2b3 --- /dev/null +++ b/del.bat @@ -0,0 +1 @@ +rm -r -fo pycraft_update From 4196093e6818335cb43671052ee93bcffd3c7ab3 Mon Sep 17 00:00:00 2001 From: r58Playz <45221816+r58Playz@users.noreply.github.com> Date: Fri, 19 Apr 2019 11:02:38 -0700 Subject: [PATCH 05/14] Update update.py --- update.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/update.py b/update.py index a220315f..05173e2d 100644 --- a/update.py +++ b/update.py @@ -1,4 +1,5 @@ from subprocess import check_call as run +from subprocess import call import shutil import os import time @@ -22,4 +23,4 @@ def update(): if file != "update.py": current_dir=os.path.basename(os.getcwd()) shutil.copy(full_filename, current_dir) - shutil.rmtree("pycraft_update", ignore-errors=True) + call("del.bat") From 181c565f354c7f77880d042e3aa585a81f821687 Mon Sep 17 00:00:00 2001 From: r58Playz <45221816+r58Playz@users.noreply.github.com> Date: Fri, 19 Apr 2019 11:03:06 -0700 Subject: [PATCH 06/14] Rename del.bat to del.ps1 --- del.bat => del.ps1 | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename del.bat => del.ps1 (100%) diff --git a/del.bat b/del.ps1 similarity index 100% rename from del.bat rename to del.ps1 From 7ddf41bbbdb2aacb477b6d6f30208c5060371b36 Mon Sep 17 00:00:00 2001 From: r58Playz <45221816+r58Playz@users.noreply.github.com> Date: Fri, 19 Apr 2019 11:03:31 -0700 Subject: [PATCH 07/14] Update update.py --- update.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/update.py b/update.py index 05173e2d..06b6846e 100644 --- a/update.py +++ b/update.py @@ -23,4 +23,4 @@ def update(): if file != "update.py": current_dir=os.path.basename(os.getcwd()) shutil.copy(full_filename, current_dir) - call("del.bat") + call("del.ps1") From ef18140be01a419611cf088384a1999792d62fca Mon Sep 17 00:00:00 2001 From: r58Playz <45221816+r58Playz@users.noreply.github.com> Date: Fri, 19 Apr 2019 15:48:44 -0700 Subject: [PATCH 08/14] Delete del.ps1 --- del.ps1 | 1 - 1 file changed, 1 deletion(-) delete mode 100644 del.ps1 diff --git a/del.ps1 b/del.ps1 deleted file mode 100644 index c7d1b2b3..00000000 --- a/del.ps1 +++ /dev/null @@ -1 +0,0 @@ -rm -r -fo pycraft_update From 947bfadbbd492008e51fc4e228a2e567bf267114 Mon Sep 17 00:00:00 2001 From: r58Playz <45221816+r58Playz@users.noreply.github.com> Date: Fri, 19 Apr 2019 15:54:06 -0700 Subject: [PATCH 09/14] Update for non-git users --- update.py | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/update.py b/update.py index 06b6846e..5bb421f3 100644 --- a/update.py +++ b/update.py @@ -4,18 +4,13 @@ import os import time import sys +import zipfile def update(): - UPDATE_CMD = ( # base command - 'git clone ' - 'https://github.com/boskee/Minecraft.git pycraft_update --quiet' - ) - try: - run(UPDATE_CMD) - except: - print("An error occured. Exiting...") - time.sleep(3) - sys.exit() + updatezip = urllib.request.urlopen('https://github.com/boskee/Minecraft/archive/master.zip') + zipref = zipfile.ZipFile(BytesIO(updatezip.read())) + zipref.extractall("pycraft_update") + zipref.close() files=os.listdir("pycraft_update") for fle in files: full_filename = os.path.join("pycraft_update", fle) @@ -23,4 +18,4 @@ def update(): if file != "update.py": current_dir=os.path.basename(os.getcwd()) shutil.copy(full_filename, current_dir) - call("del.ps1") + shutil.rmtree("pycraft_update") From c61dbbbb1ecbab80e607619713075b64759ab618 Mon Sep 17 00:00:00 2001 From: r58Playz <45221816+r58Playz@users.noreply.github.com> Date: Fri, 19 Apr 2019 15:56:06 -0700 Subject: [PATCH 10/14] Add start function for updater --- main.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index 01251059..d91e5489 100755 --- a/main.py +++ b/main.py @@ -144,9 +144,8 @@ def main(options): G.main_timer.stop() G.SERVER._stop.set() G.SERVER.shutdown() - -if __name__ == '__main__': - log_info('Starting pyCraft...') +def start(): + log_info('Starting pyCraft...') parser = argparse.ArgumentParser(description='Play a Python made Minecraft clone.') @@ -163,3 +162,5 @@ def main(options): options = parser.parse_args() main(options) +if __name__ == '__main__': + start() From 858642677fb4405cdeb683d533d8699e85ce36e3 Mon Sep 17 00:00:00 2001 From: r58Playz <45221816+r58Playz@users.noreply.github.com> Date: Fri, 19 Apr 2019 15:57:29 -0700 Subject: [PATCH 11/14] Add ability to restart game --- update.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/update.py b/update.py index 5bb421f3..e3bc3e99 100644 --- a/update.py +++ b/update.py @@ -5,6 +5,7 @@ import time import sys import zipfile +import main def update(): updatezip = urllib.request.urlopen('https://github.com/boskee/Minecraft/archive/master.zip') @@ -19,3 +20,4 @@ def update(): current_dir=os.path.basename(os.getcwd()) shutil.copy(full_filename, current_dir) shutil.rmtree("pycraft_update") + main.start()# Should work... From a4f28e5d933da6fd31fe7fb9cc479f2f5327450f Mon Sep 17 00:00:00 2001 From: r58Playz <45221816+r58Playz@users.noreply.github.com> Date: Fri, 19 Apr 2019 17:08:27 -0700 Subject: [PATCH 12/14] Remove unnessesary imports --- update.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/update.py b/update.py index e3bc3e99..116d2a81 100644 --- a/update.py +++ b/update.py @@ -1,9 +1,5 @@ -from subprocess import check_call as run -from subprocess import call import shutil import os -import time -import sys import zipfile import main From bfa51bd53b2ada03296bb9846649380315754b88 Mon Sep 17 00:00:00 2001 From: r58Playz <45221816+r58Playz@users.noreply.github.com> Date: Sun, 21 Apr 2019 08:04:18 -0700 Subject: [PATCH 13/14] Fix update.py --- update.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/update.py b/update.py index 116d2a81..4bc25594 100644 --- a/update.py +++ b/update.py @@ -1,7 +1,7 @@ import shutil import os import zipfile -import main +import urllib def update(): updatezip = urllib.request.urlopen('https://github.com/boskee/Minecraft/archive/master.zip') @@ -16,4 +16,5 @@ def update(): current_dir=os.path.basename(os.getcwd()) shutil.copy(full_filename, current_dir) shutil.rmtree("pycraft_update") + import main # Wonder what happens if you put this at the top? A TRACEBACK! main.start()# Should work... From 589e9e6c5423ccb2148aabec80d0abfdfb53e02b Mon Sep 17 00:00:00 2001 From: r58Playz <45221816+r58Playz@users.noreply.github.com> Date: Sun, 21 Apr 2019 10:56:36 -0700 Subject: [PATCH 14/14] Update update.py --- update.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/update.py b/update.py index 4bc25594..662ab803 100644 --- a/update.py +++ b/update.py @@ -1,7 +1,7 @@ import shutil import os import zipfile -import urllib +import urllif.request def update(): updatezip = urllib.request.urlopen('https://github.com/boskee/Minecraft/archive/master.zip')