Browse Source

factor out board output, make it repr so multiple lines (ssh keys

or bootup messages) are escaped...
main
John-Mark Gurney 4 years ago
parent
commit
e641a34035
1 changed files with 13 additions and 12 deletions
  1. +13
    -12
      bitelab/__main__.py

+ 13
- 12
bitelab/__main__.py View File

@@ -71,6 +71,13 @@ def make_attrs(*args):

_httpxargs = dict(timeout=20)

def output_board(brd):
print('Name:\t%s' % brd.name)
print('Class:\t%s' % brd.brdclass)
print('Attributes:')
for i in sorted(brd.attrs):
print('\t%s\t%s' % (i, repr(brd.attrs[i])))

async def real_main():
baseurl = os.environ['BITELAB_URL']
authkey = os.environ['BITELAB_AUTH']
@@ -98,11 +105,8 @@ async def real_main():
check_res_code(res)

brd = Board.parse_obj(res.json())
print('Name:\t%s' % brd.name)
print('Class:\t%s' % brd.brdclass)
print('Attributes:')
for i in sorted(brd.attrs):
print('\t%s\t%s' % (i, brd.attrs[i]))
output_board(brd)

elif sys.argv[1] == 'set':
board_id = sys.argv[-1]
res = await client.post('board/%s/attrs' %
@@ -113,11 +117,8 @@ async def real_main():
check_res_code(res)

brd = Board.parse_obj(res.json())
print('Name:\t%s' % brd.name)
print('Class:\t%s' % brd.brdclass)
print('Attributes:')
for i in sorted(brd.attrs):
print('\t%s\t%s' % (i, brd.attrs[i]))
output_board(brd)

finally:
await client.aclose()

@@ -218,7 +219,7 @@ class TestClient(unittest.TestCase):
output = '''Name:\tcora-1
Class:\tcora-z7s
Attributes:
\tip\t172.20.20.5
\tip\t'172.20.20.5'
\tpower\tFalse
'''

@@ -273,7 +274,7 @@ Attributes:
output = '''Name:\tcora-1
Class:\tcora-z7s
Attributes:
\tip\t172.20.20.5
\tip\t'172.20.20.5'
\tpower\tTrue
'''



Loading…
Cancel
Save