From: Thomas Monjalon <thomas.monjalon@6wind.com> To: ci@dpdk.org Subject: [dpdk-ci] [PATCH v5 5/9] tools: fix pwclient for proxy and python 3 Date: Thu, 15 Dec 2016 00:05:19 +0100 Message-ID: <1481756723-4868-6-git-send-email-thomas.monjalon@6wind.com> (raw) In-Reply-To: <1481756723-4868-1-git-send-email-thomas.monjalon@6wind.com> 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 <thomas.monjalon@6wind.com> --- 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
next prev parent reply other threads:[~2016-12-14 23:05 UTC|newest] Thread overview: 64+ messages / expand[flat|nested] mbox.gz Atom feed top 2016-11-25 17:02 [dpdk-ci] [PATCH 0/7] first scripts for CI integration Thomas Monjalon 2016-11-25 17:02 ` [dpdk-ci] [PATCH 1/7] tools: add mail filter Thomas Monjalon 2016-11-25 17:02 ` [dpdk-ci] [PATCH 2/7] tools: add mail parser Thomas Monjalon 2016-11-25 17:02 ` [dpdk-ci] [PATCH 3/7] config: add loader and template Thomas Monjalon 2016-11-25 17:02 ` [dpdk-ci] [PATCH 4/7] tools: add patchwork client Thomas Monjalon 2016-11-25 17:02 ` [dpdk-ci] [PATCH 5/7] tools: add per-patch report mailer Thomas Monjalon 2016-11-25 17:02 ` [dpdk-ci] [PATCH 6/7] tools: add patchwork integration Thomas Monjalon 2016-11-25 17:02 ` [dpdk-ci] [PATCH 7/7] tests: add checkpatch Thomas Monjalon 2016-12-01 13:44 ` [dpdk-ci] [PATCH v2 0/7] first scripts for CI integration Thomas Monjalon 2016-12-01 13:44 ` [dpdk-ci] [PATCH v2 1/7] tools: add mail filter Thomas Monjalon 2016-12-01 13:44 ` [dpdk-ci] [PATCH v2 2/7] tools: add mail parser Thomas Monjalon 2016-12-01 13:44 ` [dpdk-ci] [PATCH v2 3/7] config: add loader and template Thomas Monjalon 2016-12-01 13:44 ` [dpdk-ci] [PATCH v2 4/7] tools: add patchwork client Thomas Monjalon 2016-12-01 13:44 ` [dpdk-ci] [PATCH v2 5/7] tools: add per-patch report mailer Thomas Monjalon 2016-12-01 13:44 ` [dpdk-ci] [PATCH v2 6/7] tools: add patchwork integration Thomas Monjalon 2016-12-01 13:44 ` [dpdk-ci] [PATCH v2 7/7] tests: add checkpatch Thomas Monjalon 2016-12-01 16:58 ` [dpdk-ci] [PATCH v3 0/7] first scripts for CI integration Thomas Monjalon 2016-12-01 16:58 ` [dpdk-ci] [PATCH v3 1/7] tools: add mail filter Thomas Monjalon 2016-12-01 16:58 ` [dpdk-ci] [PATCH v3 2/7] tools: add mail parser Thomas Monjalon 2016-12-01 16:58 ` [dpdk-ci] [PATCH v3 3/7] config: add loader and template Thomas Monjalon 2016-12-01 16:58 ` [dpdk-ci] [PATCH v3 4/7] tools: add patchwork client Thomas Monjalon 2016-12-01 16:58 ` [dpdk-ci] [PATCH v3 5/7] tools: add per-patch report mailer Thomas Monjalon 2016-12-01 16:59 ` [dpdk-ci] [PATCH v3 6/7] tools: add patchwork integration Thomas Monjalon 2016-12-01 16:59 ` [dpdk-ci] [PATCH v3 7/7] tests: add checkpatch Thomas Monjalon 2016-12-05 13:26 ` [dpdk-ci] [PATCH v4 0/7] first scripts for CI integration Thomas Monjalon 2016-12-05 13:26 ` [dpdk-ci] [PATCH v4 1/7] tools: add mail filter Thomas Monjalon 2016-12-05 13:26 ` [dpdk-ci] [PATCH v4 2/7] tools: add mail parser Thomas Monjalon 2016-12-05 13:26 ` [dpdk-ci] [PATCH v4 3/7] config: add loader and template Thomas Monjalon 2016-12-05 13:26 ` [dpdk-ci] [PATCH v4 4/7] tools: add patchwork client Thomas Monjalon 2016-12-05 13:26 ` [dpdk-ci] [PATCH v4 5/7] tools: add per-patch report mailer Thomas Monjalon 2016-12-05 13:26 ` [dpdk-ci] [PATCH v4 6/7] tools: add patchwork integration Thomas Monjalon 2016-12-05 13:26 ` [dpdk-ci] [PATCH v4 7/7] tests: add checkpatch Thomas Monjalon 2016-12-06 6:34 ` Wei, FangfangX 2016-12-06 8:40 ` Thomas Monjalon 2016-12-06 9:04 ` Wei, FangfangX 2016-12-07 5:48 ` Wei, FangfangX 2016-12-07 9:32 ` Thomas Monjalon 2016-12-08 9:02 ` Wei, FangfangX 2016-12-08 13:11 ` Thomas Monjalon 2016-12-09 8:51 ` Wei, FangfangX 2016-12-09 9:16 ` Thomas Monjalon 2016-12-09 10:07 ` Mcnamara, John 2016-12-09 10:11 ` Thomas Monjalon 2016-12-09 12:11 ` Mcnamara, John 2016-12-12 9:27 ` Wei, FangfangX 2016-12-12 9:34 ` Wei, FangfangX 2016-12-12 9:58 ` Thomas Monjalon 2016-12-13 8:29 ` Wei, FangfangX 2016-12-13 8:49 ` Thomas Monjalon 2016-12-13 9:24 ` Wei, FangfangX 2016-12-21 11:45 ` Thomas Monjalon 2016-12-12 9:39 ` Thomas Monjalon 2016-12-13 8:22 ` Wei, FangfangX 2016-12-14 23:05 ` [dpdk-ci] [PATCH v5 0/9] first scripts for CI integration Thomas Monjalon 2016-12-14 23:05 ` [dpdk-ci] [PATCH v5 1/9] tools: add mail filter Thomas Monjalon 2016-12-14 23:05 ` [dpdk-ci] [PATCH v5 2/9] tools: add mail parser Thomas Monjalon 2016-12-14 23:05 ` [dpdk-ci] [PATCH v5 3/9] config: add loader and template Thomas Monjalon 2016-12-14 23:05 ` [dpdk-ci] [PATCH v5 4/9] tools: add patchwork client Thomas Monjalon 2016-12-14 23:05 ` Thomas Monjalon [this message] 2016-12-14 23:05 ` [dpdk-ci] [PATCH v5 6/9] tools: add patch mail download Thomas Monjalon 2016-12-14 23:05 ` [dpdk-ci] [PATCH v5 7/9] tools: add per-patch report mailer Thomas Monjalon 2016-12-14 23:05 ` [dpdk-ci] [PATCH v5 8/9] tools: add patchwork integration Thomas Monjalon 2016-12-14 23:05 ` [dpdk-ci] [PATCH v5 9/9] tests: add checkpatch Thomas Monjalon 2016-12-21 11:46 ` [dpdk-ci] [PATCH v5 0/9] first scripts for CI integration Thomas Monjalon
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=1481756723-4868-6-git-send-email-thomas.monjalon@6wind.com \ --to=thomas.monjalon@6wind.com \ --cc=ci@dpdk.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
DPDK CI discussions This inbox may be cloned and mirrored by anyone: git clone --mirror http://inbox.dpdk.org/ci/0 ci/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ci ci/ http://inbox.dpdk.org/ci \ ci@dpdk.org public-inbox-index ci Example config snippet for mirrors. Newsgroup available over NNTP: nntp://inbox.dpdk.org/inbox.dpdk.ci AGPL code for this site: git clone https://public-inbox.org/public-inbox.git