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.
25 lines
738 B
25 lines
738 B
from os import environ
|
|
from os.path import isfile
|
|
|
|
# Return unique items in iterable
|
|
def uniq(iterable):
|
|
items = set()
|
|
for item in iterable:
|
|
if item not in items:
|
|
items.add(item)
|
|
yield item
|
|
|
|
# Ternary operator for environment variables
|
|
def ifenv(name, true_func, false_func):
|
|
return true_func(environ[name]) if name in environ else false_func()
|
|
|
|
# Search for file in pathnames, return the first pathname
|
|
# that exists as a file, or None if no files were found
|
|
def find_file(pathnames):
|
|
try:
|
|
# Find the first pathname that exists as a file
|
|
pathname = next(p for p in pathnames if isfile(p))
|
|
except:
|
|
pathname = None
|
|
finally:
|
|
return pathname
|
|
|