-
Notifications
You must be signed in to change notification settings - Fork 285
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CP-50091: Moved inventory.py from scripts/examples/python/ to python3…
…/packages/inventory.py - Fixed bare-except, unspecified-encoding and indentation issue Signed-off-by: Ashwinh <ashwin.h@cloud.com>
- Loading branch information
1 parent
f80b126
commit 39a5384
Showing
4 changed files
with
38 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/usr/bin/env python3 | ||
|
||
""" | ||
inventory.py | ||
This module defines functions to read and parse constants from the xensource-inventory file. | ||
""" | ||
import sys | ||
|
||
INVENTORY = "@INVENTORY@" | ||
INSTALLATION_UUID = "INSTALLATION_UUID" | ||
|
||
|
||
def read_kvpairs(filename): | ||
"""Read in a file of key-value pairs in the format used by the inventory file""" | ||
all_entries = {} | ||
with open(filename, 'r', encoding='utf-8') as f: | ||
for line in f: | ||
equals = line.index("=") | ||
key = line[:equals] | ||
value = line[equals+1:].strip().strip("'") | ||
all_entries[key] = value | ||
return all_entries | ||
|
||
|
||
def parse(): | ||
"""Return the contents of the xensource inventory file as a dictionary""" | ||
try: | ||
return read_kvpairs(INVENTORY) | ||
except FileNotFoundError as e: | ||
print("Error: File '{}' not found. {}".format(INVENTORY, e), file=sys.stderr) | ||
return {} | ||
|
||
|
||
def get_localhost_uuid(): | ||
"""Return the UUID of the local host""" | ||
return parse()[INSTALLATION_UUID] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.