# Path: argparse_compat.py

# 
# Path: util.py
# PY3 = False


import sys, os
from argparse_compat import argparse
from util import PY3
__all__ = ["add_libname_arguments", "add_passing_libname_arguments", "ArgumentParser", "update_env_with_libnames", "add_logging_arguments", "process_logging_arguments", "update_env_with_coqpath_folders", "DEFAULT_LOG", "DEFAULT_VERBOSITY", "LOG_ALWAYS"]

# grumble, grumble, we want to support multiple -R arguments like coqc
class CoqLibnameAction(argparse.Action):
    non_default = False
#     def __init__(self, *args, **kwargs):
#         super(CoqLibnameAction, self).__init__(*args, **kwargs)
    def __call__(self, parser, namespace, values, option_string=None):
#        print('%r %r %r' % (namespace, values, option_string))
        if not self.non_default:
            setattr(namespace, self.dest, [])
            self.non_default = True
        getattr(namespace, self.dest).append(tuple(values))

DEFAULT_VERBOSITY=1
LOG_ALWAYS=None

def make_logger(log_files):
    # log if level <= the level of the logger
    def log(text, level=DEFAULT_VERBOSITY, max_level=None, force_stdout=False, force_stderr=False, end='\n'):
        selected_log_files = [f for flevel, f in log_files if level is LOG_ALWAYS or (level <= flevel and (max_level is None or flevel < max_level))]
        for i in selected_log_files:
            if force_stderr and i.fileno() == 1 and not force_stdout: continue # skip stdout if we write to stderr
            if force_stdout and i.fileno() == 2 and not force_stderr: continue # skip stderr if we write to stdout
            i.write(str(text) + end)
            i.flush()
            if i.fileno() > 2: # stderr
                os.fsync(i.fileno())
        for (force, fno, sys_file) in ((force_stdout, 1, sys.stdout), (force_stderr, 2, sys.stderr)):
            if force and not any(i.fileno() == fno for i in selected_log_files): # not already writing to std{out,err}

# Path: argparse_compat.py

# 
# Path: util.py
# PY3 = False


# Path: custom_arguments.py
import sys, os
from argparse_compat import argparse
from util import PY3

__all__ = ["add_libname_arguments", "add_passing_libname_arguments", "ArgumentParser", "update_env_with_libnames", "add_logging_arguments", "process_logging_arguments", "update_env_with_coqpath_folders", "DEFAULT_LOG", "DEFAULT_VERBOSITY", "LOG_ALWAYS"]

# grumble, grumble, we want to support multiple -R arguments like coqc
class CoqLibnameAction(argparse.Action):
    non_default = False
#     def __init__(self, *args, **kwargs):
#         super(CoqLibnameAction, self).__init__(*args, **kwargs)
    def __call__(self, parser, namespace, values, option_string=None):
#        print('%r %r %r' % (namespace, values, option_string))
        if not self.non_default:
            setattr(namespace, self.dest, [])
            self.non_default = True
        getattr(namespace, self.dest).append(tuple(values))

DEFAULT_VERBOSITY=1
LOG_ALWAYS=None

def make_logger(log_files):
    # log if level <= the level of the logger
    def log(text, level=DEFAULT_VERBOSITY, max_level=None, force_stdout=False, force_stderr=False, end='\n'):
        selected_log_files = [f for flevel, f in log_files if level is LOG_ALWAYS or (level <= flevel and (max_level is None or flevel < max_level))]
        for i in selected_log_files:
            if force_stderr and i.fileno() == 1 and not force_stdout: continue # skip stdout if we write to stderr
            if force_stdout and i.fileno() == 2 and not force_stderr: continue # skip stderr if we write to stdout
            i.write(str(text) + end)
            i.flush()
            if i.fileno() > 2: # stderr
                os.fsync(i.fileno())
        for (force, fno, sys_file) in ((force_stdout, 1, sys.stdout), (force_stderr, 2, sys.stderr)):
            if force and not any(i.fileno() == fno for i in selected_log_files): # not already writing to std{out,err}

                if PY3: