A fork of hyde, the static site generation. Some patches will be pushed upstream.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

57 lines
1.4 KiB

  1. """
  2. Module for python 2.6 compatibility.
  3. """
  4. import os
  5. from functools import partial
  6. from itertools import izip, tee
  7. def make_method(method_name, method_):
  8. def method__(*args, **kwargs):
  9. return method_(*args, **kwargs)
  10. method__.__name__ = method_name
  11. return method__
  12. def add_property(obj, method_name, method_, *args, **kwargs):
  13. m = make_method(method_name, partial(method_, *args, **kwargs))
  14. setattr(obj, method_name, property(m))
  15. def add_method(obj, method_name, method_, *args, **kwargs):
  16. m = make_method(method_name, partial(method_, *args, **kwargs))
  17. setattr(obj, method_name, m)
  18. def pairwalk(iterable):
  19. a, b = tee(iterable)
  20. next(b, None)
  21. return izip(a, b)
  22. def first_match(predicate, iterable):
  23. """
  24. Gets the first element matched by the predicate
  25. in the iterable.
  26. """
  27. for item in iterable:
  28. if predicate(item):
  29. return item
  30. return None
  31. def discover_executable(name, sitepath):
  32. """
  33. Finds an executable in the given sitepath or in the
  34. path list provided by the PATH environment variable.
  35. """
  36. # Check if an executable can be found in the site path first.
  37. # If not check the os $PATH for its presence.
  38. paths = [unicode(sitepath)] + os.environ['PATH'].split(os.pathsep)
  39. for path in paths:
  40. full_name = os.path.join(path, name)
  41. if os.path.exists(full_name):
  42. return full_name
  43. return None