Mailing List Archive

[PATCH V7 2/7] libxl: Add get/set_default_namespace in libxltypes.py.
Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
---
tools/libxl/libxl_types.idl | 2 ++
tools/libxl/libxltypes.py | 16 ++++++++++++++--
2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/tools/libxl/libxl_types.idl b/tools/libxl/libxl_types.idl
index f7249b1..718688d 100644
--- a/tools/libxl/libxl_types.idl
+++ b/tools/libxl/libxl_types.idl
@@ -3,6 +3,8 @@
# Builtin libxl types
#

+set_default_namespace("libxl_")
+
libxl_domid = Builtin("domid")
libxl_uuid = Builtin("uuid", passby=PASS_BY_REFERENCE)
libxl_mac = Builtin("mac", passby=PASS_BY_REFERENCE)
diff --git a/tools/libxl/libxltypes.py b/tools/libxl/libxltypes.py
index b7b4669..64d2f50 100644
--- a/tools/libxl/libxltypes.py
+++ b/tools/libxl/libxltypes.py
@@ -8,10 +8,21 @@ DIR_IN = 1
DIR_OUT = 2
DIR_BOTH = 3

+default_namespace = ""
+def set_default_namespace(s):
+ if type(s) != str:
+ raise TypeError, "Require a string for the default namespace."
+ global default_namespace
+ default_namespace = s
+
+def get_default_namespace():
+ global default_namespace
+ return default_namespace
+
class Type(object):
def __init__(self, typename, **kwargs):
self.comment = kwargs.setdefault('comment', None)
- self.namespace = kwargs.setdefault('namespace', "libxl_")
+ self.namespace = kwargs.setdefault('namespace', get_default_namespace())
self.dir = kwargs.setdefault('dir', DIR_BOTH)
if self.dir not in [DIR_NONE, DIR_IN, DIR_OUT, DIR_BOTH]:
raise ValueError
@@ -248,7 +259,8 @@ def parse(f):
elif isinstance(t,type(object)) and issubclass(t, Type):
globs[n] = t
elif n in ['PASS_BY_REFERENCE', 'PASS_BY_VALUE',
- 'DIR_NONE', 'DIR_IN', 'DIR_OUT', 'DIR_BOTH']:
+ 'DIR_NONE', 'DIR_IN', 'DIR_OUT', 'DIR_BOTH',
+ 'set_default_namespace']:
globs[n] = t

try:
--
Anthony PERARD


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel
Re: [PATCH V7 2/7] libxl: Add get/set_default_namespace in libxltypes.py. [ In reply to ]
On Wed, 2011-07-20 at 22:24 +0100, Anthony PERARD wrote:
> Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>

I'm not sure if it matters but default_namespace should possibly be
private to the module (__ at the start)? Perhaps get_default_namesspace
too, probably neither .idl files nor gen*.py should ever need to query
this, they should use the info in specific types.

If I were prone to bikeshedding I'd suggest that "set_default_namespace"
could be just "namespace" since it would read nicer in the .idl files.

In any case that's all nit picking so:

Acked-by: Ian Campbell <ian.campbell@citrix.com>

> ---
> tools/libxl/libxl_types.idl | 2 ++
> tools/libxl/libxltypes.py | 16 ++++++++++++++--
> 2 files changed, 16 insertions(+), 2 deletions(-)
>
> diff --git a/tools/libxl/libxl_types.idl b/tools/libxl/libxl_types.idl
> index f7249b1..718688d 100644
> --- a/tools/libxl/libxl_types.idl
> +++ b/tools/libxl/libxl_types.idl
> @@ -3,6 +3,8 @@
> # Builtin libxl types
> #
>
> +set_default_namespace("libxl_")
> +
> libxl_domid = Builtin("domid")
> libxl_uuid = Builtin("uuid", passby=PASS_BY_REFERENCE)
> libxl_mac = Builtin("mac", passby=PASS_BY_REFERENCE)
> diff --git a/tools/libxl/libxltypes.py b/tools/libxl/libxltypes.py
> index b7b4669..64d2f50 100644
> --- a/tools/libxl/libxltypes.py
> +++ b/tools/libxl/libxltypes.py
> @@ -8,10 +8,21 @@ DIR_IN = 1
> DIR_OUT = 2
> DIR_BOTH = 3
>
> +default_namespace = ""
> +def set_default_namespace(s):
> + if type(s) != str:
> + raise TypeError, "Require a string for the default namespace."
> + global default_namespace
> + default_namespace = s
> +
> +def get_default_namespace():
> + global default_namespace
> + return default_namespace
> +
> class Type(object):
> def __init__(self, typename, **kwargs):
> self.comment = kwargs.setdefault('comment', None)
> - self.namespace = kwargs.setdefault('namespace', "libxl_")
> + self.namespace = kwargs.setdefault('namespace', get_default_namespace())
> self.dir = kwargs.setdefault('dir', DIR_BOTH)
> if self.dir not in [DIR_NONE, DIR_IN, DIR_OUT, DIR_BOTH]:
> raise ValueError
> @@ -248,7 +259,8 @@ def parse(f):
> elif isinstance(t,type(object)) and issubclass(t, Type):
> globs[n] = t
> elif n in ['PASS_BY_REFERENCE', 'PASS_BY_VALUE',
> - 'DIR_NONE', 'DIR_IN', 'DIR_OUT', 'DIR_BOTH']:
> + 'DIR_NONE', 'DIR_IN', 'DIR_OUT', 'DIR_BOTH',
> + 'set_default_namespace']:
> globs[n] = t
>
> try:



_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel
Re: [PATCH V7 2/7] libxl: Add get/set_default_namespace in libxltypes.py. [ In reply to ]
On Thu, 21 Jul 2011, Ian Campbell wrote:

> On Wed, 2011-07-20 at 22:24 +0100, Anthony PERARD wrote:
> > Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
>
> I'm not sure if it matters but default_namespace should possibly be
> private to the module (__ at the start)? Perhaps get_default_namesspace
> too, probably neither .idl files nor gen*.py should ever need to query
> this, they should use the info in specific types.

Ok, I will change names but use only one '_' for "private"
function/variable.

> If I were prone to bikeshedding I'd suggest that "set_default_namespace"
> could be just "namespace" since it would read nicer in the .idl files.

:), I'll change that too.

> In any case that's all nit picking so:
>
> Acked-by: Ian Campbell <ian.campbell@citrix.com>

Thanks,

--
Anthony PERARD

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel
Re: [PATCH V7 2/7] libxl: Add get/set_default_namespace in libxltypes.py. [ In reply to ]
On Wed, 2011-07-20 at 17:24 -0400, Anthony PERARD wrote:
> Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
> ---
> tools/libxl/libxl_types.idl | 2 ++
> tools/libxl/libxltypes.py | 16 ++++++++++++++--
> 2 files changed, 16 insertions(+), 2 deletions(-)
>
> diff --git a/tools/libxl/libxl_types.idl b/tools/libxl/libxl_types.idl
> index f7249b1..718688d 100644
> --- a/tools/libxl/libxl_types.idl
> +++ b/tools/libxl/libxl_types.idl
> @@ -3,6 +3,8 @@
> # Builtin libxl types
> #
>
> +set_default_namespace("libxl_")
> +
> libxl_domid = Builtin("domid")
> libxl_uuid = Builtin("uuid", passby=PASS_BY_REFERENCE)
> libxl_mac = Builtin("mac", passby=PASS_BY_REFERENCE)
> diff --git a/tools/libxl/libxltypes.py b/tools/libxl/libxltypes.py
> index b7b4669..64d2f50 100644
> --- a/tools/libxl/libxltypes.py
> +++ b/tools/libxl/libxltypes.py
> @@ -8,10 +8,21 @@ DIR_IN = 1
> DIR_OUT = 2
> DIR_BOTH = 3
>
> +default_namespace = ""
> +def set_default_namespace(s):
> + if type(s) != str:
> + raise TypeError, "Require a string for the default namespace."
> + global default_namespace
> + default_namespace = s
> +
> +def get_default_namespace():
> + global default_namespace
> + return default_namespace

Can you make this 4-space indent please. The rest of this file is
indented that way but this comes first so emacs' python-guess-indent
guesses 2 and that confuses the autoindent of the following code.

Ian.

> +
> class Type(object):
> def __init__(self, typename, **kwargs):
> self.comment = kwargs.setdefault('comment', None)
> - self.namespace = kwargs.setdefault('namespace', "libxl_")
> + self.namespace = kwargs.setdefault('namespace', get_default_namespace())
> self.dir = kwargs.setdefault('dir', DIR_BOTH)
> if self.dir not in [DIR_NONE, DIR_IN, DIR_OUT, DIR_BOTH]:
> raise ValueError
> @@ -248,7 +259,8 @@ def parse(f):
> elif isinstance(t,type(object)) and issubclass(t, Type):
> globs[n] = t
> elif n in ['PASS_BY_REFERENCE', 'PASS_BY_VALUE',
> - 'DIR_NONE', 'DIR_IN', 'DIR_OUT', 'DIR_BOTH']:
> + 'DIR_NONE', 'DIR_IN', 'DIR_OUT', 'DIR_BOTH',
> + 'set_default_namespace']:
> globs[n] = t
>
> try:



_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel