From 3c9ac77581d68238c3a645d50214f8f8b7915df7 Mon Sep 17 00:00:00 2001 From: sami Date: Thu, 29 Apr 2010 23:59:47 +0300 Subject: [PATCH] fixes for the python stuff --- dfhack/python/build-linux | 4 ++++ dfhack/python/linsetup.py | 11 ++++++----- dfhack/python/pydfapi.py | 41 +++++++++++++++++++++++---------------- dfhack/python/test.py | 9 ++++++++- 4 files changed, 42 insertions(+), 23 deletions(-) create mode 100755 dfhack/python/build-linux diff --git a/dfhack/python/build-linux b/dfhack/python/build-linux new file mode 100755 index 000000000..43145b5aa --- /dev/null +++ b/dfhack/python/build-linux @@ -0,0 +1,4 @@ +#!/bin/bash +python linsetup.py build_ext +cp build/lib.linux-i686-2.6/pydfhack.so . +rm -r build diff --git a/dfhack/python/linsetup.py b/dfhack/python/linsetup.py index 356300304..d29ae9103 100644 --- a/dfhack/python/linsetup.py +++ b/dfhack/python/linsetup.py @@ -1,12 +1,13 @@ # -*- coding: utf-8 -*- from distutils.core import setup, Extension +from os import path e = Extension("pydfhack", sources=["DF_API.cpp", "DF_Buildings.cpp", "DF_Constructions.cpp", "DF_CreatureManager.cpp", "DF_GUI.cpp", "DF_Maps.cpp", "DF_Material.cpp", "DF_Position.cpp", "DF_Translate.cpp", "DF_Vegetation.cpp", "pydfhack.cpp"], - include_dirs=["../", "../include", "../depends/md5", "../depends/tinyxml"], - library_dirs=["../../output"], - extra_compile_args=["-DLINUX_BUILD"], - libraries=["dfhack-debug"], - export_symbols=["initpydfhack", "ReadRaw", "WriteRaw"]) + include_dirs=["../", path.join("..", "include"), path.join("..","depends","md5"), path.join("..","depends","tinyxml")], + library_dirs=[path.join("..","..","output")], + extra_compile_args=["-DLINUX_BUILD", "-w"], + libraries=["dfhack"], + export_symbols=["initpydfhack", "ReadRaw", "WriteRaw"]) setup(name="PyDFHack", version="1.0", ext_modules=[e]) diff --git a/dfhack/python/pydfapi.py b/dfhack/python/pydfapi.py index 76aea332c..0cb4c5be3 100644 --- a/dfhack/python/pydfapi.py +++ b/dfhack/python/pydfapi.py @@ -1,21 +1,28 @@ -from pydfhack import * +import pydfhack, os -class API(_API): - def __init__(self, *args, **kwds): - _API.__init__(self, args, kwds) - - self._map_mgr_type = Map - self._vegetation_mgr_type = Vegetation - self._gui_mgr_type = GUI +class API(pydfhack._API): + for file in ["Memory.xml", os.path.join("..","..","output","Memory.xml")]: + if os.path.isfile(file): + datafile = file + break + else: + raise ImportError, "Memory.xml not found." + + def __init__(self, *args, **kwds): + pydfhack._API.__init__(self, API.datafile) + + self._map_mgr_type = Map + self._vegetation_mgr_type = Vegetation + self._gui_mgr_type = GUI -class Map(_MapManager): - def __init__(self, *args, **kwds): - _MapManager.__init__(self, args, kwds) +class Map(pydfhack._MapManager): + def __init__(self, *args, **kwds): + pydfhack._MapManager.__init__(self, args, kwds) -class Vegetation(_VegetationManager): - def __init__(self, *args, **kwds): - _VegetationManager.__init__(self, args, kwds) +class Vegetation(pydfhack._VegetationManager): + def __init__(self, *args, **kwds): + pydfhack._VegetationManager.__init__(self, args, kwds) -class GUI(_GUIManager): - def __init__(self, *args, **kwds): - _GUIManager.__init__(self, args, kwds) \ No newline at end of file +class GUI(pydfhack._GUIManager): + def __init__(self, *args, **kwds): + pydfhack._GUIManager.__init__(self, args, kwds) diff --git a/dfhack/python/test.py b/dfhack/python/test.py index 802c64b2b..558fb38c4 100644 --- a/dfhack/python/test.py +++ b/dfhack/python/test.py @@ -1,2 +1,9 @@ # -*- coding: utf-8 -*- -import pydfhack +import pydfapi + +print "Attempting to initialize pydfhack...", +DF = pydfapi.API() +Map = pydfapi.Map() +Vegetation = pydfapi.Vegetation() +GUI = pydfapi.GUI() +print "OK"