Exit and print text (if defined) to stderr if code > 0 or stdout
    otherwise.

      >>> exit(code=1, text='Invalid directory path')

def exit(code=0, text=''):
    """Exit and print text (if defined) to stderr if code > 0 or stdout
    otherwise.

      >>> exit(code=1, text='Invalid directory path')
    """
    if not isinstance(text, basestring_type):
        text = unicode_type(text)
    if code > 0:
        if text:
            if not isinstance(text, basestring_type):
                text = unicode_type(text)
            sys.stderr.write(text)
        sys.exit(code)
    else:
        if text:
            print(text)
        sys.exit(0)