Merge pull request #1504 from penguinho/locale_fix

Fix Locale Settings for iOS > 7.0.0
This commit is contained in:
Dan Cuellar
2013-11-23 13:25:29 -08:00
2 changed files with 65 additions and 32 deletions

View File

@@ -366,12 +366,45 @@ IOS.prototype.setLocale = function(cb) {
var msg;
if (this.language || this.locale || this.calendarFormat) {
var iosSimLocalePath = path.resolve(__dirname, "../../../build/ios-sim-locale");
var cmd = iosSimLocalePath + ' -sdk ' + this.iOSSDKVersion;
logger.info("Changing the iOS Simulator language");
cmd = (this.language) ? cmd + ' -language ' + this.language : cmd;
cmd = (this.locale) ? cmd + ' -locale ' + this.locale : cmd;
cmd = (this.calendarFormat) ? cmd + ' -calendar ' + this.calendarFormat : cmd;
exec(cmd, { maxBuffer: 524288 }, cb);
if (fs.existsSync(iosSimLocalePath)) {
helpers.getiOSSimulatorDirectories(function(pathList) {
if (pathList.length < 1) {
msg = "Cannot set locale information because the iOS Simulator directory could not be determined.";
logger.error(msg);
cb(new Error(msg));
} else {
var localeInfoWasSet = false;
var setLanguageForPath = function(pathIndex) {
if (pathIndex >= pathList.length) {
if (localeInfoWasSet) {
cb();
} else {
msg = "Appium was unable to set locale info.";
logger.error(msg);
cb(new Error(msg));
}
} else {
var sdkVersion = pathList[pathIndex].split(path.sep).pop();
var cmd = iosSimLocalePath + ' -sdk ' + sdkVersion;
cmd = (this.language) ? cmd + ' -language ' + this.language : cmd;
cmd = (this.locale) ? cmd + ' -locale ' + this.locale : cmd;
cmd = (this.calendarFormat) ? cmd + ' -calendar ' + this.calendarFormat : cmd;
exec(cmd, { maxBuffer: 524288 }, function (err) {
if (err === null) {
localeInfoWasSet = true;
}
setLanguageForPath(pathIndex+1);
});
}
}.bind(this);
setLanguageForPath(0);
}
}.bind(this));
} else {
msg = "Could not set locale information because the ios-sim-local was not found at " + iosSimLocalePath;
logger.error(msg);
cb(new Error(msg));
}
} else {
cb();
}

View File

@@ -11,6 +11,7 @@ var logger = require('./server/logger.js').get('appium')
, util = require('util')
, os = require('os').type()
, tempdir = require('./tempdir')
, glob = require('glob')
, AdmZip = require('adm-zip');
@@ -402,38 +403,37 @@ exports.getXcodeVersion = function(cb) {
exports.getiOSSDKVersion = function(cb) {
var msg;
exports.getXcodeFolder(function(err, xcodeFolderPath) {
if (err) return cb(err);
if (xcodeFolderPath !== null) {
var sdkFolderPath = path.resolve(xcodeFolderPath,
"Platforms/iPhoneSimulator.platform/Developer/SDKs");
if (fs.existsSync(sdkFolderPath)) {
var sdkFolders = fs.readdirSync(sdkFolderPath).sort().reverse();
if (sdkFolders.length > 0) {
var match = sdkFolders[0].match(/\d\.\d/);
if (match) {
var sdkVersion = match[0];
cb(null, sdkVersion);
} else {
msg = "Could not determine sdk version number from sdk folder " + sdkFolders[0];
logger.error(msg);
cb(new Error(msg), null);
}
} else {
msg = "Did not find any SDKs at " + sdkFolderPath;
logger.error(msg);
cb(new Error(msg), null);
}
exec('xcrun --sdk iphonesimulator --show-sdk-version', { maxBuffer: 524288, timeout: 3000 }, function(err, stdout, stderr) {
if (!err) {
var iosSDKVersion = stdout.replace("\n", "");
var match = /\d.\d/.exec(iosSDKVersion);
if (match) {
cb(null, iosSDKVersion);
} else {
msg = "Could not find sdk folder path at " + sdkFolderPath;
msg ="xcrun returned a non-numeric iOS SDK version: " + iosSDKVersion;
logger.error(msg);
cb(new Error(msg), null);
}
} else {
msg = "Could not find the sdk folder path because XCode " +
"could not be found. Try setting the path with xcode-select.";
msg = "xcrun threw an error " + err;
logger.error(msg);
logger.error("Stderr: " + stderr);
logger.error("Stdout: " + stdout);
cb(new Error(msg), null);
}
}.bind(this));
});
};
exports.getiOSSimulatorDirectories = function(cb) {
var basePath = path.resolve(process.env.HOME, "Library", "Application Support",
"iPhone Simulator");
glob(basePath + "/*.*", function(err, pathList) {
if (err) {
var msg = "Could not find any directories for the iOS Simulator";
logger.error(msg);
cb(new Error(msg));
} else {
cb(pathList);
}
});
};