2012-06-20 20:33:26 +00:00
|
|
|
# -*- coding: iso-8859-1 -*-
|
|
|
|
# Copyright (C) 2012 Bastian Kleineidam
|
|
|
|
"""
|
|
|
|
File and path utilities.
|
|
|
|
"""
|
2012-11-20 17:53:53 +00:00
|
|
|
import importlib
|
2012-06-20 20:33:26 +00:00
|
|
|
|
|
|
|
def has_module (name):
|
|
|
|
"""Test if given module can be imported.
|
|
|
|
@return: flag if import is successful
|
|
|
|
@rtype: bool
|
|
|
|
"""
|
|
|
|
try:
|
2012-11-20 17:53:53 +00:00
|
|
|
importlib.import_module(name)
|
2012-06-20 20:33:26 +00:00
|
|
|
return True
|
|
|
|
except (OSError, ImportError):
|
|
|
|
# some modules (for example HTMLtidy) raise OSError
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
def is_tty (fp):
|
|
|
|
"""Check if a file object is a TTY."""
|
|
|
|
return (hasattr(fp, "isatty") and fp.isatty())
|