Only execute deploy.py when running as script
Change-Id: I40a1203cc2578517e7588b744bf93011f0e87ea3
diff --git a/deploy.py b/deploy.py
index 9b069c9..31495d6 100755
--- a/deploy.py
+++ b/deploy.py
@@ -114,52 +114,58 @@
dut.press.back()
dut.press.back()
-serials = []
-if len(sys.argv) > 1:
- serials.append(sys.argv[1])
-else:
- # List devices attached to adb
- ret = subprocess.run(
- "adb devices | grep -E '^[a-z0-9-]+\s+device$' | awk '{{print $1}}'",
- shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
- universal_newlines=True)
+def deploy():
+ serials = []
- if 0 < ret.returncode:
- # TODO handle the error
- raise Exception('Failed to list adb devices')
- elif ret.stdout:
- for line in ret.stdout.splitlines():
- serial = line.strip()
- if serial:
- serials.append(serial)
+ if len(sys.argv) > 1:
+ serials.append(sys.argv[1])
+ else:
+ # List devices attached to adb
+ ret = subprocess.run(
+ "adb devices | grep -E '^[a-z0-9-]+\s+device$' | awk '{{print $1}}'",
+ shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
+ universal_newlines=True)
-for serial in serials:
- print('Configuring device {}'.format(serial))
+ if 0 < ret.returncode:
+ # TODO handle the error
+ raise Exception('Failed to list adb devices')
+ elif ret.stdout:
+ for line in ret.stdout.splitlines():
+ serial = line.strip()
+ if serial:
+ serials.append(serial)
- dut = Device(serial)
+ for serial in serials:
+ print('Configuring device {}'.format(serial))
- # Push the scenarios, their data, and install the apps
- prepare_dut(serial, '../scenarios', '../scenarios-data', [
- '../../vendor/smartviser/viser/prebuilts/apk/com.smartviser.demogame.apk',
- '../../vendor/smartviser/viser/prebuilts/apk/com.lunarlabs.panda.proxy.apk',
- '../../vendor/smartviser/viser/prebuilts/apk/com.lunarlabs.panda.apk'
- ])
+ dut = Device(serial)
- # Start the viser app
- ret = subprocess.run(['adb', '-s', serial, 'shell', 'monkey', '-p',
- 'com.lunarlabs.panda', '-c', 'android.intent.category.LAUNCHER',
- '1'], stdout=subprocess.PIPE, stderr=subprocess.PIPE,
- universal_newlines=True)
- if 0 < ret.returncode:
- print('Could not start the viser app, error was: {}'.format(app,
- ret.stderr), file=sys.stderr)
- exit(-1)
+ # Push the scenarios, their data, and install the apps
+ prepare_dut(serial, '../scenarios', '../scenarios-data', [
+ '../../vendor/smartviser/viser/prebuilts/apk/com.smartviser.demogame.apk',
+ '../../vendor/smartviser/viser/prebuilts/apk/com.lunarlabs.panda.proxy.apk',
+ '../../vendor/smartviser/viser/prebuilts/apk/com.lunarlabs.panda.apk'
+ ])
- configure_perms(dut)
+ # Start the viser app
+ ret = subprocess.run(['adb', '-s', serial, 'shell', 'monkey', '-p',
+ 'com.lunarlabs.panda', '-c', 'android.intent.category.LAUNCHER',
+ '1'], stdout=subprocess.PIPE, stderr=subprocess.PIPE,
+ universal_newlines=True)
+ if 0 < ret.returncode:
+ print('Could not start the viser app, error was: {}'.format(app,
+ ret.stderr), file=sys.stderr)
+ exit(-1)
- # TODO DO NOT DO THE FOLLOWING IF NO SIM CARD IS IN THE DUT
- # time.sleep(10)
- # configure_sms(dut)
+ configure_perms(dut)
- configure_settings(dut)
+ # TODO DO NOT DO THE FOLLOWING IF NO SIM CARD IS IN THE DUT
+ # time.sleep(10)
+ # configure_sms(dut)
+
+ configure_settings(dut)
+
+
+if __name__ == '__main__':
+ deploy()