From 0d9eb88ab1ba73094db02fb27c8a8edcfa0a2c0e Mon Sep 17 00:00:00 2001 From: Nolan Brubaker Date: Thu, 6 Oct 2016 12:10:43 -0400 Subject: [PATCH] Move management code to inventory lib. This change moves the management code into a library file for consolidated access to the code. Nothing is changed with the interface to the inventory-manage script. The lib/__init__.py file is necessary for python to import the lib directory as a package, which will become more important as more code is relocated there. The code was originally moved to playbooks/inventory/lib, but doing so made Ansible try to run the python files, which they intentionally will not do. Change-Id: I2e31927ec48022c7a504096780977319882c6bdf --- lib/__init__.py | 0 scripts/manage_inventory.py => lib/manage.py | 0 scripts/inventory-manage.py | 13 ++++++++++--- tests/test_manage.py | 4 ++-- tox.ini | 2 +- 5 files changed, 13 insertions(+), 6 deletions(-) create mode 100644 lib/__init__.py rename scripts/manage_inventory.py => lib/manage.py (100%) diff --git a/lib/__init__.py b/lib/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/scripts/manage_inventory.py b/lib/manage.py similarity index 100% rename from scripts/manage_inventory.py rename to lib/manage.py diff --git a/scripts/inventory-manage.py b/scripts/inventory-manage.py index 29216b044c..305ad82666 100755 --- a/scripts/inventory-manage.py +++ b/scripts/inventory-manage.py @@ -20,10 +20,17 @@ """Returns data about containers and groups in tabular formats.""" # NOTE(nrb/palendae): The contents of this file were moved -# to manage_inventory.py in order to facilitate importing of the python code +# to manage.py in order to facilitate importing of the python code # This file remains for backwards compatibility -import manage_inventory +import os +import sys + +cwd = os.path.abspath(os.path.dirname(__file__)) +import_path = os.path.join(cwd, '..', 'lib') +sys.path.append(import_path) + +import manage if __name__ == "__main__": - manage_inventory.main() + manage.main() diff --git a/tests/test_manage.py b/tests/test_manage.py index 0d1f2453fc..d5ffabaaef 100644 --- a/tests/test_manage.py +++ b/tests/test_manage.py @@ -6,11 +6,11 @@ import sys import test_inventory import unittest -MANAGE_DIR = path.join(os.getcwd(), 'scripts') +MANAGE_DIR = path.join(os.getcwd(), 'lib') sys.path.append(MANAGE_DIR) -import manage_inventory as mi +import manage as mi def setUpModule(): diff --git a/tox.ini b/tox.ini index 0aa390f1e8..55932cd199 100644 --- a/tox.ini +++ b/tox.ini @@ -151,7 +151,7 @@ commands = coverage report --show-missing --include={toxinidir}/playbooks/inventory/* coverage erase coverage run {toxinidir}/tests/test_manage.py - coverage report --show-missing --include={toxinidir}/scripts/* + coverage report --show-missing --include={toxinidir}/lib/* [testenv:linters]