From mboxrd@z Thu Jan 1 00:00:00 1970 From: Juergen Gross Subject: Re: No sxputils module for xm command Date: Mon, 26 Apr 2010 07:26:25 +0200 Message-ID: <4BD52401.5020604@ts.fujitsu.com> References: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------050908070704030600050408" Return-path: In-Reply-To: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: "Xu, Jiajun" Cc: "xen-devel@lists.xensource.com" , Keir Fraser List-Id: xen-devel@lists.xenproject.org This is a multi-part message in MIME format. --------------050908070704030600050408 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit On 04/23/2010 05:49 PM, Xu, Jiajun wrote: > Hi, > I found with latest xen, 'xm' command returns fail with following error: > > [root@vt-dp6 ~]# xm list > Traceback (most recent call last): > File "/usr/sbin/xm", line 5, in ? > from xen.xm import main > File "/usr/lib/python2.4/site-packages/xen/xm/main.py", line 59, in ? > from xen.util.sxputils import sxp2map, map2sxp as map_to_sxp > ImportError: No module named sxputils > > Could anyone help on this? > Thanks a lot. Sorry, the attched patch should correct that. The module slipped through my cpupool patch (no hg add). Now I've deleted all xen python modules on my test machine before doing a new install. Seems to work now... Juergen -- Juergen Gross Principal Developer Operating Systems TSP ES&S SWE OS6 Telephone: +49 (0) 89 3222 2967 Fujitsu Technology Solutions e-mail: juergen.gross@ts.fujitsu.com Domagkstr. 28 Internet: ts.fujitsu.com D-80807 Muenchen Company details: ts.fujitsu.com/imprint.html --------------050908070704030600050408 Content-Type: text/x-patch; name="sxputils.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="sxputils.patch" Signed-off-by: juergen.gross@ts.fujitsu.com diff -r c87ec146229a tools/python/xen/util/sxputils.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/python/xen/util/sxputils.py Mon Apr 26 07:14:28 2010 +0200 @@ -0,0 +1,64 @@ +#============================================================================ +# This library is free software; you can redistribute it and/or +# modify it under the terms of version 2.1 of the GNU Lesser General Public +# License as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +#============================================================================ +# Copyright (c) 2009 Fujitsu Technology Solutions +#============================================================================ + +""" convert sxp to map / map to sxp. +""" + +import types +from xen.xend import sxp + +def map2sxp(map_val): + """ conversion of all key-value pairs of a map (recursively) to sxp. + @param map_val: map; if a value contains a list or dict it is also + converted to sxp + @type map_val: dict + @return sxp expr + @rtype: list + """ + sxp_vals = [] + for (k, v) in map_val.items(): + if isinstance(v, types.DictionaryType): + sxp_vals += [[k] + map2sxp(v)] + elif isinstance(v, types.ListType): + sxp_vals += [[k] + v] + else: + sxp_vals += [[k, v]] + return sxp_vals + +def sxp2map( s ): + """ conversion of sxp to map. + @param s: sxp expr + @type s: list + @return: map + @rtype: dict + """ + sxphash = {} + + for child in sxp.children( s ): + if isinstance( child, types.ListType ) and len( child ) > 1: + if isinstance( child[1], types.ListType ) and len( child[1] ) > 1: + sxphash[ child[0] ] = sxp2map( child ) + else: + childs = sxp.children(child) + if len(childs) > 1: + sxphash[ child[0] ] = childs + else: + sxphash[ child[0] ] = childs[0] + + return sxphash + + --------------050908070704030600050408 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --------------050908070704030600050408--