From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f47.google.com (mail-wm0-f47.google.com [74.125.82.47]) by dpdk.org (Postfix) with ESMTP id 4CC3B2A5D for ; Thu, 15 Dec 2016 00:05:34 +0100 (CET) Received: by mail-wm0-f47.google.com with SMTP id t79so18563313wmt.0 for ; Wed, 14 Dec 2016 15:05:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references; bh=bKW7ezWXfbnxKnLoYznfL+eKmZ40cTCcLKgSSg8gknk=; b=jCymjv5cY/JrDNbkP4q9ciYhNqEzqERPUFFUs06ZP7zkUGODdbZMdhM5gRbzBGad5B 75rpfMGRAswAOwnnDVAWpitnZ3JmhQJMZF0zXUrGmsKCIUFM06w/1s2Ims3zXX72rj90 4P3dMFO8aDmG3rhf4gYO4TV2wP3SAgNq+jbrUScyZkE0i3tygG3bjTx8Sxp1pajiGMZ0 UAhVdkhwlBvKExPoEy1MK6yy9cg/l2DfpTpfcr9Z9adrqAwhek+vJt7Xv3CRT/HMpGUT rBzhh+Ho13mwc9jAnNCgZNL+wm2jPHQJ99QGyjgc/hfddVhg5kPdP36AboH5+VyAzbQ/ LTow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=bKW7ezWXfbnxKnLoYznfL+eKmZ40cTCcLKgSSg8gknk=; b=LY6sCf+4cjQsF812iY4KkCE2j+Qrq7f2750Sa608Iq7IAU77wAPqO04ilXsh078Pqx W8TTlTLwIVfW4v7GHaV9dqo8PfkYGkSYK4iOGu/7fK3fIrj22M7r0LewA6IA2GAeB10Q GK5NKB2ViOAqu8cpBwb24A5WU7bOnoDKggxDoALsrlW90uP72Vj0IJ3DBAhtq6VjrJh7 vPrmQ04hVX2ryUh+/DArpg4bvveOtsh3MoQD/tgD69/3edgv53Zlh9G/+VMWXBxSpEwD McifirjL76vtUFdSORRsTYdZQYuYscG3eGRbtWMJrrCNaqAiL8GhDqBe8PTkCcTvsUnF k8CA== X-Gm-Message-State: AKaTC00YjoRXN6ZiahBerLE0lnOAcotLcn1B04FiFFxbRp5afhxvK3CLTK0Lw8dfpIFpWz8t X-Received: by 10.28.174.194 with SMTP id x185mr9115626wme.4.1481756733579; Wed, 14 Dec 2016 15:05:33 -0800 (PST) Received: from XPS13.localdomain (184.203.134.77.rev.sfr.net. [77.134.203.184]) by smtp.gmail.com with ESMTPSA id v2sm69378887wja.41.2016.12.14.15.05.32 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 14 Dec 2016 15:05:33 -0800 (PST) From: Thomas Monjalon To: ci@dpdk.org Date: Thu, 15 Dec 2016 00:05:19 +0100 Message-Id: <1481756723-4868-6-git-send-email-thomas.monjalon@6wind.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1481756723-4868-1-git-send-email-thomas.monjalon@6wind.com> References: <1480944373-10233-1-git-send-email-thomas.monjalon@6wind.com> <1481756723-4868-1-git-send-email-thomas.monjalon@6wind.com> Subject: [dpdk-ci] [PATCH v5 5/9] tools: fix pwclient for proxy and python 3 X-BeenThere: ci@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK CI discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 14 Dec 2016 23:05:34 -0000 Python 3 can be used. The environment variables http_proxy and https_proxy can be used. These fixes have been sent to the patchwork project. Signed-off-by: Thomas Monjalon --- README | 1 + tools/pwclient | 77 +++++++++++++++++++++++++++++++++------------------------- 2 files changed, 45 insertions(+), 33 deletions(-) diff --git a/README b/README index 00e1415..f662f6d 100644 --- a/README +++ b/README @@ -66,3 +66,4 @@ the scripts. The file pwclientrc must be copied in ~/.pwclientrc in order to access to the XML-RPC interface of patchwork with the script pwclient. +A proxy can be specified in the environment variables http_proxy and https_proxy. diff --git a/tools/pwclient b/tools/pwclient index f437786..3d5be69 100755 --- a/tools/pwclient +++ b/tools/pwclient @@ -102,31 +102,47 @@ class Filter(object): return str(self.d) -class BasicHTTPAuthTransport(xmlrpclib.SafeTransport): +class Transport(xmlrpclib.SafeTransport): - def __init__(self, username=None, password=None, use_https=False): - self.username = username - self.password = password - self.use_https = use_https + def __init__(self, url): xmlrpclib.SafeTransport.__init__(self) + self.credentials = None + self.host = None + self.proxy = None + self.scheme = url.split('://', 1)[0] + self.https = url.startswith('https') + if self.https: + self.proxy = os.environ.get('https_proxy') + else: + self.proxy = os.environ.get('http_proxy') + if self.proxy: + self.https = self.proxy.startswith('https') - def authenticated(self): - return self.username is not None and self.password is not None - - def send_host(self, connection, host): - xmlrpclib.Transport.send_host(self, connection, host) - if not self.authenticated(): - return - credentials = '%s:%s' % (self.username, self.password) - auth = 'Basic ' + base64.encodestring(credentials).strip() - connection.putheader('Authorization', auth) + def set_credentials(self, username=None, password=None): + self.credentials = '%s:%s' % (username, password) def make_connection(self, host): - if self.use_https: - fn = xmlrpclib.SafeTransport.make_connection + self.host = host + if self.proxy: + host = self.proxy.split('://', 1)[-1] + if self.credentials: + host = '@'.join([self.credentials, host]) + if self.https: + return xmlrpclib.SafeTransport.make_connection(self, host) else: - fn = xmlrpclib.Transport.make_connection - return fn(self, host) + return xmlrpclib.Transport.make_connection(self, host) + + if sys.version_info[0] == 2: + + def send_request(self, connection, handler, request_body): + handler = '%s://%s%s' % (self.scheme, self.host, handler) + xmlrpclib.Transport.send_request(self, connection, handler, request_body) + + else: # Python 3 + + def send_request(self, host, handler, request_body, debug): + handler = '%s://%s%s' % (self.scheme, host, handler) + return xmlrpclib.Transport.send_request(self, host, handler, request_body, debug) def project_id_by_name(rpc, linkname): @@ -253,7 +269,7 @@ def action_check_info(rpc, check_id): print(s) print('-' * len(s)) for key, value in sorted(check.items()): - print("- %- 14s: %s" % (key, unicode(value).encode("utf-8"))) + print("- %- 14s: %s" % (key, unicode(value))) def action_check_create(rpc, patch_id, context, state, url, description): @@ -277,7 +293,7 @@ def action_info(rpc, patch_id): print(s) print('-' * len(s)) for key, value in sorted(patch.items()): - print("- %- 14s: %s" % (key, unicode(value).encode("utf-8"))) + print("- %- 14s: %s" % (key, unicode(value))) def action_get(rpc, patch_id): @@ -301,7 +317,7 @@ def action_get(rpc, patch_id): sys.exit(1) try: - f.write(unicode(s).encode("utf-8")) + f.write(unicode(s)) f.close() print('Saved patch to %s' % fname) except: @@ -670,18 +686,13 @@ def main(): url = config.get(project_str, 'url') - transport = None + transport = Transport(url) if action in auth_actions: if config.has_option(project_str, 'username') and \ config.has_option(project_str, 'password'): - - use_https = url.startswith('https') - - transport = BasicHTTPAuthTransport( + transport.set_credentials( config.get(project_str, 'username'), - config.get(project_str, 'password'), - use_https) - + config.get(project_str, 'password')) else: sys.stderr.write("The %s action requires authentication, but no " "username or password\nis configured\n" % action) @@ -746,15 +757,15 @@ def main(): for patch_id in non_empty(h, patch_ids): s = rpc.patch_get_mbox(patch_id) if len(s) > 0: - i.append(unicode(s).encode("utf-8")) + i.append(unicode(s)) if len(i) > 0: - pager.communicate(input="\n".join(i)) + pager.communicate(input="\n".join(i).encode("utf-8")) pager.stdin.close() else: for patch_id in non_empty(h, patch_ids): s = rpc.patch_get_mbox(patch_id) if len(s) > 0: - print(unicode(s).encode("utf-8")) + print(unicode(s)) elif action == 'info': for patch_id in non_empty(h, patch_ids): -- 2.7.0