Skip to content

Commit

Permalink
Parse device info correctly from 3.2.0+ CLI, Choose iOS Simulator ver…
Browse files Browse the repository at this point in the history
…sion (5.0,6.1,7.0), List all iOS Simulators (iPad Retina etc), List and choose GenyMotion android devices
  • Loading branch information
Steven Senior authored and Steven Senior committed Feb 17, 2014
1 parent 77fa937 commit 1353002
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 26 deletions.
120 changes: 100 additions & 20 deletions Titanium.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@
import sublime_plugin
import json
import subprocess

#from pprint import pprint

class TitaniumCommand(sublime_plugin.WindowCommand):

def run(self, *args, **kwargs):
settings = sublime.load_settings('Titanium.sublime-settings')
self.cli = settings.get("titaniumCLI", "/usr/local/bin/titanium")
self.cli = settings.get("titaniumCLI", "/usr/bin/titanium")
self.android = settings.get("androidSDK", "/opt/android-sdk") + "/tools/android"
self.loggingLevel = settings.get("loggingLevel", "info")
self.simulatorDisplay = str(settings.get("simulatorDisplay", "--retina"))
self.simulatorHeight = str(settings.get("simulatorHeight", "--tall"))
self.iosVersion = str(settings.get("iosVersion", "unknown"))
self.simulatorDisplay = str(settings.get("simulatorDisplay", ""))
self.simulatorHeight = str(settings.get("simulatorHeight", ""))
self.iosVersion = str(settings.get("iosVersion", "7.0")) #7.0
self.iosSimVersion = str(settings.get("iosSimVersion", "6.1")) #7.0, 6.1, 5.0
self.genymotionCLI = str(settings.get("genymotionCLI", "/Applications/Genymotion Shell.app/Contents/MacOS/genyshell"))

folders = self.window.folders()
if len(folders) <= 0:
Expand Down Expand Up @@ -83,7 +85,7 @@ def select_platform(self, select):
self.targets = ["simulator", "device", "dist-appstore", "dist-adhoc"]
self.show_quick_panel(self.targets, self.select_ios_target)
elif self.platform == "android":
self.targets = ["emulator", "device", "dist-playstore"]
self.targets = ["GenyMotion", "emulator", "device", "dist-playstore"]
self.show_quick_panel(self.targets, self.select_android_target)
elif self.platform == "mobileweb":
self.targets = ["development", "production"]
Expand All @@ -103,8 +105,22 @@ def get_project_sdk_version(self):

def run_titanium(self, options=[]):
cmd = [self.cli, "build", "--sdk", self.project_sdk, "--project-dir", self.project_folder, "--no-colors", "--platform", self.platform, "--log-level", self.loggingLevel]

if (self.iosVersion is not "unknown" and self.iosVersion is not ""):
options.extend(["--ios-version", self.iosVersion])

if (self.iosSimVersion is not "unknown" and self.iosSimVersion is not ""):
options.extend(["--sim-version", self.iosSimVersion])
cmd.extend(options)

# save most recent command
global titaniumMostRecent
titaniumMostRecent = cmd

self.window.run_command("exec", {"cmd": cmd})

def run_genymotion(self, options=[]):
cmd = [self.cli, "build", "--sdk", self.project_sdk, "--project-dir", self.project_folder, "--no-colors", "--platform", self.platform, "--log-level", self.loggingLevel]
cmd.extend(options)

# save most recent command
Expand All @@ -131,13 +147,31 @@ def load_android_avds(self):
result, error = process.communicate()
self.avds = result.split()

def load_genymotion_vms(self):
cmd = '"' + self.genymotionCLI + '" -c "devices list" | grep ^[[:space:]] | grep [0-9] | grep "On" | awk -F\'|\' \'{ip=gsub(/^[ \\t]+|[ \\t]+$/, "", $5); name=gsub(/^[ \\t]+|[ \\t]+$/, "", $6); print $5","$6}\''
process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
result, error = process.communicate()

if result != '' and result != None:
l = []
for a in result.splitlines():
ip = a.split(',')[0]
name = a.split(',')[1]
l.append([name, ip])
self.genymotionvms = l
else:
sublime.error_message("No running GenyMotion devices found")

def select_android_target(self, select):
if select < 0:
return
target = self.targets[select]
if (target == "emulator"):
self.load_android_avds()
self.show_quick_panel(self.avds, self.select_android_avd)
elif (target == "GenyMotion"):
self.load_genymotion_vms();
self.show_quick_panel(self.genymotionvms, self.select_genymotion_vm)
else:
self.run_titanium(["--target", target])

Expand All @@ -146,6 +180,12 @@ def select_android_avd(self, select):
return
self.run_titanium(["--avd-id", self.avds[select]])

def select_genymotion_vm(self, select):
if select < 0:
return
self.genymotionname, self.genymotionip = self.genymotionvms[select]
self.run_genymotion(["--device-id", self.genymotionname])

#--------------------------------------------------------------
# IOS
#--------------------------------------------------------------
Expand All @@ -155,7 +195,7 @@ def select_ios_target(self, select):
return
self.target = self.targets[select]
if self.target == "simulator":
self.simtype = ["non-retina", "retina", "retina-tall", "ipad"]
self.simtype = ["iphone", "iphone-retina", "iphone-retina-tall", "ipad", "ipad-retina", "ipad-retina-tall"]
self.show_quick_panel(self.simtype, self.select_ios_simtype)
else:
self.families = ["iphone", "ipad", "universal"]
Expand All @@ -164,20 +204,44 @@ def select_ios_target(self, select):
def select_ios_simtype(self, select):
if select < 0:
return
if (self.simtype[select] == 'non-retina'):
if (self.simtype[select] == 'iphone'):
# iphone 4
simulatorType = 'iphone'
simulatorDisplay = ''
simulatorHeight = ''
elif (self.simtype[select] == "retina"):
elif (self.simtype[select] == "iphone-retina"):
simulatorType = 'iphone'
simulatorDisplay = self.simulatorDisplay
simulatorDisplay = '--retina'
simulatorHeight = ''
else:
elif (self.simtype[select] == "iphone-retina-tall"):
simulatorType = 'iphone'
simulatorDisplay = '--retina'
simulatorHeight = '--tall'
elif (self.simtype[select] == "ipad-retina"):
simulatorType = 'ipad'
simulatorDisplay = '--retina'
simulatorHeight = ''
elif (self.simtype[select] == "ipad-retina-tall"):
simulatorType = 'ipad'
simulatorDisplay = '--retina'
simulatorHeight = '--tall'
elif (self.simtype[select] == "ipad"):
simulatorType = self.simtype[select]
simulatorDisplay = self.simulatorDisplay
simulatorHeight = self.simulatorHeight
self.run_titanium(["--sim-type", simulatorType, simulatorDisplay, simulatorHeight])

self.simulatorType = simulatorType
self.simulatorDisplay = simulatorDisplay
self.simulatorHeight = simulatorHeight

self.simvers = ["7.0", "6.1", "5.0"]
self.show_quick_panel(self.simvers, self.select_ios_simversion)

def select_ios_simversion(self, select):
if select < 0:
return
self.iosSimVersion = self.simvers[select]
self.run_titanium(["--sim-type", self.simulatorType, self.simulatorDisplay, self.simulatorHeight])

def select_ios_family(self, select):
if select < 0:
Expand All @@ -190,15 +254,23 @@ def select_ios_cert(self, select):
if select < 0:
return
self.cert = self.certs[select]
self.show_quick_panel(self.devices, self.select_ios_device)

def select_ios_device(self, select):
if select < 0:
return
self.devicename, self.deviceudid = self.devices[select]
self.show_quick_panel(self.profiles, self.select_ios_profile)

def select_ios_profile(self, select):
if select < 0:
return
name, profile = self.profiles[select]
options = ["--target", self.target, "--pp-uuid", profile, "--device-family", self.family]

if self.target == "device":
options.extend(["--developer-name", self.cert])
options.extend(["--developer-name", self.cert[0]])
options.extend(["--device-id", self.deviceudid])
else:
options.extend(["--distribution-name", self.cert])

Expand All @@ -211,20 +283,28 @@ def load_ios_info(self):
process = subprocess.Popen([self.cli, "info", "--types", "ios", "--output", "json"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
result, error = process.communicate()
info = json.loads(result.decode('utf-8'))
for name, obj in list(info.items()):
if name == "iosCerts":
for target, c in list(obj.items()):
if target == "wwdr" or (target == "devNames" and self.target != "device") or (target == "distNames" and self.target == "device"):

for name, obj in list(info["ios"].items()):
if name == "certs":
for target, c in list(obj["keychains"]["/Users/stevensenior/Library/Keychains/login.keychain"].items()):
if target == "wwdr" or (target == "developer" and self.target != "device") or (target == "distribution" and self.target == "device"):
continue
l = []
for cert in c:
l.append(cert)
if cert['expired'] is False:
l.append([cert['name']])
self.certs = l
elif name == "iOSProvisioningProfiles":
elif name == "provisioningProfiles":
for target, p in list(obj.items()):
# TODO: figure out what to do with enterprise profiles
if (target == "development" and self.target == "device") or (target == "distribution" and self.target == "dist-appstore") or (target == "adhoc" and self.target == "dist-adhoc"):
l = []
for profile in p:
l.append([profile['name'], profile['uuid']])
if profile['expired'] is False:
l.append([profile['name'], profile['uuid']])
self.profiles = l
elif name == "devices":
l = []
for a in obj:
l.append([a['name'], a['udid']])
self.devices = l
12 changes: 6 additions & 6 deletions Titanium.sublime-settings
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
// Path to the Titanium CLI
"titaniumCLI": "/usr/local/bin/titanium",
"titaniumCLI": "/usr/bin/titanium",
// Logging Level [trace, debug, info, warn, error]
"loggingLevel": "info",
// Path to the android sdk
"androidSDK": "/opt/android-sdk",
"androidSDK": "~/Library/android-sdk-macosx",
// Extra Settings for the iOS Simulator
// If you dont want to set them, make the values empty
"simulatorDisplay": "--retina",
"simulatorHeight": "--tall",
"iosVersion": "" //eg. 6.1

//"simulatorDisplay": "",
//"simulatorHeight": "",
//"iosVersion": "" //eg. 6.1
"genymotionCLI": "/Applications/Genymotion Shell.app/Contents/MacOS/genyshell"
}

0 comments on commit 1353002

Please sign in to comment.