From f23f5a3a0007bc8c599c08f506153ec9f5aacd18 Mon Sep 17 00:00:00 2001 From: iou1name Date: Mon, 3 Jun 2019 08:29:03 -0400 Subject: [PATCH] added overwrought_slave.py --- .gitignore | 2 ++ README.md | 12 ++++++-- config_master.py.template | 0 config_server.py.template | 0 config_slave.py.template | 6 ++++ overwrought_slave.py | 63 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 81 insertions(+), 2 deletions(-) mode change 100644 => 100755 config_master.py.template mode change 100644 => 100755 config_server.py.template create mode 100755 config_slave.py.template create mode 100755 overwrought_slave.py diff --git a/.gitignore b/.gitignore index f3897c6..2815c24 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ __pycache__/ +mods/ *.swp *.swo +*.db config_master.py config_server.py config_slave.py diff --git a/README.md b/README.md index 0ebfdaa..acd0e17 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,8 @@ Python packages: `flask gunicorn passlib argon2_cffi` Python packages: ` ` ## Usage -### Master +### Master +Copy `overwrought_master.py` and the matching config file to your `.minecraft/` folder. Edit the config file appropriately. `$ python3 overwrought_master.py action [options] [target]` __actions__ * `add` Add a new mod to the modpack. `target` must be a url to a curseforge mod project page. By default, it will prioritize release phases as Release, Beta and then Alpha. `--phase` can alter this. Will always grab the latest version of whichever phase it targets. @@ -19,5 +20,12 @@ __actions__ * `update` Update a specific mod in the modpack. `target` must be the url associated with the mod. By default, it will prioritize the release phase previously added. `--phase` can alter this. Will only update if the targeted mod is more recent than the one previously downloaded. * `update_all` Update every mod in the modpack. No `target` needed. Will prioritize release phases similar to `update`, however `--phase` will will not affect it. * `summary` Generate a summary page as html. Summary page displays a list of all mods in the modpack and a change log that is updated as changes are made to the modpack. + ### Server -`gunicorn -b localhost:5000 -e SCRIPT_NAME=/overwrought overwrought_server:app` +`gunicorn -b localhost:5000 -e SCRIPT_NAME=/overwrought overwrought_server:app` +Use `overwrought_server.py hash` to generate an Argon2 hash of your password. Update `config_server.py` appropriately. + +### Slave +Copy `overwrought_slave.py` and the matching config file to your `.minecraft/` folder. Edit the config file appropriately. +Use `overwrought_slave.py sync` to synchronize the `mods/` folder with the remote server. +By default, old versions of mods (and any other non-modpack related file found in the `mods/` folder) will be moved to `mods_old/`. `--delete` may be used to delete these files instead eg. `overwrought_slave.py sync --delete`. diff --git a/config_master.py.template b/config_master.py.template old mode 100644 new mode 100755 diff --git a/config_server.py.template b/config_server.py.template old mode 100644 new mode 100755 diff --git a/config_slave.py.template b/config_slave.py.template new file mode 100755 index 0000000..09310c2 --- /dev/null +++ b/config_slave.py.template @@ -0,0 +1,6 @@ +#!/usr/bin/env python3 +""" +Configuration settings for overwrought_slave.py. +`remote_addr` is the address of the remote Overwrought server. +""" +remote_addr = "https://stream.steelbea.me/overwrought" diff --git a/overwrought_slave.py b/overwrought_slave.py new file mode 100755 index 0000000..5539e55 --- /dev/null +++ b/overwrought_slave.py @@ -0,0 +1,63 @@ +#!/usr/bin/env python3 +""" +The end user script for the modpack. +""" +import os +import json +import urllib.parse +import urllib.request + +import config_slave + +def sync(delete=False): + """ + Synchronize the local `mods/` folder with the remote server. + """ + remote_mods =urllib.request.urlopen(config_slave.remote_addr+'/get').read() + remote_mods = json.loads(remote_mods) + local_mods = os.listdir('mods') + + local_mods_del = [mod for mod in local_mods if mod not in remote_mods] + remote_mods_get = [mod for mod in remote_mods if mod not in local_mods] + + for mod in local_mods_del: + if delete: + os.remove(os.path.join('mods', mod)) + else: + os.makedirs('mods_old', exist_ok=True) + os.rename(os.path.join('mods', mod), os.path.join('mods_old', mod)) + print(f"Deleted {mod}") + + for mod in remote_mods_get: + url = config_slave.remote_addr + '/mods/' + urllib.parse.quote(mod) + res = urllib.request.urlopen(url) + data = res.read() + with open(os.path.join('mods', mod), 'wb') as file: + file.write(data) + print(f"Downloaded {mod}") + print("Success!") + +if __name__ == "__main__": + import argparse + + parser = argparse.ArgumentParser( + description="Script for synchronizing the local mods/ folder " + "with the remote server." + ) + parser.add_argument( + 'action', + choices=['sync'], + default='sync', + help="What action to perform." + ) + parser.add_argument( + '--delete', + action='store_true', + help="By default, old mods are moved to a mods_old/ folder " + "instead of being deleted. Checking this flag will delete " + "them instead." + ) + args = parser.parse_args() + + if args.action == 'sync': + sync(args.delete)