Created
June 21, 2016 15:24
-
-
Save dornad/e6479010d2c8bc4f67b46a8cad4ceae1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import re | |
from subprocess import Popen, PIPE | |
from subprocess import call | |
p = Popen(["xcrun","simctl","list","devices"], stdin=PIPE, stdout=PIPE, stderr=PIPE) | |
output, err = p.communicate(b"input data that is passed to subprocess' stdin") | |
blocks = re.split("--\s+(.*?)\s+--",output) | |
dic = {} | |
i=0 | |
for block in blocks: | |
matches = re.findall("iOS 8.4",block) | |
if len(matches)>0: | |
content = blocks[i+1] | |
lines = content.split("\n") | |
for line in lines: | |
line = line.strip() | |
if len(line)>0: | |
match = re.match("(.*?)\(",line) | |
if match: | |
devicename = match.group(1) | |
idMatch = re.match(".*?\((.*?)\).*",line) | |
dic[devicename] = idMatch.group(1) | |
call(["xcrun","simctl","delete",idMatch.group(1)]) | |
# print match.group(1) | |
# print line | |
i = i+1 | |
for guid in dic.itervalues(): | |
call(["xcrun","simctl","delete",guid]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment