Commit c3e618fe authored by Ian Fischer's avatar Ian Fischer

Add a clear flag for sky_tool logs on Android.

parent aa8942f4
...@@ -151,6 +151,8 @@ class SkyLogs(object): ...@@ -151,6 +151,8 @@ class SkyLogs(object):
def add_subparser(self, subparsers): def add_subparser(self, subparsers):
logs_parser = subparsers.add_parser('logs', logs_parser = subparsers.add_parser('logs',
help='Show logs for running Sky apps') help='Show logs for running Sky apps')
logs_parser.add_argument('--clear', action='store_true', dest='clear_logs',
help='Clear log history before reading from logs (currently only implemented for Android)')
logs_parser.set_defaults(func=self.run) logs_parser.set_defaults(func=self.run)
def run(self, args, pids): def run(self, args, pids):
...@@ -160,13 +162,13 @@ class SkyLogs(object): ...@@ -160,13 +162,13 @@ class SkyLogs(object):
android = AndroidDevice() android = AndroidDevice()
if android.is_connected(): if android.is_connected():
android_log_reader = android.logs() android_log_reader = android.logs(args.clear_logs)
if IOSDevice.is_connected(): if IOSDevice.is_connected():
ios_dev_log_reader = IOSDevice.logs() ios_dev_log_reader = IOSDevice.logs(args.clear_logs)
if IOSSimulator.is_connected(): if IOSSimulator.is_connected():
ios_sim_log_reader = IOSSimulator.logs() ios_sim_log_reader = IOSSimulator.logs(args.clear_logs)
if android_log_reader is not None: if android_log_reader is not None:
try: try:
...@@ -488,8 +490,17 @@ class AndroidDevice(object): ...@@ -488,8 +490,17 @@ class AndroidDevice(object):
logging.info(' '.join(cmd)) logging.info(' '.join(cmd))
subprocess.check_output(cmd) subprocess.check_output(cmd)
def logs(self): def logs(self, clear=False):
def do_logs(): def do_logs():
if clear:
cmd = [
self.adb_path,
'logcat',
'-c'
]
logging.info(' '.join(cmd))
subprocess.check_call(cmd)
cmd = [ cmd = [
self.adb_path, self.adb_path,
'logcat', 'logcat',
...@@ -603,7 +614,7 @@ class IOSDevice(object): ...@@ -603,7 +614,7 @@ class IOSDevice(object):
pass pass
@classmethod @classmethod
def logs(cls): def logs(cls, clear=False):
try: try:
cmd = [ cmd = [
'which', 'which',
...@@ -734,7 +745,7 @@ class IOSSimulator(object): ...@@ -734,7 +745,7 @@ class IOSSimulator(object):
return cls.is_booted() return cls.is_booted()
@classmethod @classmethod
def logs(cls): def logs(cls, clear=False):
def do_logs(): def do_logs():
cmd = [ cmd = [
'tail', 'tail',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment