Merge branch 'import_help' into dtt-c-render
Conflicts: src/main.c
This commit is contained in:
@@ -29,17 +29,45 @@ import multiprocessing
|
|||||||
import time
|
import time
|
||||||
import logging
|
import logging
|
||||||
import util
|
import util
|
||||||
|
import platform
|
||||||
|
|
||||||
logging.basicConfig(level=logging.INFO,format="%(asctime)s [%(levelname)s] %(message)s")
|
logging.basicConfig(level=logging.INFO,format="%(asctime)s [%(levelname)s] %(message)s")
|
||||||
|
|
||||||
|
this_dir = util.get_program_path()
|
||||||
|
|
||||||
# make sure the c_overviewer extension is available
|
# make sure the c_overviewer extension is available
|
||||||
try:
|
try:
|
||||||
import c_overviewer
|
import c_overviewer
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
## try to find the build extension
|
||||||
|
ext = os.path.join(this_dir, "c_overviewer.%s" % ("pyd" if platform.system() == "Windows" else "so"))
|
||||||
|
if os.path.exists(ext):
|
||||||
|
print "Something has gone wrong importing the c_overviewer extension. Please"
|
||||||
|
print "make sure it is up-to-date (clean and rebuild)"
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
print "You need to compile the c_overviewer module to run Minecraft Overviewer."
|
print "You need to compile the c_overviewer module to run Minecraft Overviewer."
|
||||||
print "Run `python setup.py build`, or see the README for details."
|
print "Run `python setup.py build`, or see the README for details."
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
if hasattr(sys, "frozen"):
|
||||||
|
pass # we don't bother with a compat test since it should always be in sync
|
||||||
|
elif "extension_version" in dir(c_overviewer):
|
||||||
|
# check to make sure the binary matches the headers
|
||||||
|
if os.path.exists(os.path.join(this_dir, "src", "overviewer.h")):
|
||||||
|
with open(os.path.join(this_dir, "src", "overviewer.h")) as f:
|
||||||
|
lines = f.readlines()
|
||||||
|
lines = filter(lambda x: x.startswith("#define OVERVIEWER_EXTENSION_VERSION"), lines)
|
||||||
|
if lines:
|
||||||
|
l = lines[0]
|
||||||
|
if int(l.split()[2].strip()) != c_overviewer.extension_version():
|
||||||
|
print "Please rebuild your c_overviewer module. It is out of date!"
|
||||||
|
sys.exit(1)
|
||||||
|
else:
|
||||||
|
print "Please rebuild your c_overviewer module. It is out of date!"
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
import optimizeimages
|
import optimizeimages
|
||||||
import world
|
import world
|
||||||
import quadtree
|
import quadtree
|
||||||
|
|||||||
@@ -17,6 +17,11 @@
|
|||||||
|
|
||||||
#include "overviewer.h"
|
#include "overviewer.h"
|
||||||
|
|
||||||
|
PyObject *get_extension_version(PyObject *self, PyObject *args) {
|
||||||
|
|
||||||
|
return Py_BuildValue("i", OVERVIEWER_EXTENSION_VERSION);
|
||||||
|
}
|
||||||
|
|
||||||
static PyMethodDef COverviewerMethods[] = {
|
static PyMethodDef COverviewerMethods[] = {
|
||||||
{"alpha_over", alpha_over_wrap, METH_VARARGS,
|
{"alpha_over", alpha_over_wrap, METH_VARARGS,
|
||||||
"alpha over composite function"},
|
"alpha over composite function"},
|
||||||
@@ -26,9 +31,12 @@ static PyMethodDef COverviewerMethods[] = {
|
|||||||
"returns available render modes"},
|
"returns available render modes"},
|
||||||
{"get_render_mode_info", get_render_mode_info, METH_VARARGS,
|
{"get_render_mode_info", get_render_mode_info, METH_VARARGS,
|
||||||
"returns info for a particular render mode"},
|
"returns info for a particular render mode"},
|
||||||
|
{"extension_version", get_extension_version, METH_VARARGS,
|
||||||
|
"Returns the extension version"},
|
||||||
{NULL, NULL, 0, NULL} /* Sentinel */
|
{NULL, NULL, 0, NULL} /* Sentinel */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
PyMODINIT_FUNC
|
PyMODINIT_FUNC
|
||||||
initc_overviewer(void)
|
initc_overviewer(void)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -24,6 +24,10 @@
|
|||||||
#ifndef __OVERVIEWER_H_INCLUDED__
|
#ifndef __OVERVIEWER_H_INCLUDED__
|
||||||
#define __OVERVIEWER_H_INCLUDED__
|
#define __OVERVIEWER_H_INCLUDED__
|
||||||
|
|
||||||
|
// increment this value if you've made a change to the c extesion
|
||||||
|
// and want to force users to rebuild
|
||||||
|
#define OVERVIEWER_EXTENSION_VERSION 2
|
||||||
|
|
||||||
/* Python PIL, and numpy headers */
|
/* Python PIL, and numpy headers */
|
||||||
#include <Python.h>
|
#include <Python.h>
|
||||||
#include <Imaging.h>
|
#include <Imaging.h>
|
||||||
|
|||||||
9
util.py
9
util.py
@@ -34,11 +34,14 @@ def get_program_path():
|
|||||||
|
|
||||||
|
|
||||||
def findGitVersion():
|
def findGitVersion():
|
||||||
if os.path.exists(".git"):
|
this_dir = get_program_path()
|
||||||
with open(os.path.join(".git","HEAD")) as f:
|
if os.path.exists(os.path.join(this_dir,".git")):
|
||||||
|
with open(os.path.join(this_dir,".git","HEAD")) as f:
|
||||||
data = f.read().strip()
|
data = f.read().strip()
|
||||||
if data.startswith("ref: "):
|
if data.startswith("ref: "):
|
||||||
with open(os.path.join(".git", data[5:])) as g:
|
if not os.path.exists(os.path.join(this_dir,data[5:])):
|
||||||
|
return data
|
||||||
|
with open(os.path.join(this_dir, ".git", data[5:])) as g:
|
||||||
return g.read().strip()
|
return g.read().strip()
|
||||||
else:
|
else:
|
||||||
return data
|
return data
|
||||||
|
|||||||
Reference in New Issue
Block a user