added overwrought_slave.py

This commit is contained in:
iou1name 2019-06-03 08:29:03 -04:00
parent 89e401b730
commit f23f5a3a00
6 changed files with 81 additions and 2 deletions

2
.gitignore vendored
View File

@ -1,6 +1,8 @@
__pycache__/
mods/
*.swp
*.swo
*.db
config_master.py
config_server.py
config_slave.py

View File

@ -12,6 +12,7 @@ Python packages: ` `
## Usage
### 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`
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`.

0
config_master.py.template Normal file → Executable file
View File

0
config_server.py.template Normal file → Executable file
View File

6
config_slave.py.template Executable file
View File

@ -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"

63
overwrought_slave.py Executable file
View File

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