Skip to content

Instantly share code, notes, and snippets.

@alexflint
Created July 24, 2014 22:10
Show Gist options
  • Save alexflint/10d9a11532f17daf0bff to your computer and use it in GitHub Desktop.
Save alexflint/10d9a11532f17daf0bff to your computer and use it in GitHub Desktop.
Example of parsing arguments and calling into adb from python
#!/bin/env python
import os
import argparse
import subprocess
from pathlib import Path
def main():
argument_parser = argparse.ArgumentParser(description="Android unittest runner")
argument_parser.add_argument('--gtest_output', type=str)
argument_parser.add_argument('--sandbox_path', type=str)
argument_parser.add_argument('--resource_path', type=str)
argument_parser.add_argument('name', type=str)
args = argument_parser.parse_args()
try:
subprocess.check_call('adb shell mkdir '+args.sandbox_path, shell=True)
os.mkdir('/tmp/foo')
subprocess.check_call('adb push '+args.sandbox_path, shell=True)
except OSError as ex:
print 'adb command not found'
except subprocess.CalledProcessError as ex:
print 'Error was '+ex
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment