From nobody Thu Sep 19 01:15:53 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=patchew-devel-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=patchew-devel-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1531369320205468.7513404326244; Wed, 11 Jul 2018 21:22:00 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 609B1C049D5C; Thu, 12 Jul 2018 04:21:58 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 51EE060D5C; Thu, 12 Jul 2018 04:21:58 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 42BE04BB78; Thu, 12 Jul 2018 04:21:58 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6C4LuFm020002 for ; Thu, 12 Jul 2018 00:21:56 -0400 Received: by smtp.corp.redhat.com (Postfix) id 622373001A47; Thu, 12 Jul 2018 04:21:56 +0000 (UTC) Received: from mx1.redhat.com (ext-mx17.extmail.prod.ext.phx2.redhat.com [10.5.110.46]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 560C23001A50 for ; Thu, 12 Jul 2018 04:21:53 +0000 (UTC) Received: from mail-pf0-f194.google.com (mail-pf0-f194.google.com [209.85.192.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E9E4330001DB for ; Thu, 12 Jul 2018 04:21:42 +0000 (UTC) Received: by mail-pf0-f194.google.com with SMTP id x10-v6so9915069pfm.4 for ; Wed, 11 Jul 2018 21:21:42 -0700 (PDT) Received: from localhost.localdomain ([112.196.135.182]) by smtp.gmail.com with ESMTPSA id i12-v6sm31294658pgd.87.2018.07.11.21.21.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 11 Jul 2018 21:21:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=tSCNjXzU3Wmz7VNwtqW9T8UOd7xG2Pz9tirTX+VYCCQ=; b=tSPMyKqgX2Hcetg4xl2W7tKeuAs+Qm794XvNf3/KtXEVP6aGjWeRWwemeW+G+3r2UG ZM5QpAhbe1ZFuF7yOGyWT+9ofb02D8QQul8l0CxaLOHRVHMaJcamOzzNW0GqcpKHVEri xOoVTw1b0wNGPV6ujUR4ZV/SILRrYjU9q1a7ZHa37N4euiJlw5oy/Wdop4mropwZWqOC 1rLXBFZub6We1lF3Zjc/cZ4Be1HcS7LWm5N8K7yNnyLX3HAwq/pog7KxUVawyg5CK5Zj ZNCk8KLT3uhpvmnUCiFtZyIsT5JaZEDxunUi/RPapc6CAc/TOmBCLBUB+rZeDlYJ444e DH+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=tSCNjXzU3Wmz7VNwtqW9T8UOd7xG2Pz9tirTX+VYCCQ=; b=IorFrcfGIBXJ35JFrbCrlbjksXPGLXCZx2tjhGNuJeSYQLfelSqxXfrtggQaoiZn47 FVAJLDy1/3a6AgxaNNfiUU4QTSO7IsHmlk0Mf1dHVN5fkBMRIV9WdnXVJY8L0p8pqSD0 qsDkpx5jGUk7IeA5anJ0wDSFygxGpVlLjBHD8pPOj/vhG1H5ajKWR6MRd6C0r9BWUAyv ViGKdxuuwTN+3HP8Ksu3LPHVJe3MguneFnO7a4Kq4jEUUWAdjPHXUZ2XfxSMKdmAgzHW kChOHIezvO1hXLEogSHVCvwT+MuknV7l/jYEjh98ttWPlHOuOKcchd6tveh7k2u18ly4 HbHQ== X-Gm-Message-State: AOUpUlF7/zeV5mBQhEqqNir1wBZ2VmLcfLeLe4Y7ambp/dqsy77mi515 gttH3jdKIrPqorXV6K4KcBWUBQ== X-Google-Smtp-Source: AAOMgpdLupa0W8/yqYgxYNTs05NN1DCMeYxJrwhus5n9qWbUVj+/6zFdHzrSqnz7WxLv0r6b8HiPGQ== X-Received: by 2002:a63:b504:: with SMTP id y4-v6mr36371pge.247.1531369302035; Wed, 11 Jul 2018 21:21:42 -0700 (PDT) From: Shubham Jain To: patchew-devel@redhat.com Date: Thu, 12 Jul 2018 09:51:16 +0530 Message-Id: <20180712042120.2831-3-shubhamjain7495@gmail.com> In-Reply-To: <20180712042120.2831-1-shubhamjain7495@gmail.com> References: <20180712042120.2831-1-shubhamjain7495@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Thu, 12 Jul 2018 04:21:43 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Thu, 12 Jul 2018 04:21:43 +0000 (UTC) for IP:'209.85.192.194' DOMAIN:'mail-pf0-f194.google.com' HELO:'mail-pf0-f194.google.com' FROM:'shubhamjain7495@gmail.com' RCPT:'' X-RedHat-Spam-Score: 3.05 *** (DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, RCVD_IN_SORBS_WEB, SPF_PASS, T_DKIM_INVALID) 209.85.192.194 mail-pf0-f194.google.com 209.85.192.194 mail-pf0-f194.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.46 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-loop: patchew-devel@redhat.com Cc: Shubham Jain Subject: [Patchew-devel] [PATCH v5 2/6] Changes in Patchew cli to use rest-api X-BeenThere: patchew-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Patchew development and discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: patchew-devel-bounces@redhat.com Errors-To: patchew-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Thu, 12 Jul 2018 04:21:58 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Added general rest_api function to make request to apis and get response. --- patchew-cli | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/patchew-cli b/patchew-cli index 9e1fd22..2069885 100755 --- a/patchew-cli +++ b/patchew-cli @@ -91,6 +91,40 @@ class SubCommand(object): else: r =3D None return r + + def rest_api_do(self, url_cmd, request_method=3D'get', content_type=3D= None, data=3DNone): + logging.debug("API call '%s':" % url_cmd) + logging.debug("data:\n%s" % data) + cookie =3D http.cookiejar.MozillaCookieJar(COOKIE_FILENAME) + try: + cookie.load() + except IOError: + pass + except http.cookiejar.LoadError: + print("Error while loading cookie", COOKIE_FILENAME) + pass + handler =3D urllib.request.HTTPCookieProcessor(cookie) + opener =3D urllib.request.build_opener(handler) + if url_cmd.startswith("http"): + url =3D url_cmd + else: + url =3D self.base_url + '/api/v1/' + url_cmd + '/' + if data is None: + post_data =3D "" + else: + post_data =3D data + req =3D urllib.request.Request(url, data=3Dbytes(post_data, encodi= ng=3D"utf-8"), method=3Drequest_method.upper()) + if content_type is not None: + req.add_header('Content-Type', content_type) + resp =3D opener.open(req) + cookie.save(ignore_discard=3DTrue, ignore_expires=3DTrue) + respdata =3D resp.read() + logging.debug("Server response:\n%s" % (respdata or "")) + if respdata: + r =3D json.loads(respdata.decode("utf-8")) + else: + r =3D None + return r =20 def do(self, args, argv): """Do command""" --=20 2.15.1 (Apple Git-101) _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel