Merge pull request #1417 from mrtcode/pdftools-test
Fix PDF tools usage in tests
This commit is contained in:
commit
ca9a7c685e
7 changed files with 98 additions and 20 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1,4 +1,5 @@
|
||||||
.DS_Store
|
.DS_Store
|
||||||
node_modules
|
node_modules
|
||||||
build
|
build
|
||||||
.signatures.json
|
.signatures.json
|
||||||
|
tmp
|
||||||
|
|
|
@ -26,8 +26,6 @@
|
||||||
Zotero.Fulltext = Zotero.FullText = new function(){
|
Zotero.Fulltext = Zotero.FullText = new function(){
|
||||||
this.isCachedMIMEType = isCachedMIMEType;
|
this.isCachedMIMEType = isCachedMIMEType;
|
||||||
|
|
||||||
this.__defineGetter__("pdfConverterName", function() { return 'pdftotext'; });
|
|
||||||
this.__defineGetter__("pdfInfoName", function() { return 'pdfinfo'; });
|
|
||||||
this.__defineGetter__("pdfConverterCacheFile", function () { return '.zotero-ft-cache'; });
|
this.__defineGetter__("pdfConverterCacheFile", function () { return '.zotero-ft-cache'; });
|
||||||
this.__defineGetter__("pdfInfoCacheFile", function () { return '.zotero-ft-info'; });
|
this.__defineGetter__("pdfInfoCacheFile", function () { return '.zotero-ft-info'; });
|
||||||
|
|
||||||
|
@ -54,11 +52,9 @@ Zotero.Fulltext = Zotero.FullText = new function(){
|
||||||
const kWbClassHWKatakanaLetter = 6;
|
const kWbClassHWKatakanaLetter = 6;
|
||||||
const kWbClassThaiLetter = 7;
|
const kWbClassThaiLetter = 7;
|
||||||
|
|
||||||
var _pdfConverterFileName = null;
|
|
||||||
var _pdfConverter = null; // nsIFile to executable
|
var _pdfConverter = null; // nsIFile to executable
|
||||||
var _pdfInfoFileName = null;
|
|
||||||
var _pdfInfo = null; // nsIFile to executable
|
var _pdfInfo = null; // nsIFile to executable
|
||||||
var _popplerDatadir = null;
|
var _pdfData = null;
|
||||||
|
|
||||||
var _idleObserverIsRegistered = false;
|
var _idleObserverIsRegistered = false;
|
||||||
var _idleObserverDelay = 30;
|
var _idleObserverDelay = 30;
|
||||||
|
@ -74,19 +70,19 @@ Zotero.Fulltext = Zotero.FullText = new function(){
|
||||||
this.decoder = Components.classes["@mozilla.org/intl/utf8converterservice;1"].
|
this.decoder = Components.classes["@mozilla.org/intl/utf8converterservice;1"].
|
||||||
getService(Components.interfaces.nsIUTF8ConverterService);
|
getService(Components.interfaces.nsIUTF8ConverterService);
|
||||||
|
|
||||||
_pdfConverterFileName = this.pdfConverterName;
|
let pdfConverterFileName = "pdftotext";
|
||||||
_pdfInfoFileName = this.pdfInfoName;
|
let pdfInfoFileName = "pdfinfo";
|
||||||
|
|
||||||
if (Zotero.isWin) {
|
if (Zotero.isWin) {
|
||||||
_pdfConverterFileName += '.exe';
|
pdfConverterFileName += '.exe';
|
||||||
_pdfInfoFileName += '.exe';
|
pdfInfoFileName += '.exe';
|
||||||
}
|
}
|
||||||
|
|
||||||
let dir = FileUtils.getFile('AChrom', []).parent;
|
let dir = FileUtils.getFile('AChrom', []).parent;
|
||||||
|
|
||||||
_popplerDatadir = dir.clone();
|
_pdfData = dir.clone();
|
||||||
_popplerDatadir.append('poppler-data');
|
_pdfData.append('poppler-data');
|
||||||
_popplerDatadir = _popplerDatadir.path;
|
_pdfData = _pdfData.path;
|
||||||
|
|
||||||
_pdfConverter = dir.clone();
|
_pdfConverter = dir.clone();
|
||||||
_pdfInfo = dir.clone();
|
_pdfInfo = dir.clone();
|
||||||
|
@ -99,8 +95,8 @@ Zotero.Fulltext = Zotero.FullText = new function(){
|
||||||
_pdfInfo.append('MacOS');
|
_pdfInfo.append('MacOS');
|
||||||
}
|
}
|
||||||
|
|
||||||
_pdfConverter.append(_pdfConverterFileName);
|
_pdfConverter.append(pdfConverterFileName);
|
||||||
_pdfInfo.append(_pdfInfoFileName);
|
_pdfInfo.append(pdfInfoFileName);
|
||||||
|
|
||||||
Zotero.uiReadyPromise.delay(30000).then(() => {
|
Zotero.uiReadyPromise.delay(30000).then(() => {
|
||||||
this.registerContentProcessor();
|
this.registerContentProcessor();
|
||||||
|
@ -135,6 +131,22 @@ Zotero.Fulltext = Zotero.FullText = new function(){
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
this.setPDFConverterPath = function(path) {
|
||||||
|
_pdfConverter = Zotero.File.pathToFile(path);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
this.setPDFInfoPath = function(path) {
|
||||||
|
_pdfInfo = Zotero.File.pathToFile(path);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
this.setPDFDataPath = function(path) {
|
||||||
|
_pdfData = path;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
this.getLibraryVersion = function (libraryID) {
|
this.getLibraryVersion = function (libraryID) {
|
||||||
if (!libraryID) throw new Error("libraryID not provided");
|
if (!libraryID) throw new Error("libraryID not provided");
|
||||||
return Zotero.DB.valueQueryAsync(
|
return Zotero.DB.valueQueryAsync(
|
||||||
|
@ -201,7 +213,7 @@ Zotero.Fulltext = Zotero.FullText = new function(){
|
||||||
this.getPDFConverterExecAndArgs = function () {
|
this.getPDFConverterExecAndArgs = function () {
|
||||||
return {
|
return {
|
||||||
exec: _pdfConverter,
|
exec: _pdfConverter,
|
||||||
args: ['-datadir', _popplerDatadir]
|
args: ['-datadir', _pdfData]
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -293,6 +293,9 @@ if(run) {
|
||||||
window.onload = function() {
|
window.onload = function() {
|
||||||
Zotero.spawn(function* () {
|
Zotero.spawn(function* () {
|
||||||
yield Zotero.Schema.schemaUpdatePromise;
|
yield Zotero.Schema.schemaUpdatePromise;
|
||||||
|
|
||||||
|
initPDFToolsPath();
|
||||||
|
|
||||||
return mocha.run();
|
return mocha.run();
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
|
@ -473,6 +473,37 @@ function getPromiseError(promise) {
|
||||||
return promise.thenReturn(false).catch(e => e);
|
return promise.thenReturn(false).catch(e => e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Init paths for PDF tools and data
|
||||||
|
*/
|
||||||
|
function initPDFToolsPath() {
|
||||||
|
let pdfConvertedFileName = 'pdftotext';
|
||||||
|
let pdfInfoFileName = 'pdfinfo';
|
||||||
|
|
||||||
|
if (Zotero.isWin) {
|
||||||
|
pdfConvertedFileName += '-win.exe';
|
||||||
|
pdfInfoFileName += '-win.exe';
|
||||||
|
}
|
||||||
|
else if (Zotero.isMac) {
|
||||||
|
pdfConvertedFileName += '-mac';
|
||||||
|
pdfInfoFileName += '-mac';
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
let cpu = Zotero.platform.split(' ')[1];
|
||||||
|
pdfConvertedFileName += '-linux-' + cpu;
|
||||||
|
pdfInfoFileName += '-linux-' + cpu;
|
||||||
|
}
|
||||||
|
|
||||||
|
let pdfToolsPath = OS.Path.join(Zotero.Profile.dir, 'pdftools');
|
||||||
|
let pdfConverterPath = OS.Path.join(pdfToolsPath, pdfConvertedFileName);
|
||||||
|
let pdfInfoPath = OS.Path.join(pdfToolsPath, pdfInfoFileName);
|
||||||
|
let pdfDataPath = OS.Path.join(pdfToolsPath, 'poppler-data');
|
||||||
|
|
||||||
|
Zotero.FullText.setPDFConverterPath(pdfConverterPath);
|
||||||
|
Zotero.FullText.setPDFInfoPath(pdfInfoPath);
|
||||||
|
Zotero.FullText.setPDFDataPath(pdfDataPath);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the nsIFile corresponding to the test data directory
|
* Returns the nsIFile corresponding to the test data directory
|
||||||
* (i.e., test/tests/data)
|
* (i.e., test/tests/data)
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
CWD="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||||
|
ROOT_DIR="$( cd "$( dirname "$SCRIPT_DIR" )" && pwd )"
|
||||||
|
|
||||||
case "$OSTYPE" in
|
case "$OSTYPE" in
|
||||||
msys*|mingw*|cygwin*) IS_CYGWIN=1 ;;
|
msys*|mingw*|cygwin*) IS_CYGWIN=1 ;;
|
||||||
|
@ -116,7 +117,7 @@ TEMPDIR="`mktemp -d 2>/dev/null || mktemp -d -t 'zotero-unit'`"
|
||||||
PROFILE="$TEMPDIR/profile"
|
PROFILE="$TEMPDIR/profile"
|
||||||
mkdir -p "$PROFILE/extensions"
|
mkdir -p "$PROFILE/extensions"
|
||||||
|
|
||||||
makePath ZOTERO_PATH "`dirname "$CWD"`/build"
|
makePath ZOTERO_PATH "$ROOT_DIR/build"
|
||||||
echo "$ZOTERO_PATH" > "$PROFILE/extensions/zotero@chnm.gmu.edu"
|
echo "$ZOTERO_PATH" > "$PROFILE/extensions/zotero@chnm.gmu.edu"
|
||||||
|
|
||||||
makePath ZOTERO_UNIT_PATH "$ZOTERO_PATH/test"
|
makePath ZOTERO_UNIT_PATH "$ZOTERO_PATH/test"
|
||||||
|
@ -125,6 +126,24 @@ echo "$ZOTERO_UNIT_PATH" > "$PROFILE/extensions/zotero-unit@zotero.org"
|
||||||
# Create data directory
|
# Create data directory
|
||||||
mkdir "$TEMPDIR/Zotero"
|
mkdir "$TEMPDIR/Zotero"
|
||||||
|
|
||||||
|
# Download PDF tools if not cached in the source directory and copy to profile directory
|
||||||
|
PDF_TOOLS_VERSION="0.0.1"
|
||||||
|
PDF_TOOLS_URL="https://zotero-download.s3.amazonaws.com/pdftools/pdftools-$PDF_TOOLS_VERSION.tar.gz"
|
||||||
|
PDF_TOOLS_CACHE_DIR="$ROOT_DIR/tmp/pdftools"
|
||||||
|
PDF_TOOLS_DIR="$PROFILE/pdftools"
|
||||||
|
if [ ! -f "$PDF_TOOLS_CACHE_DIR/$PDF_TOOLS_VERSION" ]; then
|
||||||
|
echo "Fetching PDF tools version $PDF_TOOLS_VERSION"
|
||||||
|
echo
|
||||||
|
rm -rf "$PDF_TOOLS_CACHE_DIR"
|
||||||
|
mkdir -p "$PDF_TOOLS_CACHE_DIR"
|
||||||
|
curl -o "$PDF_TOOLS_CACHE_DIR/pdftools.tar.gz" $PDF_TOOLS_URL
|
||||||
|
tar -zxf "$PDF_TOOLS_CACHE_DIR/pdftools.tar.gz" -C $PDF_TOOLS_CACHE_DIR
|
||||||
|
rm "$PDF_TOOLS_CACHE_DIR/pdftools.tar.gz"
|
||||||
|
touch "$PDF_TOOLS_CACHE_DIR/$PDF_TOOLS_VERSION"
|
||||||
|
echo
|
||||||
|
fi
|
||||||
|
cp -R $PDF_TOOLS_CACHE_DIR $PDF_TOOLS_DIR
|
||||||
|
|
||||||
cat <<EOF > "$PROFILE/prefs.js"
|
cat <<EOF > "$PROFILE/prefs.js"
|
||||||
user_pref("app.update.enabled", false);
|
user_pref("app.update.enabled", false);
|
||||||
user_pref("extensions.autoDisableScopes", 0);
|
user_pref("extensions.autoDisableScopes", 0);
|
||||||
|
@ -170,7 +189,7 @@ trap "{ rm -rf \"$TEMPDIR\"; }" EXIT
|
||||||
if [[ "$TRAVIS" != true ]] && ! ps | grep scripts/build.js | grep -v grep > /dev/null; then
|
if [[ "$TRAVIS" != true ]] && ! ps | grep scripts/build.js | grep -v grep > /dev/null; then
|
||||||
echo
|
echo
|
||||||
echo "Running JS build process"
|
echo "Running JS build process"
|
||||||
cd "$CWD/.."
|
cd "$ROOT_DIR"
|
||||||
npm run build || exit $?
|
npm run build || exit $?
|
||||||
echo
|
echo
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -5,6 +5,7 @@ describe("Zotero.Fulltext", function () {
|
||||||
// Hidden browser, which requires a browser window, needed for charset detection
|
// Hidden browser, which requires a browser window, needed for charset detection
|
||||||
// (until we figure out a better way)
|
// (until we figure out a better way)
|
||||||
win = yield loadBrowserWindow();
|
win = yield loadBrowserWindow();
|
||||||
|
initPDFToolsPath();
|
||||||
});
|
});
|
||||||
after(function () {
|
after(function () {
|
||||||
if (win) {
|
if (win) {
|
||||||
|
@ -133,7 +134,7 @@ describe("Zotero.Fulltext", function () {
|
||||||
toSync.push({
|
toSync.push({
|
||||||
item: pdfAttachment,
|
item: pdfAttachment,
|
||||||
content: "Zotero [zoh-TAIR-oh] is a free, easy-to-use tool to help you collect, "
|
content: "Zotero [zoh-TAIR-oh] is a free, easy-to-use tool to help you collect, "
|
||||||
+ "organize, cite, and share your research sources.\n\n",
|
+ "organize, cite, and share\nyour research sources.\n\n",
|
||||||
indexedChars: 0,
|
indexedChars: 0,
|
||||||
indexedPages: 1
|
indexedPages: 1
|
||||||
});
|
});
|
||||||
|
@ -175,6 +176,16 @@ describe("Zotero.Fulltext", function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("#setItemContent()", function () {
|
describe("#setItemContent()", function () {
|
||||||
|
before(() => {
|
||||||
|
// Disable PDF indexing
|
||||||
|
Zotero.Prefs.set('fulltext.pdfMaxPages', 0);
|
||||||
|
});
|
||||||
|
|
||||||
|
after(() => {
|
||||||
|
// Re-enable PDF indexing
|
||||||
|
Zotero.Prefs.clear('fulltext.pdfMaxPages');
|
||||||
|
});
|
||||||
|
|
||||||
it("should store data in .zotero-ft-unprocessed file", function* () {
|
it("should store data in .zotero-ft-unprocessed file", function* () {
|
||||||
var item = yield importFileAttachment('test.pdf');
|
var item = yield importFileAttachment('test.pdf');
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@ describe("PDF Recognition", function() {
|
||||||
yield Zotero.Promise.all([
|
yield Zotero.Promise.all([
|
||||||
loadZoteroPane().then(w => win = w)
|
loadZoteroPane().then(w => win = w)
|
||||||
]);
|
]);
|
||||||
|
initPDFToolsPath();
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(function* () {
|
beforeEach(function* () {
|
||||||
|
|
Loading…
Reference in a new issue