Create where_is utility to locate a binary in the standard places
This is particularly useful on Mac OS X where Gramps is passed a PATH that does not include elements added by the terminal shell.
This commit is contained in:
parent
700f15be75
commit
90de264ccf
@ -44,7 +44,7 @@ from subprocess import Popen, PIPE
|
||||
#-------------------------------------------------------------------------
|
||||
from ...const import GRAMPS_LOCALE as glocale
|
||||
_ = glocale.translation.gettext
|
||||
from ...utils.file import search_for
|
||||
from ...utils.file import search_for, where_is
|
||||
from . import BaseDoc
|
||||
from ..menu import NumberOption, TextOption, EnumeratedListOption, \
|
||||
BooleanOption
|
||||
@ -103,11 +103,7 @@ if win():
|
||||
_GS_CMD = ""
|
||||
else:
|
||||
_DOT_FOUND = search_for("dot")
|
||||
|
||||
if search_for("gs") == 1:
|
||||
_GS_CMD = "gs"
|
||||
else:
|
||||
_GS_CMD = ""
|
||||
_GS_CMD = where_is("gs")
|
||||
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
|
@ -61,7 +61,7 @@ def find_file( filename):
|
||||
try:
|
||||
if os.path.isfile(filename):
|
||||
return(filename)
|
||||
except UnicodeError:
|
||||
except UnicodeError as err:
|
||||
LOG.error("Filename %s raised a Unicode Error %s.", repr(filename), err)
|
||||
|
||||
LOG.debug("Filename %s not found.", repr(filename))
|
||||
@ -228,6 +228,24 @@ def search_for(name):
|
||||
return 1
|
||||
return 0
|
||||
|
||||
|
||||
def where_is(name):
|
||||
""" This command is similar to the Linux "whereis -b file" command.
|
||||
It looks for an executable file (name) in the PATH python is using, as
|
||||
well as several likely other paths. It returns the first file found,
|
||||
or an empty string if not found.
|
||||
"""
|
||||
paths = set(os.environ['PATH'].split(os.pathsep))
|
||||
if not win():
|
||||
paths.update(("/bin", "/usr/bin", "/usr/local/bin", "/opt/local/bin",
|
||||
"/opt/bin"))
|
||||
for i in paths:
|
||||
fname = os.path.join(i, name)
|
||||
if os.access(fname, os.X_OK) and not os.path.isdir(fname):
|
||||
return fname
|
||||
return ""
|
||||
|
||||
|
||||
def create_checksum(full_path):
|
||||
"""
|
||||
Create a md5 hash for the given file.
|
||||
|
Loading…
Reference in New Issue
Block a user