Commit 5c927409 authored by Sebastien Gougeaud's avatar Sebastien Gougeaud Committed by Thomas Leibovici
Browse files

cli: 'list -o' prints following user order



Except for xml format (where the dictionary insertion order is
preserved in python3.6 and above), the output of 'list -o' commands
is now ordered following the attributes order given by the user.

Because csv format order is not an alphabetical one anymore,
acceptance.sh 'list -o' commands are modified if followed by a grep,
to only output the requested attribute.

Change-Id: I9b667d969fae955137d83cb1d22c7231f5c1caa1
Signed-off-by: default avatarSebastien Gougeaud <sebastien.gougeaud@cea.fr>
Reviewed-on: https://cws-fleury.labs.ocre.cea.fr/gerrit/6708


Reviewed-by: Linter
Reviewed-by: default avatarPatrice LUCAS <patrice.lucas@cea.fr>
Tested-by: default avatarJenkins s8open_nr <s8open_nr@ccc.ocre.cea.fr>
Reviewed-by: default avatarThomas Leibovici <thomas.leibovici@cea.fr>
parent b6354c77
......@@ -23,8 +23,9 @@
Output and formatting utilities.
"""
import json
from collections import OrderedDict
import csv
import json
import StringIO
from tabulate import tabulate
import xml.dom.minidom
......@@ -37,7 +38,7 @@ import yaml
def csv_dump(data):
"""Convert a list of dictionaries to a csv string"""
outbuf = StringIO.StringIO()
writer = csv.DictWriter(outbuf, sorted(data[0].keys()))
writer = csv.DictWriter(outbuf, data[0].keys())
if hasattr(writer, 'writeheader'):
#pylint: disable=no-member
writer.writeheader()
......@@ -92,7 +93,8 @@ def filter_display_dict(objs, attrs):
obj_list = info
else:
for attr_dict in info:
obj_list.append({k: attr_dict[k] for k in attr_dict if k in attrs})
obj_list.append(OrderedDict([(k, attr_dict[k]) for k in attrs
if k in attr_dict]))
return obj_list
......
......@@ -139,7 +139,7 @@ function tape_setup
local dr1=$(echo $drives | awk '{print $1}')
echo "$dr1"
# check drive status
$phobos drive list -o all $dr1 --format=csv | grep "^locked" ||
$phobos drive list -o adm_status $dr1 --format=csv | grep "^locked" ||
error "Drive should be added with locked state"
# unlock all drives but one (except if N_DRIVE < 2)
......@@ -206,10 +206,12 @@ function lock_test
mkdir $dir_prefix.1
mkdir $dir_prefix.2
$LOG_VALG $phobos dir add $dir_prefix.1
$phobos dir list -o all $dir_prefix.1 --format=csv | grep ",locked" ||
$phobos dir list -o adm_status $dir_prefix.1 --format=csv |
grep "^locked" ||
error "Directory should be added with locked state"
$LOG_VALG $phobos dir add $dir_prefix.2 --unlock
$phobos dir list -o all $dir_prefix.2 --format=csv | grep ",unlocked" ||
$phobos dir list -o adm_status $dir_prefix.2 --format=csv |
grep "^unlocked" ||
error "Directory should be added with unlocked state"
rmdir $dir_prefix.*
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment