Merge lp:~cjwatson/launchpad/simplify-buildout-bin-shell into lp:launchpad

Proposed by Colin Watson on 2017-01-17
Status: Merged
Merged at revision: 18319
Proposed branch: lp:~cjwatson/launchpad/simplify-buildout-bin-shell
Merge into: lp:launchpad
Diff against target: 173 lines (+52/-62)
5 files modified
Makefile (+5/-5)
lib/lp/scripts/utilities/withxvfb.py (+41/-45)
setup.py (+1/-0)
utilities/lint (+2/-8)
utilities/update-download-cache (+3/-4)
To merge this branch: bzr merge lp:~cjwatson/launchpad/simplify-buildout-bin-shell
Reviewer Review Type Date Requested Status
William Grant code 2017-01-17 Approve on 2017-01-18
Review via email: mp+314973@code.launchpad.net

Commit Message

Move shell scripts out of buildout-templates/bin/.

Description of the Change

lint is mainly used by "make lint", so it's simplest to just move that to utilities/.

update-download-cache is (as far as I know) unreferenced and probably rarely used, so again it's simplest to just move that to utilities/.

with-xvfb is likely to be referenced from test wrappers (it certainly is by mine), so I rewrote it in Python and added an entry point for it in setup.py.

To post a comment you must log in.
William Grant (wgrant) :
review: Approve (code)
18314. By Colin Watson on 2017-01-21

Merge devel.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Makefile'
2--- Makefile 2017-01-21 13:03:26 +0000
3+++ Makefile 2017-01-21 13:43:34 +0000
4@@ -52,10 +52,10 @@
5 bin/fl-record bin/fl-run-bench bin/fl-run-test bin/googletestservice \
6 bin/i18ncompile bin/i18nextract bin/i18nmergeall bin/i18nstats \
7 bin/harness bin/iharness bin/ipy bin/jsbuild bin/lpjsmin\
8- bin/killservice bin/kill-test-services bin/lint.sh bin/retest \
9+ bin/killservice bin/kill-test-services bin/retest \
10 bin/run bin/run-testapp bin/sprite-util bin/start_librarian \
11- bin/tags bin/test bin/tracereport bin/twistd bin/update-download-cache \
12- bin/watch_jsbuild
13+ bin/tags bin/test bin/tracereport bin/twistd \
14+ bin/watch_jsbuild bin/with-xvfb
15
16 BUILDOUT_TEMPLATES = buildout-templates/_pythonpath.py.in
17
18@@ -109,10 +109,10 @@
19 lp.services.mailman.tests
20
21 lint: ${PY}
22- @bash ./bin/lint.sh
23+ @bash ./utilities/lint
24
25 lint-verbose: ${PY}
26- @bash ./bin/lint.sh -v
27+ @bash ./utilities/lint -v
28
29 logs:
30 mkdir logs
31
32=== renamed file 'buildout-templates/bin/with-xvfb.in' => 'lib/lp/scripts/utilities/withxvfb.py'
33--- buildout-templates/bin/with-xvfb.in 2011-09-09 15:05:54 +0000
34+++ lib/lp/scripts/utilities/withxvfb.py 2017-01-21 13:43:34 +0000
35@@ -1,46 +1,42 @@
36-#!/bin/bash
37-#
38-# Copyright 2011 Canonical Ltd. This software is licensed under the
39+# Copyright 2011-2017 Canonical Ltd. This software is licensed under the
40 # GNU Affero General Public License version 3 (see the file LICENSE).
41-#
42-# Wrapper that provides a default Xvfb environment for the given
43-# command.
44-#
45-# If the command is not found it is searched for in the same directory
46-# as this script. This lets you do `bin/with-xvfb iharness` for
47-# example.
48-#
49-# Follows sinzui's advice to the launchpad-dev list:
50-# https://lists.launchpad.net/launchpad-dev/msg07879.html
51-#
52-
53-set -eu
54-
55-# Look for $1 - i.e. the command to run - in this script's directory
56-# if it's not found along the default PATH.
57-if [ $# -ge 1 ] && ! type -P "$1" > /dev/null
58-then
59- if command="$(PATH="$(dirname "$0")" type -P "$1")"
60- then
61- # Shift $1 off and set new positional arguments.
62- shift && set -- "$${command}" "$@"
63- fi
64-# If no command has been given and SHELL is set, spawn a shell.
65-elif [ $# -eq 0 -a -n "$${SHELL:-}" ]
66-then
67- set -- "$${SHELL}"
68-fi
69-
70-#
71-# --auto-servernum
72-# Try to get a free server number, starting at 99. See xvfb-run(1).
73-#
74-# --server-args=
75-# -ac disables host-based access control mechanisms. See Xserver(1).
76-# -screen forces a screen configuration. At the time of writing
77-# there is some disagreement between xvfb-run(1) and Xvfb(1)
78-# about what the default is.
79-#
80-exec xvfb-run \
81- --server-args="-ac -screen 0 1024x768x24" \
82- --auto-servernum -- "$@"
83+
84+"""Run a command with a default Xvfb environment
85+
86+If the command is not found it is searched for in the same directory as this
87+script. This lets you do `bin/with-xvfb iharness` for example.
88+
89+Follows sinzui's advice to the launchpad-dev list:
90+ https://lists.launchpad.net/launchpad-dev/msg07879.html
91+"""
92+
93+from __future__ import absolute_import, print_function, unicode_literals
94+
95+import os
96+import sys
97+
98+from lp.services.osutils import find_on_path
99+
100+
101+def main():
102+ # Look for the command to run in this script's directory if it's not
103+ # found along the default PATH.
104+ args = sys.argv[1:]
105+ if args and not find_on_path(args[0]):
106+ nearby = os.path.join(os.path.dirname(sys.argv[0]), args[0])
107+ if os.access(nearby, os.X_OK):
108+ args[0] = nearby
109+ # If no command has been given and SHELL is set, spawn a shell.
110+ elif not args and os.environ.get("SHELL"):
111+ args = [os.environ["SHELL"]]
112+
113+ args = [
114+ # -ac disables host-based access control mechanisms. See Xserver(1).
115+ # -screen forces a screen configuration. At the time of writing
116+ # there is some disagreement between xvfb-run(1) and Xvfb(1)
117+ # about what the default is.
118+ "--server-args=-ac -screen 0 1024x768x24",
119+ # Try to get a free server number, starting at 99. See xvfb-run(1).
120+ "--auto-servernum",
121+ ] + args
122+ os.execvp("xvfb-run", args)
123
124=== modified file 'setup.py'
125--- setup.py 2017-01-18 00:55:27 +0000
126+++ setup.py 2017-01-21 13:43:34 +0000
127@@ -177,6 +177,7 @@
128 'start_librarian = lp.scripts.runlaunchpad:start_librarian',
129 'twistd = twisted.scripts.twistd:run',
130 'watch_jsbuild = lp.scripts.utilities.js.watchjsbuild:main',
131+ 'with-xvfb = lp.scripts.utilities.withxvfb:main',
132 ]
133 ),
134 )
135
136=== renamed file 'buildout-templates/bin/lint.sh.in' => 'utilities/lint'
137--- buildout-templates/bin/lint.sh.in 2012-05-11 05:14:01 +0000
138+++ utilities/lint 2017-01-21 13:43:34 +0000
139@@ -1,20 +1,14 @@
140 #!/bin/bash
141 #
142-# Copyright 2009-2010 Canonical Ltd. This software is licensed under the
143+# Copyright 2009-2017 Canonical Ltd. This software is licensed under the
144 # GNU Affero General Public License version 3 (see the file LICENSE).
145 #
146 # Runs pocketlint on files changed from parent branch.
147
148
149-${shell-relative-path-setup}
150-
151-utilitiesdir=${buildout:directory/utilities|shell-path}
152-[ -z "$utilitiesdir" ] && utilitiesdir=.
153-
154-
155 if [ -z "$1" ]; then
156 # No command line argument provided, lint all changed files.
157- files=$($utilitiesdir/find-changed-files.sh)
158+ files=$($(dirname "$0")/find-changed-files.sh)
159 else
160 # Add newlines so grep filters out pyfiles correctly later.
161 files=`echo $* | tr " " "\n"`
162
163=== renamed file 'buildout-templates/bin/update-download-cache.in' => 'utilities/update-download-cache'
164--- buildout-templates/bin/update-download-cache.in 2010-04-20 19:10:35 +0000
165+++ utilities/update-download-cache 2017-01-21 13:43:34 +0000
166@@ -1,4 +1,3 @@
167-${shell-relative-path-setup}
168-
169-bzr up ${buildout:directory/buildout/download-cache|shell-path}
170-
171+#!/bin/sh
172+
173+bzr up "$(dirname "$0")/../download-cache"