Skip to content

Commit

Permalink
Reimplement get-mods.sh as a Python script
Browse files Browse the repository at this point in the history
Users no longer require sh, curl, unzip, or a *nix environment in order
to automatically download the required mods. This should allow users of
other operating systems such as Windows to also use this script.

Bug: #28
  • Loading branch information
vilhelmgray committed Apr 1, 2020
1 parent 3e3fe2e commit 37e17b5
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 52 deletions.
53 changes: 53 additions & 0 deletions get_mods.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env python3

import io
import os
import shutil
import sys
import urllib.request
import zipfile

worldmods = os.path.normpath(sys.argv[1])
if not os.path.exists(worldmods):
print("The provided path does not exist")
exit(1)

mods = (
("https://codeload.github.com/minetest-mods/mesecons/zip/master", "mesecons"),
("https://codeload.github.com/LNJ2/carpet/zip/master", "carpet"),
("https://codeload.github.com/minetest-mods/crops/zip/master", "crops"),
("https://codeload.github.com/minetest-mods/flowerpot/zip/master", "flowerpot"),
("https://codeload.github.com/minetest-mods/lapis/zip/master", "lapis"),
("https://codeload.github.com/minetest-mods/quartz/zip/master", "quartz"),
("https://codeload.github.com/minetest-mods/xdecor/zip/master", "xdecor"),
("https://codeload.github.com/oOChainLynxOo/hardenedclay/zip/master", "hardenedclay"),
("https://codeload.github.com/minetest-mods/nether/zip/master", "nether"),
("https://codeload.github.com/ShadowNinja/minetest_bedrock/zip/master", "minetest_bedrock"),
("https://gitlab.com/VanessaE/basic_materials/-/archive/master/basic_materials-master.zip", "basic_materials"),
("https://gitlab.com/VanessaE/biome_lib/-/archive/master/biome_lib-master.zip", "biome_lib"),
("https://gitlab.com/VanessaE/plantlife_modpack/-/archive/master/plantlife_modpack-master.zip", "plantlife_modpack"),
("https://gitlab.com/VanessaE/signs_lib/-/archive/master/signs_lib-master.zip", "signs_lib")
)

# Some servers don't recognize the default Python-urllib user agent
headers = { 'User-Agent':'Mozilla' }

for url, mod in mods:
print("Fetching:", mod);
request = urllib.request.Request(url, None, headers)
with urllib.request.urlopen(request) as response:
with zipfile.ZipFile(io.BytesIO(response.read()), 'r') as mod_zip:
mod_zip.extractall(worldmods)
mod = os.path.normpath(worldmods+"/"+mod)
os.rename(mod+"-master", mod)
minetest_bedrock = os.path.normpath(worldmods+"/"+"minetest_bedrock")
bedrock = os.path.normpath(worldmods+"/"+"bedrock")
os.rename(minetest_bedrock, bedrock)

# Remove unneeded/unwanted submods
prune = ( "dryplants", "along_shore", "molehills", "woodsoils", "bushes", "bushes_classic", "youngtrees", "3dmushrooms", "cavestuff", "poisonivy", "trunks" )
for ex in prune:
ex = "plantlife_modpack/" + ex
print("Pruning:", ex)
ex = os.path.normpath(worldmods+"/"+ex)
shutil.rmtree(ex)
51 changes: 1 addition & 50 deletions mcimport.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,55 +50,6 @@
sn.write(" vm:update_map()\n")
sn.write("end)\n\n")

if not os.path.exists(sys.argv[2]+"/get-mods.sh"):
path = sys.argv[2]+"/get-mods.sh"
with open(path, "w") as md:
md.write('''\
#!/bin/sh
# run this script to automatically get all the required mods
mods=(
https://codeload.github.com/minetest-mods/mesecons/zip/master,mesecons
https://codeload.github.com/LNJ2/carpet/zip/master,carpet
https://codeload.github.com/minetest-mods/crops/zip/master,crops
https://codeload.github.com/minetest-mods/flowerpot/zip/master,flowerpot
https://codeload.github.com/minetest-mods/lapis/zip/master,lapis
https://codeload.github.com/minetest-mods/quartz/zip/master,quartz
https://codeload.github.com/minetest-mods/xdecor/zip/master,xdecor
https://codeload.github.com/oOChainLynxOo/hardenedclay/zip/master,hardenedclay
https://codeload.github.com/minetest-mods/nether/zip/master,nether
https://codeload.github.com/ShadowNinja/minetest_bedrock/zip/master,minetest_bedrock
https://gitlab.com/VanessaE/basic_materials/-/archive/master/basic_materials-master.zip,basic_materials
https://gitlab.com/VanessaE/biome_lib/-/archive/master/biome_lib-master.zip,biome_lib
https://gitlab.com/VanessaE/plantlife_modpack/-/archive/master/plantlife_modpack-master.zip,plantlife_modpack
https://gitlab.com/VanessaE/signs_lib/-/archive/master/signs_lib-master.zip,signs_lib
)
cd worldmods
for item in ${mods[@]} ; do
(
url=$(echo $item | cut -d, -f1)
mod=$(echo $item | cut -d, -f2)
echo "Fetching: $mod"
curl -q -L -o $mod.zip $url
unzip -qq $mod.zip
rm $mod.zip
mv $mod-master $mod
mv minetest_bedrock bedrock
)
done
# remove unneeded/unwanted submods
for ex in plantlife_modpack/dryplants plantlife_modpack/along_shore plantlife_modpack/molehills plantlife_modpack/woodsoils plantlife_modpack/bushes plantlife_modpack/bushes_classic plantlife_modpack/youngtrees plantlife_modpack/3dmushrooms plantlife_modpack/cavestuff plantlife_modpack/poisonivy plantlife_modpack/trunks; do
echo "Pruning: $ex"
rm -rf $ex
done
''')
st = os.stat(path)
os.chmod(path, st.st_mode | stat.S_IXUSR)

mcmap = MCMap(sys.argv[1])
mtmap = MTMap(sys.argv[2])

Expand All @@ -107,4 +58,4 @@
mtmap.save()

print("Conversion finished!\n")
print("Run \"sh get-mods.sh\" in the new world folder to automatically download all required mods.")
print("Pass the new world folder to get_mods.py to automatically download all required mods."
3 changes: 1 addition & 2 deletions mcimport.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@ if [ $? == 0 ]; then
if ! zenity --width=800 --question --title="Download required mods?" --text="The world was succesfully converted. Do you want me to download and install all the required mods now? This should be done for each converted world."; then
exit 0
fi
cd "${HOME}/.minetest/worlds/$OUT"
(
bash get-mods.sh
python3 get_mods.py "${HOME}/.minetest/worlds/$OUT"
echo "====================="
echo "Finished! You can now close this window!"
) | zenity --text-info --width=800 --height=600 --title='Downloading required mods.' --text='Downloading...'
Expand Down

0 comments on commit 37e17b5

Please sign in to comment.