From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id CEE721381F3 for ; Wed, 14 Aug 2013 20:11:18 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 6EF39E0CA5; Wed, 14 Aug 2013 20:11:10 +0000 (UTC) Received: from eu-ger-1.hurrikane.de (eu-ger-1.hurrikane.de [83.136.86.198]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id A885EE0C8D for ; Wed, 14 Aug 2013 20:11:09 +0000 (UTC) Received: by eu-ger-1.hurrikane.de (Postfix, from userid 1000) id 5459D26C24; Wed, 14 Aug 2013 22:11:03 +0200 (CEST) From: Mark Kubacki To: gentoo-portage-dev@lists.gentoo.org Cc: W-Mark Kubacki Subject: [gentoo-portage-dev] [PATCH 2/3] Send output of ```emerge --version``` as User-Agent HTTP-header Date: Wed, 14 Aug 2013 22:10:39 +0200 Message-Id: <1376511040-15874-3-git-send-email-wmark@hurrikane.de> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1376511040-15874-1-git-send-email-wmark@hurrikane.de> References: <1376511040-15874-1-git-send-email-wmark@hurrikane.de> Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-portage-dev@lists.gentoo.org Reply-to: gentoo-portage-dev@lists.gentoo.org MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Archives-Salt: 64c9ba62-d7ed-433c-90e3-e8ecebd50d7c X-Archives-Hash: 9cae6c4eb086351f7e4c1535dc00aa98 From: W-Mark Kubacki The remote server logs will read like this: 2001:db8::4 - - [14/Aug/2013:20:58:02 +0200] "GET /Packages HTTP/1.1" 304 0 "-" "Gentoo Portage 2.1.13.7 (default/linux/amd64/13.0, gcc-4.6.2, glibc-2.18, 3.9.0-rc8-mark-signed+ x86_64)" This will enable administrators to… • check if a machine uses the correct binhost • decide when new server-side features can be enabled (Portage ver.) • notify the machine's administrator of malconfigurations (such as wrong GCC libraries, profile, obsolete kernel) Construction of this header happens before "Packages" are fetched from a remote binhost. Signed-off-by: W-Mark Kubacki --- pym/portage/dbapi/bintree.py | 8 +++++++- pym/portage/util/_urlopen.py | 4 ++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/pym/portage/dbapi/bintree.py b/pym/portage/dbapi/bintree.py index 61ac6b5..44ee8e6 100644 --- a/pym/portage/dbapi/bintree.py +++ b/pym/portage/dbapi/bintree.py @@ -20,6 +20,7 @@ portage.proxy.lazyimport.lazyimport(globals(), 'portage.util.listdir:listdir', 'portage.util._urlopen:urlopen@_urlopen', 'portage.versions:best,catpkgsplit,catsplit,_pkg_str', + '_emerge.actions:load_emerge_config,getportageversion', ) from portage.cache.mappings import slot_dict_class @@ -892,8 +893,13 @@ class binarytree(object): # Don't use urlopen for https, since it doesn't support # certificate/hostname verification (bug #469888). if parsed_url.scheme not in ('https',): + trees = load_emerge_config().trees + user_agent = "Gentoo "+getportageversion(self.settings["PORTDIR"], None, + self.settings.profile_path, self.settings["CHOST"], + trees[self.settings['EROOT']]["vartree"].dbapi) try: - f = _urlopen(url, if_modified_since=local_timestamp) + f = _urlopen(url, user_agent=user_agent, + if_modified_since=local_timestamp) if hasattr(f, 'headers') and f.headers.get('timestamp', ''): remote_timestamp = f.headers.get('timestamp') except IOError as err: diff --git a/pym/portage/util/_urlopen.py b/pym/portage/util/_urlopen.py index 798e7b4..9876f29 100644 --- a/pym/portage/util/_urlopen.py +++ b/pym/portage/util/_urlopen.py @@ -26,7 +26,7 @@ if sys.hexversion >= 0x3000000: # and the file-'mtime' TIMESTAMP_TOLERANCE=5 -def urlopen(url, if_modified_since=None): +def urlopen(url, user_agent=None, if_modified_since=None): parse_result = urllib_parse.urlparse(url) if parse_result.scheme not in ("http", "https"): return _urlopen(url) @@ -35,7 +35,7 @@ def urlopen(url, if_modified_since=None): url = urllib_parse.urlunparse((parse_result.scheme, netloc, parse_result.path, parse_result.params, parse_result.query, parse_result.fragment)) password_manager = urllib_request.HTTPPasswordMgrWithDefaultRealm() request = urllib_request.Request(url) - request.add_header('User-Agent', 'Gentoo Portage '+VERSION) + request.add_header('User-Agent', user_agent or 'Gentoo Portage '+VERSION) if if_modified_since: request.add_header('If-Modified-Since', _timestamp_to_http(if_modified_since)) if parse_result.username is not None: -- 1.8.3.2