Merge lp:~smoser/pollinate/trunk.speedups into lp:~pollinate/pollinate/trunk

Proposed by Scott Moser
Status: Merged
Merged at revision: 366
Proposed branch: lp:~smoser/pollinate/trunk.speedups
Merge into: lp:~pollinate/pollinate/trunk
Diff against target: 89 lines (+52/-9)
1 file modified
pollinate (+52/-9)
To merge this branch: bzr merge lp:~smoser/pollinate/trunk.speedups
Reviewer Review Type Date Requested Status
pollinate Pending
Review via email: mp+337394@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Scott Moser (smoser) wrote :

This does change the order of packages, and makes their order in the string not guaranteed.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'pollinate'
2--- pollinate 2018-01-30 22:28:52 +0000
3+++ pollinate 2018-02-08 22:29:35 +0000
4@@ -17,6 +17,7 @@
5 # along with this program. If not, see <http://www.gnu.org/licenses/>.
6
7 set -e
8+set -f
9
10 PKG="pollinate"
11 TMPDIR=$(mktemp -d -t "${PKG}.XXXXXXXXXXXX")
12@@ -142,26 +143,68 @@
13 _RET="virt/$ret"
14 }
15
16+read_package_versions() {
17+ local pkgs="pollinate curl cloud-init" data="" p=""
18+ data=$(dpkg-query \
19+ -W --showformat='${Package}/${Version} ' $pkgs 2>/dev/null) || :
20+ # fill in 'package/' for any package not installed.
21+ for p in ${pkgs}; do
22+ [ "${data#*$p/}" = "$data" ] && data="${data} $p/"
23+ done
24+ if [ -n "$TESTING" ]; then
25+ p="pollinate"
26+ data="${data%%$p/*}$p${TESTING}/${data#*$p/}"
27+ fi
28+ set -- $data
29+ _RET="$*"
30+}
31+
32+read_uname_info() {
33+ # taken from cloud-init ds-identify.
34+ # run uname, and parse output.
35+ # uname is tricky to parse as it outputs always in a given order
36+ # independent of option order. kernel-version is known to have spaces.
37+ # 1 -s kernel-name
38+ # 2 -n nodename
39+ # 3 -r kernel-release
40+ # 4.. -v kernel-version(whitespace)
41+ # N-2 -m machine
42+ # N-1 -o operating-system
43+ local out="" krel="" machine="" os=""
44+ out=$(uname -snrvmo) || { _RET=""; return; }
45+ set -- $out
46+ krel="$3"
47+ shift 3
48+ while [ $# -gt 2 ]; do
49+ shift
50+ done
51+ machine=$1
52+ os=$2
53+ _RET="$os/$krel/$machine"
54+ return 0
55+}
56+
57 user_agent() {
58 # Construct a user agent, with useful debug information
59 # Very similar to Firefox and Chrome
60- local pollinate_ver="$(dpkg-query -W --showformat='${Version}' pollinate 2>/dev/null || true)"
61- local curl_ver="$(dpkg-query -W --showformat='${Version}' curl 2>/dev/null || true)"
62- local cloud_init_ver="$(dpkg-query -W --showformat='${Version}' cloud-init 2>/dev/null)"
63+
64 . /etc/lsb-release
65- local lsb=$(echo "${DISTRIB_DESCRIPTION}" | sed -e "s/ /\//g")
66- local platform="$(uname -o)/$(uname -r)/$(uname -m)"
67- local cpu="$(grep -m1 "^model name" /proc/cpuinfo | sed -e "s/.*: //" -e "s:\s\+:/:g")"
68- local up="NA" idle="NA"
69+
70+ local pkg_info="" lsb="" platform="" cpu="" up="NA" idle="NA" uptime
71+ read_package_versions && pkg_info="$_RET"
72+ read_uname_info && platform="$_RET"
73+
74+ lsb=$(echo "${DISTRIB_DESCRIPTION}" | sed -e "s/ /\//g")
75+ cpu="$(grep -m1 "^model name" /proc/cpuinfo | sed -e "s/.*: //" -e "s:\s\+:/:g")"
76 { read up idle < /proc/uptime ; } >/dev/null 2>&1 || :
77- local uptime="uptime/$up/$idle"
78+ uptime="uptime/$up/$idle"
79
80 local addl_data="" build_info="" virt=""
81 read_build_info && build_info="${_RET}"
82 read_addl_info && addl_data="${_RET}"
83 read_virt && virt="${_RET}"
84
85- USER_AGENT="pollinate${TESTING}/${pollinate_ver} curl/${curl_ver} cloud-init/${cloud_init_ver} ${lsb} ${platform} ${cpu} ${uptime}${virt:+ ${virt}}${build_info:+ ${build_info}}${addl_data:+ ${addl_data}}"
86+ USER_AGENT="${pkg_info} ${lsb} ${platform} ${cpu} ${uptime}${virt:+ ${virt}}${build_info:+ ${build_info}}${addl_data:+ ${addl_data}}"
87 }
88
89 exchange() {

Subscribers

People subscribed via source and target branches

to all changes: