Skip to content
Extraits de code Groupes Projets
Valider 04d6ca3a rédigé par Patrick Watrin's avatar Patrick Watrin
Parcourir les fichiers

Pre-install Unitex library to allow _unitex extension linking.

parent b1e85b9b
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
#include <Python.h> #include <Python.h>
#include "UnitexLibIO.h" #include "UnitexLibIO.h"
static char unitex_docstring[] = static char unitex_docstring[] =
"This module provides some usefull C function to work with the Unitex library."; "This module provides some usefull C function to work with the Unitex library.";
static char unitex_get_vfs_file_list_docstring[] =
"This function converts a C array of string (char**) into a Python list.";
static char unitex_get_vfs_file_list_docstring[] =
"This function list (disk or virtual) directory contents.";
static PyObject *unitex_get_vfs_file_list(PyObject *self, PyObject *args); static PyObject *unitex_get_vfs_file_list(PyObject *self, PyObject *args);
PyObject *unitex_get_vfs_file_list(PyObject *self, PyObject *args) { PyObject *unitex_get_vfs_file_list(PyObject *self, PyObject *args) {
char *filename; char *path;
if (!PyArg_ParseTuple(args, "s", &filename)) if (!PyArg_ParseTuple(args, "s", &path))
return NULL; return NULL;
char **array=GetUnitexFileList(filename); char **array=GetUnitexFileList(path);
if (array==NULL) if (array==NULL)
return PyList_New(0); return PyList_New(0);
...@@ -57,3 +58,5 @@ PyMODINIT_FUNC PyInit__unitex(void) { ...@@ -57,3 +58,5 @@ PyMODINIT_FUNC PyInit__unitex(void) {
return NULL; return NULL;
return module; return module;
} }
...@@ -24,8 +24,7 @@ UNITEX_INC = os.path.abspath(UNITEX_INC) ...@@ -24,8 +24,7 @@ UNITEX_INC = os.path.abspath(UNITEX_INC)
class CustomBuild(build): class CustomBuild(build):
def run(self): def run(self):
build.run(self) # Unitex library compilation.
command = "cd %s && make 64BITS=yes LIBRARY=yes TRE_DIRECT_COMPILE=yes DEBUG=yes" % os.path.join(UNITEX_INC, "build") command = "cd %s && make 64BITS=yes LIBRARY=yes TRE_DIRECT_COMPILE=yes DEBUG=yes" % os.path.join(UNITEX_INC, "build")
try: try:
...@@ -39,14 +38,18 @@ class CustomBuild(build): ...@@ -39,14 +38,18 @@ class CustomBuild(build):
if process.returncode != 0: if process.returncode != 0:
raise OSError(process.stderr.read()) raise OSError(process.stderr.read())
# Unitex library installation (needed by _unitex C extension).
library = None
if sys.platform == "darwin":
library = "libunitex.dylib"
elif sys.platform == "linux":
library = "libunitex.so"
else:
sys.stderr.write("Plateform '%s' not supported...\n" % sys.platform)
sys.exit(1)
class CustomClean(clean): command = "cd %s && cp %s /usr/local/lib" % (os.path.join(UNITEX_INC, "bin"), library)
def run(self):
clean.run(self)
command = "cd %s && make clean" % os.path.join(UNITEX_INC, "build")
try: try:
process = subprocess.Popen(command, stderr=subprocess.PIPE, shell=True) process = subprocess.Popen(command, stderr=subprocess.PIPE, shell=True)
...@@ -59,24 +62,16 @@ class CustomClean(clean): ...@@ -59,24 +62,16 @@ class CustomClean(clean):
if process.returncode != 0: if process.returncode != 0:
raise OSError(process.stderr.read()) raise OSError(process.stderr.read())
build.run(self)
class CustomInstall(install):
def run(self):
install.run(self)
library = None class CustomClean(clean):
if sys.platform == "darwin": def run(self):
library = "libunitex.dylib" clean.run(self)
elif sys.platform == "linux2":
library = "libunitex.so"
else:
sys.stderr.write("Plateform '%s' not supported...\n" % sys.platform)
sys.exit(1)
command = "cd %s && cp %s /usr/local/lib" % (os.path.join(UNITEX_INC, "bin"), library) command = "cd %s && make clean" % os.path.join(UNITEX_INC, "build")
try: try:
process = subprocess.Popen(command, stderr=subprocess.PIPE, shell=True) process = subprocess.Popen(command, stderr=subprocess.PIPE, shell=True)
...@@ -124,12 +119,13 @@ setup( ...@@ -124,12 +119,13 @@ setup(
ext_modules=[ ext_modules=[
Extension("_unitex", Extension("_unitex",
include_dirs = [UNITEX_INC], include_dirs = [UNITEX_INC],
libraries=["unitex"],
library_dirs=['/usr/local/lib'],
sources = ["extensions/_unitex.c"]) sources = ["extensions/_unitex.c"])
], ],
cmdclass = { cmdclass = {
"build": CustomBuild, "build": CustomBuild,
"clean": CustomClean, "clean": CustomClean
"install": CustomInstall
} }
) )
...@@ -22,7 +22,7 @@ LIBUNITEX = None ...@@ -22,7 +22,7 @@ LIBUNITEX = None
if sys.platform == "darwin": if sys.platform == "darwin":
LIBUNITEX = ctypes.cdll.LoadLibrary("libunitex.dylib") LIBUNITEX = ctypes.cdll.LoadLibrary("libunitex.dylib")
elif sys.platform == "linux2": elif sys.platform == "linux":
LIBUNITEX = ctypes.cdll.LoadLibrary("libunitex.so") LIBUNITEX = ctypes.cdll.LoadLibrary("libunitex.so")
else: else:
raise UnitexException("Plateform '%s' not supported..." % sys.platform) raise UnitexException("Plateform '%s' not supported..." % sys.platform)
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
import ctypes import ctypes
from _unitex import unitex_get_vfs_file_list
from unitex import UnitexException, LOGGER, LIBUNITEX from unitex import UnitexException, LOGGER, LIBUNITEX
...@@ -69,7 +70,7 @@ class UnitexIOConstants: ...@@ -69,7 +70,7 @@ class UnitexIOConstants:
def vfs_cp(source_path, target_path): def cp(source_path, target_path):
_source_path = ctypes.c_char_p(bytes(str(source_path), "utf-8")) _source_path = ctypes.c_char_p(bytes(str(source_path), "utf-8"))
_target_path = ctypes.c_char_p(bytes(str(target_path), "utf-8")) _target_path = ctypes.c_char_p(bytes(str(target_path), "utf-8"))
...@@ -77,14 +78,14 @@ def vfs_cp(source_path, target_path): ...@@ -77,14 +78,14 @@ def vfs_cp(source_path, target_path):
if ret != 0: if ret != 0:
raise UnitexException("File copy failed!") raise UnitexException("File copy failed!")
def vfs_rm(path): def rm(path):
_path = ctypes.c_char_p(bytes(str(path), "utf-8")) _path = ctypes.c_char_p(bytes(str(path), "utf-8"))
ret = LIBUNITEX.RemoveUnitexFile(_path) ret = LIBUNITEX.RemoveUnitexFile(_path)
if ret != 0: if ret != 0:
raise UnitexException("File suppression failed!") raise UnitexException("File suppression failed!")
def vfs_mv(old_path, new_path): def mv(old_path, new_path):
_old_path = ctypes.c_char_p(bytes(str(old_path), "utf-8")) _old_path = ctypes.c_char_p(bytes(str(old_path), "utf-8"))
_new_path = ctypes.c_char_p(bytes(str(new_path), "utf-8")) _new_path = ctypes.c_char_p(bytes(str(new_path), "utf-8"))
...@@ -92,6 +93,9 @@ def vfs_mv(old_path, new_path): ...@@ -92,6 +93,9 @@ def vfs_mv(old_path, new_path):
if ret != 0: if ret != 0:
raise UnitexException("File renaming failed!") raise UnitexException("File renaming failed!")
def ls(path):
return unitex_get_vfs_file_list(path)
def mkdir(path): def mkdir(path):
_path = ctypes.c_char_p(bytes(str(path), "utf-8")) _path = ctypes.c_char_p(bytes(str(path), "utf-8"))
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter