def print_progress(file=None):
    """!
    @brief Progress printer factory.
    
    This factory function checks whether the output file is a TTY, and instantiates the
    appropriate subclass of ProgressReport.
    
    @param file The output file. Optional. If not provided, or if set to None, then sys.stdout
          will be used automatically.
    """
    
    if file is None:
        file = sys.stdout
    try:
        istty = os.isatty(file.fileno())
    except (OSError, AttributeError):
        # Either the file doesn't have a fileno method, or calling it returned an
        # error. In either case, just assume we're not connected to a TTY.
        istty = False
    
    klass = ProgressReportTTY if istty else ProgressReportNoTTY
    return klass(file)