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 "UnitexLibIO.h"
static char unitex_docstring[] =
"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);
PyObject *unitex_get_vfs_file_list(PyObject *self, PyObject *args) {
char *filename;
if (!PyArg_ParseTuple(args, "s", &filename))
char *path;
if (!PyArg_ParseTuple(args, "s", &path))
return NULL;
char **array=GetUnitexFileList(filename);
char **array=GetUnitexFileList(path);
if (array==NULL)
return PyList_New(0);
......@@ -57,3 +58,5 @@ PyMODINIT_FUNC PyInit__unitex(void) {
return NULL;
return module;
}
......@@ -24,8 +24,7 @@ UNITEX_INC = os.path.abspath(UNITEX_INC)
class CustomBuild(build):
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")
try:
......@@ -39,14 +38,18 @@ class CustomBuild(build):
if process.returncode != 0:
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):
def run(self):
clean.run(self)
command = "cd %s && make clean" % os.path.join(UNITEX_INC, "build")
command = "cd %s && cp %s /usr/local/lib" % (os.path.join(UNITEX_INC, "bin"), library)
try:
process = subprocess.Popen(command, stderr=subprocess.PIPE, shell=True)
......@@ -59,24 +62,16 @@ class CustomClean(clean):
if process.returncode != 0:
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":
library = "libunitex.dylib"
elif sys.platform == "linux2":
library = "libunitex.so"
else:
sys.stderr.write("Plateform '%s' not supported...\n" % sys.platform)
sys.exit(1)
def run(self):
clean.run(self)
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:
process = subprocess.Popen(command, stderr=subprocess.PIPE, shell=True)
......@@ -124,12 +119,13 @@ setup(
ext_modules=[
Extension("_unitex",
include_dirs = [UNITEX_INC],
libraries=["unitex"],
library_dirs=['/usr/local/lib'],
sources = ["extensions/_unitex.c"])
],
cmdclass = {
"build": CustomBuild,
"clean": CustomClean,
"install": CustomInstall
"clean": CustomClean
}
)
......@@ -22,7 +22,7 @@ LIBUNITEX = None
if sys.platform == "darwin":
LIBUNITEX = ctypes.cdll.LoadLibrary("libunitex.dylib")
elif sys.platform == "linux2":
elif sys.platform == "linux":
LIBUNITEX = ctypes.cdll.LoadLibrary("libunitex.so")
else:
raise UnitexException("Plateform '%s' not supported..." % sys.platform)
......
......@@ -3,6 +3,7 @@
import ctypes
from _unitex import unitex_get_vfs_file_list
from unitex import UnitexException, LOGGER, LIBUNITEX
......@@ -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"))
_target_path = ctypes.c_char_p(bytes(str(target_path), "utf-8"))
......@@ -77,14 +78,14 @@ def vfs_cp(source_path, target_path):
if ret != 0:
raise UnitexException("File copy failed!")
def vfs_rm(path):
def rm(path):
_path = ctypes.c_char_p(bytes(str(path), "utf-8"))
ret = LIBUNITEX.RemoveUnitexFile(_path)
if ret != 0:
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"))
_new_path = ctypes.c_char_p(bytes(str(new_path), "utf-8"))
......@@ -92,6 +93,9 @@ def vfs_mv(old_path, new_path):
if ret != 0:
raise UnitexException("File renaming failed!")
def ls(path):
return unitex_get_vfs_file_list(path)
def mkdir(path):
_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