[Patchew-devel] [PATCH v4 2/4] Make Patchew cli's Project use rest api
Fam Zheng
famz at redhat.com
Tue Jul 10 07:41:35 UTC 2018
On Sat, 07/07 00:02, Shubham Jain wrote:
> -Make ProjectCommand use rest_api_do instead of api_do
> ---
> api/rest.py | 1 +
> patchew-cli | 37 +++++++++++++++++++++----------------
> 2 files changed, 22 insertions(+), 16 deletions(-)
>
> diff --git a/api/rest.py b/api/rest.py
> index 45dab6e..39bdda0 100644
> --- a/api/rest.py
> +++ b/api/rest.py
> @@ -146,6 +146,7 @@ class ProjectsViewSet(viewsets.ModelViewSet):
> queryset = Project.objects.all().order_by('id')
> serializer_class = ProjectSerializer
> permission_classes = (PatchewPermission,)
> + authentication_classes = (CsrfExemptSessionAuthentication, )
>
> @action(methods=['post'], detail=True, permission_classes=[ImportPermission])
> def update_project_head(self, request, pk=None):
> diff --git a/patchew-cli b/patchew-cli
> index 2069885..9d9fde0 100755
> --- a/patchew-cli
> +++ b/patchew-cli
> @@ -125,7 +125,7 @@ class SubCommand(object):
> else:
> r = None
> return r
> -
> +
> def do(self, args, argv):
> """Do command"""
> print("Not implemented")
> @@ -255,11 +255,11 @@ class ProjectCommand(SubCommand):
> parser.add_argument("--verbose", "-v", action="store_true",
> help="Show details about projects")
> args = parser.parse_args(argv)
> - r = self.api_do("get-projects")
> + r = self.rest_api_do(url_cmd="projects", request_method='get')
> if args.raw:
> print(json.dumps(r, indent=2, separators=",:"))
> return 0
> - for p in r:
> + for p in r['results']:
> print(p["name"])
> if args.verbose:
> for k, v in p.items():
> @@ -273,8 +273,8 @@ class ProjectCommand(SubCommand):
> parser.add_argument("name", nargs="+",
> help="The name of project to show info")
> args = parser.parse_args(argv)
> - r = self.api_do("get-projects")
> - for p in r:
> + r = self.rest_api_do(url_cmd="projects", request_method='get')
> + for p in r['results']:
> if not p["name"] in args.name:
> continue
> if len(args.name) > 1:
> @@ -297,12 +297,15 @@ class ProjectCommand(SubCommand):
> parser.add_argument("--desc", "-d", default="",
> help="Project short discription")
> args = parser.parse_args(argv)
> - self.api_do("add-project",
> - name=args.name,
> - mailing_list=args.mailing_list,
> - url=args.url,
> - git=args.git,
> - description=args.desc)
> + data = {'name':args.name,
> + 'mailing_list':args.mailing_list,
> + 'url':args.url,
> + 'git':args.git,
> + 'description':args.desc}
> + self.rest_api_do(url_cmd="projects",
> + request_method='post',
> + content_type='application/json',
> + data=json.dumps(data))
>
> def update_one_project(self, wd, project):
> logging.info("Updating project '%s'", project["name"])
> @@ -354,16 +357,18 @@ class ProjectCommand(SubCommand):
> except Exception as e:
> logging.warn("Failed to push the new head to patchew mirror: %s",
> str(e))
> - self.api_do("update-project-head", project=project["name"],
> - old_head=old_head,
> - new_head=new_head,
> - message_ids=msgids)
> + url = project['resource_uri'] + "/update_project_head/"
> + self.rest_api_do(url, request_method='post',
> + old_head=old_head,
> + new_head=new_head,
> + message_ids=msgids)
>
> def update_project(self, argv):
> parser = argparse.ArgumentParser()
> parser.add_argument("--name", "-n", help="Name of the project")
> args = parser.parse_args(argv)
> - projects = self.api_do("get-projects", name=args.name)
> + projects = self.rest_api_do("projects")
> + projects = [p for p in projects['results'] if p['name'] == args.name]
This breaks the case when args.name == None. Previously, all projects will be
updated.
Fam
> wd = tempfile.mkdtemp()
> logging.debug("TMPDIR: %s", wd)
> try:
> --
> 2.15.1 (Apple Git-101)
>
> _______________________________________________
> Patchew-devel mailing list
> Patchew-devel at redhat.com
> https://www.redhat.com/mailman/listinfo/patchew-devel
More information about the Patchew-devel
mailing list