2
0
mirror of https://github.com/xcat2/confluent.git synced 2024-12-25 12:41:39 +00:00

Fix nodediscover order and csv together

This commit is contained in:
Jarrod Johnson 2019-02-26 13:57:11 -05:00
parent ad64cda249
commit 161cf37f46
2 changed files with 23 additions and 12 deletions

View File

@ -69,10 +69,7 @@ def print_disco(options, session, currmac, outhandler, columns):
record.append(','.join(rawval))
else:
record.append(str(rawval))
if options.csv:
csv.writer(sys.stdout).writerow(record)
else:
outhandler.add_row(record)
outhandler.add_row(record)
def process_header(header):
@ -204,7 +201,6 @@ def import_csv(options, session):
def list_discovery(options, session):
outhandler = None
orderby = None
if options.fields:
columns = []
@ -219,15 +215,12 @@ def list_discovery(options, session):
for field in columns:
if options.order.lower() == field.lower():
orderby = field
if options.csv:
if orderby:
hsht
csv.writer(sys.stdout).writerow(columns)
else:
outhandler = client.Tabulator(columns)
outhandler = client.Tabulator(columns)
for mac in list_matching_macs(options, session):
print_disco(options, session, mac, outhandler, columns)
if outhandler:
if options.csv:
outhandler.write_csv(sys.stdout, orderby)
else:
for row in outhandler.get_table(orderby):
print(row)

View File

@ -16,6 +16,7 @@
# limitations under the License.
import anydbm as dbm
import csv
import errno
import fnmatch
import hashlib
@ -70,6 +71,23 @@ class Tabulator(object):
for row in self.rows:
yield fmtstr.format(*row)
def write_csv(self, output, order=None):
output = csv.writer(output)
output.writerow(self.headers)
i = 0
for head in self.headers:
if order and order == head:
order = i
i = i + 1
if order is not None:
for row in sorted(
self.rows,
key=lambda x: sortutil.naturalize_string(x[order])):
output.writerow(row)
else:
for row in self.rows:
output.writerow(row)
def printerror(res, node=None):
exitcode = 0