Support passing just a single project name

This allows you to pass just the project name, like 'nova',
to the --project option so you don't have to actually know
the underlying file structure.

Change-Id: I9f0f7f54ff5f5c1d99f391fc0706c00ccbe8886f
This commit is contained in:
Matt Riedemann 2016-03-10 15:05:30 -05:00
parent 428802c94c
commit ecaabf2146
2 changed files with 16 additions and 1 deletions

View File

@ -18,3 +18,11 @@ class TestProjectInfo(base.TestCase):
def test_project_definitions_load(self):
utils.get_projects_info('', True)
def test_get_projects_info_single_name(self):
projects = utils.get_projects_info('nova')
self.assertEqual(1, len(projects))
def test_get_projects_info_single_name_projects_prefixed(self):
projects = utils.get_projects_info('projects/stable.json')
self.assertEqual(1, len(projects))

View File

@ -31,7 +31,8 @@ import paramiko
LOG = logging.getLogger(__name__)
def get_projects_info(project=None, all_projects=False, base_dir='./projects'):
def get_projects_info(project=None, all_projects=False,
base_dir='./projects/'):
"""Return the list of project dict objects.
:param project: pathname of the JSON project info file.
@ -57,6 +58,12 @@ def get_projects_info(project=None, all_projects=False, base_dir='./projects'):
if all_projects:
files = glob.glob('%s/*.json' % base_dir)
else:
# handle just passing the project name
if not os.path.isfile(project):
if not project.startswith(base_dir):
project = base_dir + project
if not project.endswith('.json'):
project = project + '.json'
files = [project]
projects = []