Browse Source

Add support for the PATH environment variable.

main
Steve Frécinaux 13 years ago
parent
commit
df9625f7f3
2 changed files with 21 additions and 1 deletions
  1. +9
    -1
      hyde/plugin.py
  2. +12
    -0
      hyde/util.py

+ 9
- 1
hyde/plugin.py View File

@@ -8,11 +8,12 @@ from hyde import loader

from hyde.exceptions import HydeException
from hyde.fs import File
from hyde.util import getLoggerWithNullHandler, first_match
from hyde.util import getLoggerWithNullHandler, first_match, discover_executable
from hyde.model import Expando

from functools import partial

import os
import re
import subprocess
import traceback
@@ -255,6 +256,13 @@ class CLTransformer(Plugin):
raise self.template.exception_class(
self.executable_not_found_message)

# Honour the PATH environment variable.
if not os.path.isabs(app_path):
app_path = discover_executable(app_path)
if app_path is None:
raise self.template.exception_class(
self.executable_not_found_message)

app = File(app_path)

if not app.exists:


+ 12
- 0
hyde/util.py View File

@@ -2,6 +2,7 @@
Module for python 2.6 compatibility.
"""
import logging
import os
import sys
from itertools import ifilter, izip, tee

@@ -122,3 +123,14 @@ def first_match(predicate, iterable):
if predicate(item):
return item
return None

def discover_executable(name):
"""
Finds an executable in the path list provided by the PATH
environment variable.
"""
for path in os.environ['PATH'].split(os.pathsep):
full_name = os.path.join(path, name)
if os.path.exists(full_name):
return full_name
return None

Loading…
Cancel
Save