-Retrieve trunk translators from repo

-Make translator tester always re-retrieve translators that were previously retrieved from repo
This commit is contained in:
Simon Kornblith 2011-06-30 23:05:15 +00:00
parent 1d72849d99
commit ca1e3f8647
3 changed files with 45 additions and 32 deletions

View file

@ -29,6 +29,9 @@ Zotero.Repo = new function() {
var _timeoutID; var _timeoutID;
const infoRe = /^\s*{[\S\s]*?}\s*?[\r\n]/; const infoRe = /^\s*{[\S\s]*?}\s*?[\r\n]/;
this.SOURCE_ZOTERO_STANDALONE = 1;
this.SOURCE_REPO = 2;
/** /**
* Try to retrieve translator metadata from Zotero Standalone and initialize repository check * Try to retrieve translator metadata from Zotero Standalone and initialize repository check
* timer * timer
@ -58,13 +61,14 @@ Zotero.Repo = new function() {
// try standalone // try standalone
Zotero.Connector.callMethod("getTranslatorCode", {"translatorID":translatorID}, function(result) { Zotero.Connector.callMethod("getTranslatorCode", {"translatorID":translatorID}, function(result) {
if(result) { if(result) {
_haveCode(result, translatorID, callback); _haveCode(result, translatorID, Zotero.Repo.SOURCE_ZOTERO_STANDALONE, callback);
return; return;
} }
// then try repo // then try repo
Zotero.HTTP.doGet(ZOTERO_CONFIG.REPOSITORY_URL+"/code/"+translatorID, function(xmlhttp) { Zotero.HTTP.doGet(ZOTERO_CONFIG.REPOSITORY_URL+"/code/"+ZOTERO_CONFIG.REPOSITORY_CHANNEL+"/"+translatorID, function(xmlhttp) {
_haveCode(xmlhttp.status === 200 ? xmlhttp.responseText : false, translatorID, callback); _haveCode(xmlhttp.status === 200 ? xmlhttp.responseText : false, translatorID,
Zotero.Repo.SOURCE_REPO, callback);
}); });
}); });
}; };
@ -72,7 +76,7 @@ Zotero.Repo = new function() {
/** /**
* Called when code has been retrieved from standalone or repo * Called when code has been retrieved from standalone or repo
*/ */
function _haveCode(code, translatorID, callback) { function _haveCode(code, translatorID, source, callback) {
if(!code) { if(!code) {
Zotero.logError(new Error("Code could not be retrieved for " + translatorID)); Zotero.logError(new Error("Code could not be retrieved for " + translatorID));
callback(false); callback(false);
@ -112,7 +116,7 @@ Zotero.Repo = new function() {
} }
} }
} }
callback(code); callback(code, source);
} }
/** /**

View file

@ -110,7 +110,8 @@ Zotero.Translators = new function() {
} }
// only need to get code if it is of some use // only need to get code if it is of some use
if(translator.runMode === Zotero.Translator.RUN_MODE_IN_BROWSER) { if(translator.runMode === Zotero.Translator.RUN_MODE_IN_BROWSER
&& !translator.hasOwnProperty("code")) {
translator.getCode(function() { callback(translator) }); translator.getCode(function() { callback(translator) });
} else { } else {
callback(translator); callback(translator);
@ -120,14 +121,16 @@ Zotero.Translators = new function() {
/** /**
* Gets all translators for a specific type of translation * Gets all translators for a specific type of translation
* @param {String} type The type of translators to get (import, export, web, or search) * @param {String} type The type of translators to get (import, export, web, or search)
* @param {Function} [callback] An optional callback to be executed when translators have been * @param {Function} callback A required callback to be executed when translators have been
* retrieved. If no callback is specified, translators are * retrieved.
* returned. * @param {Boolean} [debugMode] Whether to assume debugging mode. If true, code is included for
* unsupported translators, and code originally retrieved from the
* repo is re-retrieved from Zotero Standalone.
*/ */
this.getAllForType = function(type, callback, includeUnsupported) { this.getAllForType = function(type, callback, debugMode) {
if(!_initialized) Zotero.Translators.init() if(!_initialized) Zotero.Translators.init()
var translators = _cache[type].slice(0); var translators = _cache[type].slice(0);
new Zotero.Translators.CodeGetter(translators, callback, translators, includeUnsupported); new Zotero.Translators.CodeGetter(translators, callback, translators, debugMode);
return true; return true;
} }
@ -325,13 +328,13 @@ Zotero.Translators = new function() {
* @param {Zotero.Translator[]} translators Translators for which to retrieve code * @param {Zotero.Translator[]} translators Translators for which to retrieve code
* @param {Function} callback Callback to call once code has been retrieved * @param {Function} callback Callback to call once code has been retrieved
* @param {Function} callbackArgs All arguments to be passed to callback (including translators) * @param {Function} callbackArgs All arguments to be passed to callback (including translators)
* @param {Boolean} [includeUnsupported] If true, include code for unsupported translators * @param {Boolean} [debugMode] If true, include code for unsupported translators
*/ */
Zotero.Translators.CodeGetter = function(translators, callback, callbackArgs, includeUnsupported) { Zotero.Translators.CodeGetter = function(translators, callback, callbackArgs, debugMode) {
this._translators = translators; this._translators = translators;
this._callbackArgs = callbackArgs; this._callbackArgs = callbackArgs;
this._callback = callback; this._callback = callback;
this._includeUnsupported = includeUnsupported; this._debugMode = debugMode;
this.getCodeFor(0); this.getCodeFor(0);
} }
@ -344,9 +347,17 @@ Zotero.Translators.CodeGetter.prototype.getCodeFor = function(i) {
return; return;
} }
if(this._translators[i].runMode === Zotero.Translator.RUN_MODE_IN_BROWSER || this._includeUnsupported) { var translator = this._translators[i];
// get next translator
this._translators[i].getCode(function() { me.getCodeFor(i+1) }); // retrieve code if no code and translator is supported locally
if((translator.runMode === Zotero.Translator.RUN_MODE_IN_BROWSER && !translator.hasOwnProperty("code"))
// or if debug mode is enabled (even if unsupported locally)
|| (this._debugMode && (!translator.hasOwnProperty("code")
// or if in debug mode and the code we have came from the repo (which doesn't
// include test cases)
|| translator.codeSource === Zotero.Repo.SOURCE_REPO))) {
// get next translator
translator.getCode(function() { me.getCodeFor(i+1) });
return; return;
} }
@ -439,22 +450,19 @@ Zotero.Translator.prototype.init = function(info) {
* Retrieves code for this translator * Retrieves code for this translator
*/ */
Zotero.Translator.prototype.getCode = function(callback) { Zotero.Translator.prototype.getCode = function(callback) {
if(this.code) { var me = this;
callback(true); Zotero.Repo.getTranslatorCode(this.translatorID,
} else { function(code, source) {
var me = this; if(!code) {
Zotero.Repo.getTranslatorCode(this.translatorID, callback(false);
function(code) { } else {
if(!code) { // cache code for session only (we have standalone anyway)
callback(false); me.code = code;
} else { me.codeSource = source;
// cache code for session only (we have standalone anyway) callback(true);
me.code = code;
callback(true);
}
} }
); }
} );
} }
Zotero.Translator.prototype.__defineGetter__("displayOptions", function() { Zotero.Translator.prototype.__defineGetter__("displayOptions", function() {

View file

@ -29,6 +29,7 @@ const ZOTERO_CONFIG = {
REPOSITORY_URL: 'https://repo.zotero.org/repo', REPOSITORY_URL: 'https://repo.zotero.org/repo',
REPOSITORY_CHECK_INTERVAL: 86400, // 24 hours REPOSITORY_CHECK_INTERVAL: 86400, // 24 hours
REPOSITORY_RETRY_INTERVAL: 3600, // 1 hour REPOSITORY_RETRY_INTERVAL: 3600, // 1 hour
REPOSITORY_CHANNEL: 'trunk',
BASE_URI: 'http://zotero.org/', BASE_URI: 'http://zotero.org/',
WWW_BASE_URL: 'http://www.zotero.org/', WWW_BASE_URL: 'http://www.zotero.org/',
SYNC_URL: 'https://sync.zotero.org/', SYNC_URL: 'https://sync.zotero.org/',