Skip to content

Commit

Permalink
Some coding style
Browse files Browse the repository at this point in the history
  • Loading branch information
viincenb committed Oct 11, 2018
1 parent 96a5ce9 commit dcb713d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 32 deletions.
54 changes: 27 additions & 27 deletions lib/converter.js
Expand Up @@ -427,11 +427,11 @@ function detectLibreOffice (additionalPaths) {
// Try finding a Python binary shipped alongside the soffice binary,
// either in its actual directory, or - if it's a symbolic link -
// in the directory it points to.
var symlinkDestination;
var _symlinkDestination;
try {
symlinkDestination = path.resolve(path.dirname(sofficePath), fs.readlinkSync(sofficePath));
_symlinkDestination = path.resolve(path.dirname(sofficePath), fs.readlinkSync(sofficePath));
// Assume symbolic link, will throw in case it's not:
sofficeActualDirectory = path.dirname(symlinkDestination);
sofficeActualDirectory = path.dirname(_symlinkDestination);
} catch (errorToIgnore) {
// Not a symlink.
sofficeActualDirectory = path.dirname(sofficePath);
Expand All @@ -446,13 +446,13 @@ function detectLibreOffice (additionalPaths) {
}

function _findBinaries(paths, pythonName, sofficeName) {
var whichPython;
var whichSoffice;
var sofficeActualDirectory;
var _whichPython;
var _whichSoffice;
var _sofficeActualDirectory;
// Look for the soffice binary - first in the well-known paths, then in
// the system PATH. On Linux, this prioritizes "upstream" (TDF) packages
// over distro-provided ones from the OS' repository.
whichSoffice = which.sync(sofficeName, { path: paths.join(':'), nothrow: true }) || which.sync(sofficeName, { nothrow: true }) || null;
_whichSoffice = which.sync(sofficeName, { path: paths.join(':'), nothrow: true }) || which.sync(sofficeName, { nothrow: true }) || null;
// Check for a Python binary bundled with soffice, fall back to system-wide:
// This is a bit more complex, since we deal with some corner cases.
// 1. Hopefully use the python from the original soffice package, same dir
Expand All @@ -465,15 +465,15 @@ function detectLibreOffice (additionalPaths) {
// This is only attempted if the paths exist on this system to avoid
// a fallback to system PATH that "which" does when passed an empty string.
// 3. Fall back to system python (hopefully named python3).
whichPython = _findBundledPython(whichSoffice, 'python3') ||
_findBundledPython(whichSoffice, 'python') ||
_whichPython = _findBundledPython(_whichSoffice, 'python3') ||
_findBundledPython(_whichSoffice, 'python') ||
(paths.length > 0 && which.sync('python3', { path: paths.join(':'), nothrow: true })) ||
(paths.length > 0 && which.sync('python', { path: paths.join(':'), nothrow: true })) ||
which.sync('python3', { nothrow: true }) ||
which.sync('python', { nothrow: true }) || null;
return {
soffice: whichSoffice,
python: whichPython
soffice: _whichSoffice,
python: _whichPython
};
}

Expand All @@ -489,15 +489,15 @@ function detectLibreOffice (additionalPaths) {
}
}

var pathsToCheck = additionalPaths || [];
var _pathsToCheck = additionalPaths || [];
// overridable file names to look for in the checked paths:
var pythonName = 'python';
var sofficeName = 'soffice';
var linuxDirnamePattern = /^libreoffice\d+\.\d+$/;
var windowsDirnamePattern = /^LibreOffice \d+(?:\.\d+)?$/i;
var _pythonName = 'python';
var _sofficeName = 'soffice';
var _linuxDirnamePattern = /^libreoffice\d+\.\d+$/;
var _windowsDirnamePattern = /^LibreOffice \d+(?:\.\d+)?$/i;

if (process.platform === 'darwin') {
pathsToCheck = pathsToCheck.concat([
_pathsToCheck = _pathsToCheck.concat([
// It is better to use the python bundled with LibreOffice:
'/Applications/LibreOffice.app/Contents/MacOS',
'/Applications/LibreOffice.app/Contents/Resources'
Expand All @@ -507,25 +507,25 @@ function detectLibreOffice (additionalPaths) {
// The Document Foundation packages (.debs, at least) install to /opt,
// into a directory named after the contained LibreOffice version.
// Add any existing directories that match this to the list.
pathsToCheck = pathsToCheck.concat(_listProgramDirectories('/opt', linuxDirnamePattern));
_pathsToCheck = _pathsToCheck.concat(_listProgramDirectories('/opt', _linuxDirnamePattern));
}
else if (process.platform === 'win32') {
pathsToCheck = pathsToCheck
.concat(_listProgramDirectories('C:\\Program Files', windowsDirnamePattern))
.concat(_listProgramDirectories('C:\\Program Files (x86)', windowsDirnamePattern));
pythonName = 'python.exe';
_pathsToCheck = _pathsToCheck
.concat(_listProgramDirectories('C:\\Program Files', _windowsDirnamePattern))
.concat(_listProgramDirectories('C:\\Program Files (x86)', _windowsDirnamePattern));
_pythonName = 'python.exe';
}
else {
debug('your platform "%s" is not supported yet', process.platform);
}

// Common logic for all OSes: perform the search and save results as options:
var foundPaths = _findBinaries(pathsToCheck, pythonName, sofficeName);
if (foundPaths.soffice) {
debug('LibreOffice found: soffice at %s, python at %s', foundPaths.soffice, foundPaths.python);
var _foundPaths = _findBinaries(_pathsToCheck, _pythonName, _sofficeName);
if (_foundPaths.soffice) {
debug('LibreOffice found: soffice at %s, python at %s', _foundPaths.soffice, _foundPaths.python);
isLibreOfficeFound = true;
converterOptions.pythonExecPath = foundPaths.python;
converterOptions.sofficeExecPath = foundPaths.soffice;
converterOptions.pythonExecPath = _foundPaths.python;
converterOptions.sofficeExecPath = _foundPaths.soffice;
}

if (isLibreOfficeFound === false) {
Expand Down
10 changes: 5 additions & 5 deletions lib/lopath.js
Expand Up @@ -35,15 +35,15 @@ function convertToURL(inputPath) {
throw new PathError('Paths to convert must be absolute');
}
// Split into parts so that we can join into a URL:
var normalizedPath = path.normalize(inputPath);
var _normalizedPath = path.normalize(inputPath);
// (Use both delimiters blindly - we're aiming for maximum compatibility)
var pathComponents = normalizedPath.split(/[\\/]/);
var _pathComponents = _normalizedPath.split(/[\\/]/);
// Make sure there is no leading empty element, since we always add a
// leading "/" anyway.
if (pathComponents[0] === '') {
pathComponents.shift();
if (_pathComponents[0] === '') {
_pathComponents.shift();
}
var outputURL = 'file:///' + pathComponents.join('/');
var outputURL = 'file:///' + _pathComponents.join('/');
return outputURL;
}

Expand Down

0 comments on commit dcb713d

Please sign in to comment.