Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#! /usr/bin/env ruby
require 'rexml/document'
# File path : device_set.plist
DEVICE_SET_PLIST="#{Dir.home}/Library/Developer/CoreSimulator/Devices/device_set.plist"
SQLITE_LIST = "#{Dir.home}/Library/Developer/CoreSimulator/Devices/*/data/Containers/Data/Application/*/Documents/*.sqlite"
# Device information
class Device
def initialize(os, model)
@os = os
@model = model
end
attr_reader :os, :model
def to_s()
sprintf("%s %s", os , model)
end
end
# This class hold all device information of defined by device_set.plist
class DeviceHolder
def initialize()
@device = {}
end
def push(id, os, model)
@device[id] = Device.new(os, model)
end
def get(id)
@device[id]
end
def ids
@device.key
end
def to_s(id)
get(id).to_s
end
end
class DeviceSetPlistReader
def initialize(filename)
@filename = filename
@holder = DeviceHolder.new
end
def execute
doc = REXML::Document.new(open(@filename))
default_device = doc.root.elements['dict/dict']
os_name = nil
default_device.elements.each do |el|
if 'key' == el.name
os_name = trimming(el.text)
elsif 'dict' == el.name
read_device_id(el, os_name)
end
end
@holder
end
private
def trimming(text)
text.split('.').last
end
def read_device_id(target, os_name)
# Ex.
# <key>com.apple.CoreSimulator.SimDeviceType.Resizable-iPad</key>
# <string>DEVICE_ID1</string>
# <key>com.apple.CoreSimulator.SimDeviceType.Resizable-iPhone</key>
# <string>DEVICE_ID2</string>
model = nil
target.elements.each do |el|
if 'key' == el.name
model = trimming(el.text)
elsif 'string' == el.name
@holder.push(el.text, os_name, model)
end
end
end
end
#### Start process
reader = DeviceSetPlistReader.new(DEVICE_SET_PLIST)
holder = reader.execute
Dir.glob(SQLITE_LIST).sort{|x,y| -1*(File::stat(x) <=> File::stat(y))}.each do |file|
dirs = file.split('/')
device_id = dirs[-8] # Device ID is in the 8th from behind.
application_name = dirs[-1].sub(/.sqlite$/, '')
printf("%s\n %s\n %s\n", application_name, holder.to_s(device_id), file)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.