Browse Source

Finished chunkymap installer for Windows

master
poikilos 9 years ago
committed by Jacob Gustafson
parent
commit
47746174d4
  1. 50
      README.md
  2. 3
      chunkymap-regen-loop.bat
  3. 5
      install-chunkymap-on-windows.bat
  4. 210
      install-chunkymap-on-windows.py

50
README.md

@ -87,29 +87,33 @@ world_path
#--no-clobber: do not overwrite existing
# after you do this, the update script will do it for you if you are using /var/www/html/minetest, otherwise edit the update script before using it to get these things updated
* IF you are using Windows
* put these files anywhere
* python 2.7.x such as from python.org
* run get_python_architecture.py to make sure you know whether to download the following in 32-bit or 64-bit
Administrator Command Prompt (to find it in Win 10, right-click windows menu)
* update python package system:
`C:\python27\python -m pip install --upgrade pip wheel setuptools`
* numpy such as can be installed via the easy unofficial installer wheel at
http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy
then:
cd to the folder where you downloaded the whl file
`C:\python27\python -m pip install "numpy-1.10.4+mkl-cp27-cp27m-win32.whl"`
(but put your specific downloaded whl file instead)
* Pillow (instead of PIL (Python Imaging Library) which is a pain on Windows): there is a PIL installer wheel for Python such as 2.7 here:
http://www.lfd.uci.edu/~gohlke/pythonlibs/
as suggested on http://stackoverflow.com/questions/2088304/installing-pil-python-imaging-library-in-win7-64-bits-python-2-6-4
then:
`C:\python27\python -m pip install "Pillow-3.1.1-cp27-none-win32.whl"`
(but put your specific downloaded whl file instead, such as Pillow-3.1.1-cp27-none-win_amd64.whl)
* edit chunkymap_regen.py and uncomment www_minetest_path="/var/www/html/minetest" then change the value in quotes to your web server's htdocs folder such as, if you are using Apache, can be found as the value of the DocumentRoot variable in httpd.conf in the Apache folder in Program Files
* edit chunkymap_regen.py and change world_name to your world name
* run (or if your python executable does not reside in C:\Python27\ then first edit the file):
chunkymap-regen-loop.bat
* copy example.php and chunkymap.php (and optionally browser.php) to your DocumentRoot or whatever folder will contain the chunkymapdata folder
* Install Python 2.7
* Run install-chunkymap-on-windows.bat
(which just runs C:\Python27\python install-chunkymap-on-windows.py)
(the installer will automatically download and install numpy and Pillow)
* OPTIONAL manual install:
* put these files anywhere
* python 2.7.x such as from python.org
* run get_python_architecture.py to make sure you know whether to download the following in 32-bit or 64-bit
Administrator Command Prompt (to find it in Win 10, right-click windows menu)
* update python package system:
`C:\python27\python -m pip install --upgrade pip wheel setuptools`
* numpy such as can be installed via the easy unofficial installer wheel at
http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy
then:
cd to the folder where you downloaded the whl file
`C:\python27\python -m pip install "numpy-1.10.4+mkl-cp27-cp27m-win32.whl"`
(but put your specific downloaded whl file instead)
* Pillow (instead of PIL (Python Imaging Library) which is a pain on Windows): there is a PIL installer wheel for Python such as 2.7 here:
http://www.lfd.uci.edu/~gohlke/pythonlibs/
as suggested on http://stackoverflow.com/questions/2088304/installing-pil-python-imaging-library-in-win7-64-bits-python-2-6-4
then:
`C:\python27\python -m pip install "Pillow-3.1.1-cp27-none-win32.whl"`
(but put your specific downloaded whl file instead, such as Pillow-3.1.1-cp27-none-win_amd64.whl)
* run (or if your python executable does not reside in C:\Python27\ then first edit the file):
chunkymap-regen-loop.bat
(all the batch does is run C:\Python27\python chunkymap-regen.py)
(chunkymap-regen.py will ask for configuration options on first run and ask for your www root)
## Known Issues
* Detect exceptions in mintestmapper (such as database locked) and do not mark the chunk as is_empty

3
chunkymap-regen-loop.bat

@ -1,4 +1 @@
C:\Python27\python.exe chunkymap-regen.py
pause

5
install-chunkymap-on-windows.bat

@ -0,0 +1,5 @@
@echo off
SET TRY_PYTHON_EXE=C:\Python27\pythonw.exe
SET MT_CM_INSTALLER_PY=install-chunkymap-on-windows.py
IF EXIST "%TRY_PYTHON_EXE%" THEN "%TRY_PYTHON_EXE%" "%MT_CM_INSTALLER_PY%"
IF NOT EXIST "%TRY_PYTHON_EXE%" THEN echo You are missing %TRY_PYTHON_EXE% so this batch file cannot use it--try running %MT_CM_INSTALLER_PY% in your favorite Python 2.

210
install-chunkymap-on-windows.py

@ -0,0 +1,210 @@
import platform
import urllib2
import sys
import subprocess
import os
import traceback
#import os.path
def view_traceback():
ex_type, ex, tb = sys.exc_info()
traceback.print_tb(tb)
del tb
#as per Pedro Lobito on http://stackoverflow.com/questions/802134/changing-user-agent-on-urllib2-urlopen
from urllib import FancyURLopener
class MyOpener(FancyURLopener, object):
version = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; it; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11'
def web_get(url, file_name):
myopener = MyOpener()
print("Downloading "+url+"...")
myopener.retrieve(url, file_name)
#as per http://stackoverflow.com/questions/22676/how-do-i-download-a-file-over-http-using-python
def web_get_BADUSERAGENT(url, file_name):
file_name = None
try:
#url = "http://download.thinkbroadband.com/10MB.zip"
#file_name = url.split('/')[-1]
u = urllib2.urlopen(url)
f = open(file_name, 'wb')
meta = u.info()
file_size = int(meta.getheaders("Content-Length")[0])
print "Downloading: %s Bytes: %s" % (file_name, file_size)
file_size_dl = 0
block_sz = 8192
while True:
buffer = u.read(block_sz)
if not buffer:
break
file_size_dl += len(buffer)
f.write(buffer)
status = r"%10d [%3.2f%%]" % (file_size_dl, file_size_dl * 100. / file_size)
status = status + chr(8)*(len(status)+1)
print status,
f.close()
except:
print("Could not finish downloading '"+url+"':")
view_traceback()
return file_name
python_folder_path = os.path.dirname(sys.executable)
print("")
print("This script will install numpy and PIL wheels into "+python_folder_path+" on Windows. If this doesn't sound like something you should do, please press Ctrl C and terminate this script.")
os_bits="64"
print(platform.architecture()[0])
is_detected = False
if "32" in platform.architecture()[0]:
os_bits = "32"
is_detected = True
elif "64" in platform.architecture()[0]:
os_bits = "64"
is_detected = True
detected_msg = " (shown above)"
if is_detected:
detected_msg = " (detected above)"
print("")
answer = raw_input("Enter #of bits in your python architecture [blank for "+os_bits+detected_msg+"]: ")
if answer is not None:
answer = answer.strip()
if len(answer)>0:
os_bits=answer
pip_update_cmd_string=sys.executable+" -m pip install --upgrade pip wheel setuptools"
subprocess.call(pip_update_cmd_string)
downloaded_numpy_name = None
downloaded_pillow_name = None
remote_numpy_path = None
if os_bits=="32":
downloaded_numpy_name="numpy-1.10.4+mkl-cp27-cp27m-win32.whl"
downloaded_pillow_name="Pillow-3.1.1-cp27-none-win32.whl"
elif os_bits=="64":
downloaded_numpy_name="numpy-1.10.4+mkl-cp27-cp27m-win_amd64.whl"
downloaded_pillow_name="Pillow-3.1.1-cp27-none-win_amd64.whl"
remote_numpy_path = "http://www.lfd.uci.edu/~gohlke/pythonlibs/djcobkfp/"+downloaded_numpy_name
remote_pillow_path = "http://www.lfd.uci.edu/~gohlke/pythonlibs/djcobkfp/"+downloaded_pillow_name
profile_path=None
if os.path.sep=="\\":
profile_path=os.environ.get("USERPROFILE")
#elif os.path.sep=="/":
# profile_path=os.environ.get("HOME")
if profile_path is not None and os.path.isdir(profile_path):
downloads_path = os.path.join(profile_path, "Downloads")
else:
downloads_path = "."
downloaded_pillow_path = os.path.join(downloads_path, downloaded_pillow_name)
downloaded_numpy_path = os.path.join(downloads_path, downloaded_numpy_name)
download_test_enable = True
if download_test_enable:
if not os.path.isfile(downloaded_numpy_path):
web_get(remote_numpy_path, downloaded_numpy_path)
if os.path.isfile(downloaded_numpy_path):
print("Successfully downloaded '"+downloaded_numpy_path+"'")
else:
print(downloaded_pillow_path+" is present")
if not os.path.isfile(downloaded_pillow_path):
web_get(remote_pillow_path, downloaded_pillow_path)
if os.path.isfile(downloaded_pillow_path):
print("Successfully downloaded '"+downloaded_pillow_path+"'")
else:
print(downloaded_pillow_path+" is present")
python_folder_name = os.path.basename(python_folder_path)
if python_folder_name.lower()[:7]!="python3":
is_python_version_confirmed = False
if python_folder_name.lower()[:7]=="python2":
is_python_version_confirmed = True
if not is_python_version_confirmed:
confirm_string = "n"
answer = raw_input("You are running this script from '"+python_folder_path+"' which does not appear to be a python folder. Are you sure you REALLY sure you want to install Python 2 wheels and chunkymap there y/[n]? ")
if answer!=None:
answer = answer.strip()
else:
answer = ""
if answer.lower()=="y" or answer.lower()=="yes":
is_python_version_confirmed = True
else:
print("Installation of chunkymap was cancelled by the user.")
if is_python_version_confirmed:
python_Lib_path = os.path.join(python_folder_path,"Lib")
python_Lib_site_packages_path = os.path.join(python_Lib_path, "site-packages")
if os.path.isdir(python_Lib_site_packages_path):
installed_numpy_path = os.path.join(python_Lib_site_packages_path, "numpy")
if not os.path.isdir(installed_numpy_path):
#downloaded_numpy_path = os.path.join(downloads_path, downloaded_numpy_name)
install_numpy_cmd_string = sys.executable+" -m pip install \""+downloaded_numpy_path+"\""
if not os.path.isfile(downloaded_numpy_path):
print("Trying to download "+remote_numpy_path+"...")
web_get(remote_numpy_path, downloaded_numpy_path)
else:
print("Detected previously-downloaded '"+downloaded_numpy_path+"'")
if os.path.isfile(downloaded_numpy_path):
subprocess.call(install_numpy_cmd_string)
if os.path.isdir(installed_numpy_path):
print("Numpy was detected at '"+installed_numpy_path+"'")
installed_pillow_path = os.path.join(python_Lib_site_packages_path, "PIL")
if not os.path.isdir(installed_pillow_path):
#downloaded_pillow_path = os.path.join(downloads_path, downloaded_pillow_name)
install_pillow_cmd_string = sys.executable+" -m pip install \""+downloaded_pillow_path+"\""
if not os.path.isfile(downloaded_pillow_path):
print("")
print("Trying to download "+remote_pillow_path+"...")
web_get(remote_pillow_path, downloaded_pillow_path)
else:
print("Detected previously-downloaded '"+downloaded_pillow_path+"'")
if os.path.isfile(downloaded_pillow_path):
subprocess.call(install_pillow_cmd_string)
if os.path.isdir(installed_pillow_path):
downloaded_chunkymap_name="chunkymap.zip"
downloaded_chunkymap_path=os.path.join(downloads_path,downloaded_chunkymap_name)
run_py_path="chunkymap-regen.py"
remote_chunkymap_path="https://github.com/expertmm/minetest-chunkymap/archive/master.zip"
if not os.path.isfile(run_py_path):
if not os.path.isfile(downloaded_chunkymap_path):
web_get(remote_chunkymap_path,downloaded_chunkymap_path)
if os.path.isfile(downloaded_chunkymap_path):
print("Successfully downloaded "+downloaded_chunkymap_name)
else:
print("Failed to download or detect chunkymap-regen.py -- please download "+remote_chunkymap_path)
print("(You must right-click on "+downloaded_chunkymap_path+" then click Extract All, then you can run this file from that folder to redetect a compatible python and write that python to "+run_bat_path)
else:
print("Now you can run "+run_py_path+" using: ")
print(" "+sys.executable+" "+run_py_path)
run_bat_path="chunkymap-regen-loop.bat"
if os.path.isfile(run_bat_path):
os.remove(run_bat_path)
outs = open(run_bat_path, 'w')
outs.write(sys.executable+" "+run_py_path+"\n")
outs.close()
print(" OR by double-clicking")
print(" "+run_bat_path)
else:
raw_input("Cannot detect nor install "+installed_pillow_path+" so installation cannot continue. Try downloading "+downloaded_pillow_name+" to '"+downloads_path+"' then run this script again. Press enter to exit.")
else:
raw_input("Cannot detect nor install "+installed_numpy_path+" so installation cannot continue. Try downloading "+downloaded_numpy_name+" to '"+downloads_path+"' then run this script again. Press enter to exit.")
else:
raw_input("Cannot detect a site-packages folder in python installation of current python executable "+sys.executable+" so installation cannot continue. Press enter to exit.")
else:
raw_input("This installer does not know the correct wheels for python 3 (detected at "+python_folder_path+"). Please run this script with python 2 instead. Please see README.md for manual installation, but download python 3 wheels instead of the example wheels listed in README.md. Press enter to exit.")
Loading…
Cancel
Save