added overwrought_slave.py
This commit is contained in:
parent
89e401b730
commit
f23f5a3a00
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,6 +1,8 @@
|
||||||
__pycache__/
|
__pycache__/
|
||||||
|
mods/
|
||||||
*.swp
|
*.swp
|
||||||
*.swo
|
*.swo
|
||||||
|
*.db
|
||||||
config_master.py
|
config_master.py
|
||||||
config_server.py
|
config_server.py
|
||||||
config_slave.py
|
config_slave.py
|
||||||
|
|
12
README.md
12
README.md
|
@ -11,7 +11,8 @@ Python packages: `flask gunicorn passlib argon2_cffi`
|
||||||
Python packages: ` `
|
Python packages: ` `
|
||||||
|
|
||||||
## Usage
|
## 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]`
|
`$ python3 overwrought_master.py action [options] [target]`
|
||||||
__actions__
|
__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.
|
* `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` 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.
|
* `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.
|
* `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
|
### 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`.
|
||||||
|
|
0
config_master.py.template
Normal file → Executable file
0
config_master.py.template
Normal file → Executable file
0
config_server.py.template
Normal file → Executable file
0
config_server.py.template
Normal file → Executable file
6
config_slave.py.template
Executable file
6
config_slave.py.template
Executable 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
63
overwrought_slave.py
Executable 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)
|
Loading…
Reference in New Issue
Block a user