Skip to content

Instantly share code, notes, and snippets.

@n8gray
Forked from buscarini/remove_sim_dups.py
Last active August 29, 2015 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save n8gray/24546b2b16195ce4bc59 to your computer and use it in GitHub Desktop.
Save n8gray/24546b2b16195ce4bc59 to your computer and use it in GitHub Desktop.
Remove Xcode duplicated simulators
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import re
from subprocess import Popen, PIPE
from subprocess import call
# Change this to True to see what will be deleted without deleting anything
DRY_RUN = False
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:
if block.startswith("--"):
print "Block:", block
foundSims = {}
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)
if foundSims.has_key(devicename):
idMatch = re.match(".*?\((.*?)\).*",line).group(1)
if DRY_RUN:
print "Would delete", line
else:
print "Deleting", line
call(["xcrun", "simctl", "delete", idMatch])
else:
foundSims[devicename] = True
print "Keeping", line
i = i+1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment