Merge lp:~sergiusens/phablet-tools/common_scripts into lp:phablet-tools

Proposed by Sergio Schvezov
Status: Merged
Approved by: Oliver Grawert
Approved revision: 272
Merged at revision: 273
Proposed branch: lp:~sergiusens/phablet-tools/common_scripts
Merge into: lp:phablet-tools
Diff against target: 288 lines (+86/-45)
5 files modified
phablet-network (+29/-26)
phablet-screenshot (+6/-14)
phablet-test-run (+17/-5)
setup.py (+5/-0)
shell-adb-common.sh (+29/-0)
To merge this branch: bzr merge lp:~sergiusens/phablet-tools/common_scripts
Reviewer Review Type Date Requested Status
Oliver Grawert Approve
Andy Doan Pending
Review via email: mp+219520@code.launchpad.net

Commit message

Adding a common script to ref from other scripts and removing ADBOPTS in favor of ANDROID_SERIAL
Fixing minor whitespace issues

To post a comment you must log in.
Revision history for this message
Oliver Grawert (ogra) wrote :

looks good ...

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'phablet-network'
2--- phablet-network 2014-04-14 20:48:07 +0000
3+++ phablet-network 2014-05-14 13:06:51 +0000
4@@ -14,6 +14,12 @@
5 #
6 # Copyright (C) 2012 Canonical, Ltd.
7
8+if [ -f "$(dirname $0)/shell-adb-common.sh" ]; then
9+ . "$(dirname $0)/shell-adb-common.sh"
10+else
11+ . "/usr/share/phabletutils/shell-adb-common.sh"
12+fi
13+
14 export LC_ALL=C
15
16 usage() {
17@@ -24,7 +30,7 @@
18
19 OPTIONS:
20 -h Show this message
21- -s Specify the serial of the device to install (see adb $ADBOPTS devices)
22+ -s Specify the serial of the device to install
23 -n Select network file
24 -t Timeout for waiting on network connection to become active.
25 Default=$WAIT_TIMEOUT
26@@ -35,7 +41,6 @@
27 EOF
28 }
29
30-ADBOPTS=""
31 OPTION_NETWORK_FILE=""
32 SKIP_SETUP=""
33 SKIP_WAIT=""
34@@ -55,26 +60,26 @@
35 ;;
36 -n)
37 shift;
38- OPTION_NETWORK_FILE=$1
39- shift;
40- ;;
41- -s)
42- shift;
43- ADBOPTS="-s $1"
44- shift;
45- ;;
46- -t|--timeout)
47+ OPTION_NETWORK_FILE=$1
48+ shift;
49+ ;;
50+ -s)
51+ shift;
52+ SERIAL="$1"
53+ shift;
54+ ;;
55+ -t|--timeout)
56 shift;
57 WAIT_TIMEOUT=$1
58 shift;
59 ;;
60- --skip-wait)
61+ --skip-wait)
62 shift;
63- SKIP_WAIT=1
64+ SKIP_WAIT=1
65 ;;
66- --skip-setup)
67+ --skip-setup)
68 shift;
69- SKIP_SETUP=1
70+ SKIP_SETUP=1
71 ;;
72 --)
73 shift;
74@@ -83,6 +88,11 @@
75 esac
76 done
77
78+
79+# exporting ANDROID_SERIAL to support multiple devices connected
80+# seamlessly
81+[ -z "$SERIAL" ] || export ANDROID_SERIAL="$SERIAL"
82+
83 NETWORK_MANAGER=/etc/NetworkManager/system-connections
84
85 find_active_network() {
86@@ -125,8 +135,8 @@
87
88 echo Provisioning network file to device
89 target_network_file=$NETWORK_MANAGER/active_ws_connection.conf
90- adb $ADBOPTS push $TMP_FILE $target_network_file
91- adb $ADBOPTS shell "chmod 600 $target_network_file"
92+ adb push $TMP_FILE $target_network_file
93+ adb shell "chmod 600 $target_network_file"
94
95 rm -f $TMP_FILE
96
97@@ -142,7 +152,7 @@
98 # the logic below will ensure that DNS resolution part of the
99 # ping worked, which should be enough to prove to us that the
100 # network stack is ready
101- if adb $ADBOPTS shell ping -c1 launchpad.net | grep PING ; then
102+ if adb shell ping -c1 launchpad.net | grep PING ; then
103 exit 0
104 fi
105 done
106@@ -153,14 +163,7 @@
107 fi
108 }
109
110-# Quick way to make sure that we fail gracefully if more than one device
111-# is connected and no serial is passed
112-err="$(adb $ADBOPTS wait-for-device 2>&1)"
113-if [ "$err" = "error: more than one device and emulator" ]; then
114- echo "$err"
115- adb devices
116- exit 1
117-fi
118+check_devices
119
120 [ -n "$SKIP_SETUP" ] || setup_connection
121 [ -n "$SKIP_WAIT" ] || wait_for_network
122
123=== modified file 'phablet-screenshot'
124--- phablet-screenshot 2014-05-08 12:44:41 +0000
125+++ phablet-screenshot 2014-05-14 13:06:51 +0000
126@@ -22,6 +22,12 @@
127 # Street, Fifth Floor, Boston, MA 02110-1301 USA
128 set -eu
129
130+if [ -f "$(dirname $0)/shell-adb-common.sh" ]; then
131+ . "$(dirname $0)/shell-adb-common.sh"
132+else
133+ . "/usr/share/phabletutils/shell-adb-common.sh"
134+fi
135+
136 PICDIR=$(mktemp -d /tmp/$(basename $0).XXXXXX)
137 FBDEV=fb0
138 SERIAL=""
139@@ -78,20 +84,6 @@
140 fi
141 }
142
143-check_devices() {
144- # Quick way to make sure that we fail gracefully if more than one device
145- # is connected and no serial is passed
146- set +e
147- adb wait-for-device
148- err=$?
149- set -e
150- if [ $err != 0 ]; then
151- echo "E: more than one device or emulator"
152- adb devices
153- exit 1
154- fi
155-}
156-
157 sf_is_running() {
158 # Return 0 if surface flinger is running then we'll use screencap
159 # instead
160
161=== modified file 'phablet-test-run'
162--- phablet-test-run 2014-04-01 01:36:31 +0000
163+++ phablet-test-run 2014-05-14 13:06:51 +0000
164@@ -14,6 +14,12 @@
165 #
166 # Copyright (C) 2012 Canonical, Ltd.
167
168+if [ -f "$(dirname $0)/shell-adb-common.sh" ]; then
169+ . "$(dirname $0)/shell-adb-common.sh"
170+else
171+ . "/usr/share/phabletutils/shell-adb-common.sh"
172+fi
173+
174 TESTSUITE=""
175 TESTPACKAGES=""
176 LOCALPACKAGES=""
177@@ -24,7 +30,6 @@
178
179 EXECUTE_COMMAND=0
180 USER=phablet
181-ADBOPTS=""
182 NOSHELL=0
183 RETVAL=0
184 VERBOSE=""
185@@ -53,15 +58,15 @@
186 }
187
188 wait_for_device() {
189- adb $ADBOPTS wait-for-device
190+ adb wait-for-device
191 }
192
193 exec_with_adb() {
194- adb $ADBOPTS shell /usr/bin/env -i PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin "$@"
195+ adb shell /usr/bin/env -i PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin "$@"
196 }
197
198 exec_with_adb_user() {
199- adb $ADBOPTS shell sudo -u $USER -i "$@"
200+ adb shell sudo -u $USER -i "$@"
201 }
202
203 install_packages() {
204@@ -196,7 +201,7 @@
205 TESTPACKAGES="$TESTPACKAGES $OPTARG"
206 ;;
207 s)
208- ADBOPTS="-s $OPTARG"
209+ SERIAL="$OPTARG"
210 ;;
211 x)
212 EXECUTE_COMMAND=1
213@@ -209,12 +214,19 @@
214
215 shift $((OPTIND - 1))
216
217+
218+# exporting ANDROID_SERIAL to support multiple devices connected
219+# seamlessly
220+[ -z "$SERIAL" ] || export ANDROID_SERIAL="$SERIAL"
221+
222 TESTSUITE=$@
223 if test -z "$TESTSUITE"; then
224 echo To run a test please specify a test suite
225 exit 0
226 fi
227
228+check_devices
229+
230 install_packages
231
232 if [ $NOSHELL -eq 1 ]; then
233
234=== modified file 'setup.py'
235--- setup.py 2014-04-05 17:01:01 +0000
236+++ setup.py 2014-05-14 13:06:51 +0000
237@@ -20,6 +20,10 @@
238 'phablet-bootchart',
239 ]
240
241+DATA_FILES = [
242+ ('/usr/share/phabletutils/', ['shell-adb-common.sh', ]),
243+ ]
244+
245 if __name__ == "__main__":
246 setup(
247 name='phablet-tools',
248@@ -30,5 +34,6 @@
249 license='GPLv3',
250 packages=find_packages(exclude=("tests",)),
251 scripts=PYTHON_SCRIPTS + SH_SCRIPTS,
252+ data_files=DATA_FILES,
253 test_suite='tests',
254 )
255
256=== added file 'shell-adb-common.sh'
257--- shell-adb-common.sh 1970-01-01 00:00:00 +0000
258+++ shell-adb-common.sh 2014-05-14 13:06:51 +0000
259@@ -0,0 +1,29 @@
260+#!/bin/sh
261+# This program is free software: you can redistribute it and/or modify it
262+# under the terms of the the GNU General Public License version 3, as
263+# published by the Free Software Foundation.
264+#
265+# This program is distributed in the hope that it will be useful, but
266+# WITHOUT ANY WARRANTY; without even the implied warranties of
267+# MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
268+# PURPOSE. See the applicable version of the GNU General Public
269+# License for more details.
270+#.
271+# You should have received a copy of the GNU General Public License
272+# along with this program. If not, see <http://www.gnu.org/licenses/>.
273+#
274+# Copyright (C) 2014 Canonical, Ltd.
275+
276+check_devices() {
277+ # Quick way to make sure that we fail gracefully if more than one device
278+ # is connected and no serial is passed
279+ set +e
280+ adb wait-for-device
281+ err=$?
282+ set -e
283+ if [ $err != 0 ]; then
284+ echo "E: more than one device or emulator"
285+ adb devices
286+ exit 1
287+ fi
288+}

Subscribers

People subscribed via source and target branches