From 24fcdb395fbd9769a33093e09a68b2339de66ed6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Graber?= Date: Mon, 11 Mar 2013 11:57:50 -0400 Subject: [PATCH] python: Don't hardcode LXCPATH in python module MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Stéphane Graber Acked-by: Serge E. Hallyn --- .gitignore | 1 - configure.ac | 1 - src/python-lxc/lxc.c | 14 +++++++++++++- src/python-lxc/lxc/{__init__.py.in => __init__.py} | 3 +-- 4 files changed, 14 insertions(+), 5 deletions(-) rename src/python-lxc/lxc/{__init__.py.in => __init__.py} (99%) diff --git a/.gitignore b/.gitignore index bef5cd1d1..26c97c810 100644 --- a/.gitignore +++ b/.gitignore @@ -66,7 +66,6 @@ src/lxc/lxc-wait src/lxc/legacy/lxc-ls src/python-lxc/build/ -src/python-lxc/lxc/__init__.py src/python-lxc/lxc/__pycache__/ src/tests/lxc-test-containertests diff --git a/configure.ac b/configure.ac index 792aae860..9afb14824 100644 --- a/configure.ac +++ b/configure.ac @@ -383,7 +383,6 @@ AC_CONFIG_FILES([ src/lxc/lxc.functions src/python-lxc/Makefile - src/python-lxc/lxc/__init__.py src/lua-lxc/Makefile diff --git a/src/python-lxc/lxc.c b/src/python-lxc/lxc.c index 2abdc4cc0..8fd0a7892 100644 --- a/src/python-lxc/lxc.c +++ b/src/python-lxc/lxc.c @@ -95,6 +95,12 @@ Container_init(Container *self, PyObject *args, PyObject *kwds) return 0; } +static PyObject * +get_default_config_path(Container *self, PyObject *args, PyObject *kwds) +{ + return PyUnicode_FromString(lxc_get_default_config_path()); +} + // Container properties static PyObject * Container_config_file_name(Container *self, PyObject *args, PyObject *kwds) @@ -628,12 +634,18 @@ PyVarObject_HEAD_INIT(NULL, 0) Container_new, /* tp_new */ }; +static PyMethodDef LXC_methods[] = { + {"get_default_config_path", (PyCFunction)get_default_config_path, METH_NOARGS, + "Returns the current LXC config path"}, + {NULL, NULL, 0, NULL} +}; + static PyModuleDef _lxcmodule = { PyModuleDef_HEAD_INIT, "_lxc", "Binding for liblxc in python", -1, - NULL, NULL, NULL, NULL, NULL + LXC_methods }; PyMODINIT_FUNC diff --git a/src/python-lxc/lxc/__init__.py.in b/src/python-lxc/lxc/__init__.py similarity index 99% rename from src/python-lxc/lxc/__init__.py.in rename to src/python-lxc/lxc/__init__.py index f1848f24a..828a1cb32 100644 --- a/src/python-lxc/lxc/__init__.py.in +++ b/src/python-lxc/lxc/__init__.py @@ -26,14 +26,13 @@ import glob import os import subprocess import stat -import tempfile import time import warnings warnings.warn("The python-lxc API isn't yet stable " "and may change at any point in the future.", Warning, 2) -default_config_path = "@LXCPATH@" +default_config_path = _lxc.get_default_config_path() class ContainerNetwork():