<html>
<head>
<meta content="text/html; charset=GB2312" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix">On 12/18/2013 05:12 AM, Royce Lv wrote:<br>
</div>
<blockquote cite="mid:52B14AC8.8080702@linux.vnet.ibm.com"
type="cite">
<meta content="text/html; charset=GB2312"
http-equiv="Content-Type">
<div class="moz-cite-prefix">On 2013年12月18日 14:40, Sheldon wrote:<br>
</div>
<blockquote cite="mid:52B14364.8070308@linux.vnet.ibm.com"
type="cite">
<meta content="text/html; charset=GB2312"
http-equiv="Content-Type">
<div id="smartTemplate4-quoteHeader">Reviewed-by: ShaoHe Feng <a
moz-do-not-send="true" class="moz-txt-link-rfc2396E"
href="mailto:shaohef@linux.vnet.ibm.com"><shaohef@linux.vnet.ibm.com></a><br>
</div>
<div class="moz-cite-prefix">On 12/18/2013 02:31 PM, Royce Lv
wrote:<br>
</div>
<blockquote cite="mid:52B1415F.1050902@linux.vnet.ibm.com"
type="cite">On 2013年12月17日 20:50, Ramon Medeiros wrote: <br>
<blockquote type="cite">On 12/17/2013 10:10 AM, <a
moz-do-not-send="true" class="moz-txt-link-abbreviated"
href="mailto:lvroyce0210@gmail.com">lvroyce0210@gmail.com</a>
wrote: <br>
<blockquote type="cite">From: Royce Lv <a
moz-do-not-send="true" class="moz-txt-link-rfc2396E"
href="mailto:lvroyce@linux.vnet.ibm.com"><lvroyce@linux.vnet.ibm.com></a>
<br>
<br>
Abstract a helper function to parse cmd result. <br>
Usage: <br>
(1)get cmd result with subprocess.call or subprocess.Popen
<br>
(2) call pass_cmd_output to get formated outputs <br>
Example: <br>
blkid = subprocess.Popen(["cat", "/proc/mounts"], <br>
stdout=subprocess.PIPE, stderr=subprocess.PIPE) <br>
outs = blkid.communicate()[0] <br>
output_items= ['path', 'mnt_point', 'type', 'option'] <br>
utils.pass_cmd_output(outs, output_items) <br>
Sample output: <br>
[{'path': '/dev/sda8', 'type': 'ext4', <br>
'option': 'rw,relatime,data=ordered', 'mnt_point':
'/home'}, <br>
{'path': 'localhost:/home/royce/isorepo', 'type': 'nfs4',
<br>
'option': 'rw...addr=127.0.0.1', 'mnt_point': '/mnt'}] <br>
<br>
Signed-off-by: Royce Lv <a moz-do-not-send="true"
class="moz-txt-link-rfc2396E"
href="mailto:lvroyce@linux.vnet.ibm.com"><lvroyce@linux.vnet.ibm.com></a>
<br>
--- <br>
src/kimchi/utils.py | 7 +++++++ <br>
1 file changed, 7 insertions(+) <br>
<br>
diff --git a/src/kimchi/utils.py b/src/kimchi/utils.py <br>
index f7eda93..1890a28 100644 <br>
--- a/src/kimchi/utils.py <br>
+++ b/src/kimchi/utils.py <br>
@@ -84,3 +84,10 @@ def import_class(class_path): <br>
<br>
def import_module(module_name): <br>
return __import__(module_name, fromlist=['']) <br>
+ <br>
+def parse_cmd_output(output, output_items): <br>
+ res = [] <br>
+ for line in output.split("\n"): <br>
</blockquote>
can you get the Popen result and use readlines, to get a
array with the lines, instead of striping it? <br>
</blockquote>
Hi Ramon, <br>
<br>
Thanks for your review, I think for file read result it is OK,
but seems for popen.communicate just pull out the raw output ,
and only stdout provide readlines interface, which official
doc does not recommend because of deadlock problem. (<a
moz-do-not-send="true" class="moz-txt-link-freetext"
href="http://docs.python.org/3.3/library/subprocess.html#subprocess.Popen.communicate">http://docs.python.org/3.3/library/subprocess.html#subprocess.Popen.communicate</a>).<br>
</blockquote>
I think Ramon want:<br>
<pre wrap="">+ with open("/proc/mounts" , "rb") as f:
+ res = []
+ for output in f.readlines():
+ res.append(dict(zip(['dev_path', 'mnt_point', 'type'], output.split()))
+ return res
</pre>
</blockquote>
</blockquote>
yes, this was my wish!<br>
<blockquote cite="mid:52B14AC8.8080702@linux.vnet.ibm.com"
type="cite">
<blockquote cite="mid:52B14364.8070308@linux.vnet.ibm.com"
type="cite">
<pre wrap="">
</pre>
maybe you want a common function to parse both the output from
stdout and files. <br>
<br>
blkid = subprocess.Popen(["cat", "/proc/mounts"],<br>
</blockquote>
True, I want a helper function that all command can use to get a
structural result.<br>
So that in the future if we want to get iscsi session, or other
things , we can reuse this function. <br>
</blockquote>
ok<br>
<br>
<blockquote cite="mid:52B14AC8.8080702@linux.vnet.ibm.com"
type="cite">
<blockquote cite="mid:52B14364.8070308@linux.vnet.ibm.com"
type="cite">
<blockquote cite="mid:52B1415F.1050902@linux.vnet.ibm.com"
type="cite"> <br>
<blockquote type="cite">
<blockquote type="cite">+ res.append(dict(zip(output_items,
line.split()))) <br>
+ <br>
+ return res <br>
</blockquote>
<br>
<br>
</blockquote>
<br>
</blockquote>
<br>
<br>
<div id="smartTemplate4-template"> </div>
<div class="moz-signature">
<pre>Sheldon Feng(冯少合)<shaohef@linux.vnet.ibm.com>
IBM Linux Technology Center</shaohef@linux.vnet.ibm.com></pre>
</div>
-- <br>
project-kimchi mailing list <a moz-do-not-send="true"
class="moz-txt-link-rfc2396E"
href="mailto:project-kimchi@googlegroups.com"><project-kimchi@googlegroups.com></a><br>
<a moz-do-not-send="true"
href="https://groups.google.com/forum/#%21forum/project-kimchi">https://groups.google.com/forum/#!forum/project-kimchi</a><br>
--- <br>
You received this message because you are subscribed to the
Google Groups "project-kimchi" group.<br>
To unsubscribe from this group and stop receiving emails from
it, send an email to <a moz-do-not-send="true"
class="moz-txt-link-abbreviated"
href="mailto:project-kimchi+unsubscribe@googlegroups.com">project-kimchi+unsubscribe@googlegroups.com</a>.<br>
For more options, visit <a moz-do-not-send="true"
href="https://groups.google.com/groups/opt_out">https://groups.google.com/groups/opt_out</a>.<br>
</blockquote>
<br>
-- <br>
project-kimchi mailing list
<a class="moz-txt-link-rfc2396E" href="mailto:project-kimchi@googlegroups.com"><project-kimchi@googlegroups.com></a><br>
<a moz-do-not-send="true"
href="https://groups.google.com/forum/#%21forum/project-kimchi">https://groups.google.com/forum/#!forum/project-kimchi</a><br>
--- <br>
You received this message because you are subscribed to the Google
Groups "project-kimchi" group.<br>
To unsubscribe from this group and stop receiving emails from it,
send an email to <a class="moz-txt-link-abbreviated" href="mailto:project-kimchi+unsubscribe@googlegroups.com">project-kimchi+unsubscribe@googlegroups.com</a>.<br>
For more options, visit <a moz-do-not-send="true"
href="https://groups.google.com/groups/opt_out">https://groups.google.com/groups/opt_out</a>.<br>
</blockquote>
<br>
<br>
<pre class="moz-signature" cols="72">--
Ramon Nunes Medeiros
Software Engineer - Linux Technology Center Brazil
IBM Systems & Technology Group
Phone : +55 19 2132 7878
<a class="moz-txt-link-abbreviated" href="mailto:ramonn@br.ibm.com">ramonn@br.ibm.com</a></pre>
</body>
</html>
<p></p>
-- <br />
project-kimchi mailing list <project-kimchi@googlegroups.com><br />
<a href="https://groups.google.com/forum/#!forum/project-kimchi">https://groups.google.com/forum/#!forum/project-kimchi</a><br />
--- <br />
You received this message because you are subscribed to the Google Groups "project-kimchi" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an email to project-kimchi+unsubscribe@googlegroups.com.<br />
For more options, visit <a href="https://groups.google.com/groups/opt_out">https://groups.google.com/groups/opt_out</a>.<br />