From: DW Talton Date: Mon, 18 Nov 2019 22:39:03 +0000 (-0700) Subject: Add RTD project details update support X-Git-Tag: v0.28.0^0 X-Git-Url: https://gerrit.linuxfoundation.org/infra/gitweb?a=commitdiff_plain;h=ce8508e48bc148a5f97e3a9cf41922d5b15841a2;p=releng%2Flftools.git Add RTD project details update support Add the ability to update RTD project details from the CLI. Issue: RELENG-2543 Signed-off-by: DW Talton Change-Id: Ic165376cfcd7a81acb4ac602882d9d7925827c6a --- diff --git a/lftools/api/endpoints/readthedocs.py b/lftools/api/endpoints/readthedocs.py index f9c47a3d..fed07ae6 100644 --- a/lftools/api/endpoints/readthedocs.py +++ b/lftools/api/endpoints/readthedocs.py @@ -46,26 +46,13 @@ class ReadTheDocs(client.RestApi): :param kwargs: :return: [projects] """ - result = self.get('projects/')[1] # NOQA - more_results = None + result = self.get('projects/?limit=999')[1] # NOQA data = result['results'] project_list = [] - if result['next']: - more_results = result['next'].rsplit('/', 1)[-1] - - if more_results: - while more_results is not None: - get_more_results = self.get('projects/' + more_results)[1] - data.append(get_more_results['results']) - more_results = get_more_results['next'] - - if more_results is not None: - more_results = more_results.rsplit('/', 1)[-1] - for project in data: - project_list.append(project['slug']) - + if 'slug' in project: + project_list.append(project['slug']) return project_list def project_details(self, project): @@ -144,6 +131,22 @@ class ReadTheDocs(client.RestApi): data=json_data) return result + def project_update(self, project, *args): + """Update any project details. + + :param project: Project's name (slug). + :param args: Any of the JSON keys allows by RTD API. + :return: Bool + """ + data = args[0] + json_data = json.dumps(data) + result = self.patch('projects/{}/'.format(project), data=json_data) + + if result.status_code == 204: + return True, result.status_code + else: + return False, result.status_code + def project_create(self, name, repository_url, repository_type, homepage, programming_language, language, **kwargs): """Create a new Read the Docs project. @@ -227,24 +230,10 @@ class ReadTheDocs(client.RestApi): :param kwargs: :return: [subprojects] """ - result = self.get('projects/{}/subprojects/'.format(project))[1] # NOQA - more_results = None + result = self.get('projects/{}/subprojects/?limit=999'.format(project))[1] # NOQA data = result['results'] subproject_list = [] - if result['next']: - more_results = result['next'].rsplit('/', 1)[-1] - - if more_results: - while more_results is not None: - get_more_results = self.get('projects/{}/subprojects/' - .format(project) + more_results)[1] - data.append(get_more_results['results']) - more_results = get_more_results['next'] - - if more_results is not None: - more_results = more_results.rsplit('/', 1)[-1] - for subproject in data: subproject_list.append(subproject['child']['slug']) diff --git a/lftools/cli/rtd.py b/lftools/cli/rtd.py index c5d595ed..35ab11b2 100644 --- a/lftools/cli/rtd.py +++ b/lftools/cli/rtd.py @@ -92,6 +92,21 @@ def project_create(ctx, project_name, repository_url, repository_type, log.info(pformat(data)) +@click.command(name='project-update', + context_settings=dict(ignore_unknown_options=True, + allow_extra_args=True,)) +@click.argument('project-name') +@click.pass_context +def project_update(ctx, project_name): + """Create a new project.""" + r = readthedocs.ReadTheDocs() + d = dict() + for item in ctx.args: + d.update([item.split('=')]) + data = r.project_update(project_name, d) + log.info(pformat(data)) + + @click.command(name='project-build-list') @click.argument('project-slug') @click.pass_context @@ -183,6 +198,7 @@ rtd.add_command(project_create) rtd.add_command(project_build_list) rtd.add_command(project_build_details) rtd.add_command(project_build_trigger) +rtd.add_command(project_update) rtd.add_command(subproject_list) rtd.add_command(subproject_details) rtd.add_command(subproject_create) diff --git a/lftools/deploy.py b/lftools/deploy.py index ea56bedc..6537e13f 100755 --- a/lftools/deploy.py +++ b/lftools/deploy.py @@ -12,6 +12,7 @@ import concurrent.futures import errno +import glob import gzip import io import logging @@ -26,7 +27,6 @@ import tempfile import zipfile from defusedxml.minidom import parseString -import glob import requests import six diff --git a/releasenotes/notes/readthedocs-ec3b30d399730b9d.yaml b/releasenotes/notes/readthedocs-ec3b30d399730b9d.yaml new file mode 100644 index 00000000..a353d9a5 --- /dev/null +++ b/releasenotes/notes/readthedocs-ec3b30d399730b9d.yaml @@ -0,0 +1,9 @@ +--- +features: + - | + Add the ability to update existing project's properties. This is done by invoking + lftools rtd project-update PROJECT_NAME key='value' where key is the name of a json + API key for the RTD API and value is the new value you require. +fixes: + - | + Fixed issues with project and subproject listing. diff --git a/tests/test_rtd.py b/tests/test_rtd.py index 5cb65b7b..22d7edc2 100644 --- a/tests/test_rtd.py +++ b/tests/test_rtd.py @@ -151,7 +151,7 @@ def test_subproject_list(datafiles): json_file = open('subproject_list.json', 'r') json_data = json.loads(json_file.read()) responses.add(responses.GET, - url='https://readthedocs.org/api/v3/projects/TestProject1/subprojects/', # noqa + url='https://readthedocs.org/api/v3/projects/TestProject1/subprojects/?limit=999', # noqa json=json_data, status=200, match_querystring=True) assert 'testproject2' in rtd.subproject_list('TestProject1')