Skip to content

Commit

Permalink
smurf: configmeld now issues a warning if meld is not available
Browse files Browse the repository at this point in the history
  • Loading branch information
David Berry committed Feb 18, 2013
1 parent ec81a57 commit a7fc9d1
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
12 changes: 9 additions & 3 deletions applications/smurf/scripts/configmeld.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
* python (2.7 or 3.*)
* Description:
* This script use the unix meld tool to display two sets of
* configuration parameters, highlighting the differences between
* This script use the unix meld tool (see meldmerge.org) to display two
* sets of configuration parameters, highlighting the differences between
* them. Each config may be supplied directly, as is done when running
* MAKEMAP, or can be read from the History component of an NDF that
* was created by MAKEMAP.
Expand Down Expand Up @@ -45,7 +45,8 @@
* Notes:
* - The unix "meld" command must be installed and available on the
* unix PATH.
* unix PATH. If not already installed, it can be obtained from
* "meldmerge.org".
* Copyright:
* Copyright (C) 2013 Science & Technology Facilities Council.
Expand Down Expand Up @@ -100,6 +101,11 @@ def cleanup():
except:
pass

# First check that "meld" ia available.
if starutil.which( "meld" ) == None:
print( "\n!! The 'configmeld' command uses the Unix 'meld' command, but "
"meld appears not to be installed. See 'meldmerge.org'.\n" )
os._exit(1)

# Catch any exception so that we can always clean up, even if control-C
# is pressed.
Expand Down
38 changes: 38 additions & 0 deletions applications/smurf/scripts/starutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@



# ------------------- misc ---------------------------

# Function to return the name of the executing script, without any
# trailing ".py" suffix.
Expand All @@ -36,12 +37,49 @@ def cmd():
__cmd = __cmd[:-3]
return __cmd


# "Protected" function to return the name of the executing script,
# followed by a colon and a space.
def _cmd_token():
return "{0}: ".format(cmd())


def which(program):
"""
This command mimics the UNix 'which' command. It searches the PATH for
a named commadn and returns the full path to the executable if found, and
None otherwise.
Invocation:
which(command)
Arguments:
command = string
The commmand to find
Returned Value:
The full path to the executable, or None of the executanble is not
found.
"""

def is_exe(fpath):
return os.path.isfile(fpath) and os.access(fpath, os.X_OK)

fpath, fname = os.path.split(program)
if fpath:
if is_exe(program):
return program
else:
for path in os.environ["PATH"].split(os.pathsep):
path = path.strip('"')
exe_file = os.path.join(path, program)
if is_exe(exe_file):
return exe_file

return None




Expand Down

0 comments on commit a7fc9d1

Please sign in to comment.