Return exit code of zero iff directory is not changed.
773307
def main():  # pragma: nocover
    
    p = argparse.ArgumentParser()
    p.add_argument(
        'directory',
        help="Directory to check"
    )
    p.add_argument(
        '--verbose', '-v', action='store_true',
        help="increase verbosity"
    )
    args = p.parse_args()

    import sys
    _changed = changed(sys.argv[1], args=args)
    sys.exit(_changed)
317354
def ensure_dir_does_not_exist(*args):
    """"""
    path = os.path.join(*args)
    if os.path.isdir(path):
        shutil.rmtree(path)
1133345
def safe_exit(output):
    """"""
    try:
        sys.stdout.write(output)
        sys.stdout.flush()
    except IOError:
        pass
66294
def shell_out(cmd, stderr=STDOUT, cwd=None):
    """"""
    if cwd is None:
        from os import getcwd
        cwd = getcwd()  # TODO do I need to normalize this on Windows

    out = check_output(cmd, cwd=cwd, stderr=stderr, universal_newlines=True)
    return _clean_output(out)
679444
def statusfmt(status):
    
    if status == 0:
        msg = 'exited ok'
    elif os.WIFSIGNALED(status):
        msg = 'died on '+signame(os.WTERMSIG(status))
    elif os.WIFEXITED(status) and os.WEXITSTATUS(status) > 0:
        msg = 'exited '+str(os.WEXITSTATUS(status))
    else:
        msg = 'unknown exit code 0x%04x' % (status,)
    if os.WCOREDUMP(status):
        msg += ' (core dumped)'
    return msg
490869
def check_path(options, rootdir=None, candidates=None, code=None):
    
    if not candidates:
        candidates = []
        for path_ in options.paths:
            path = op.abspath(path_)
            if op.isdir(path):
                for root, _, files in walk(path):
                    candidates += [op.relpath(op.join(root, f), CURDIR)
                                   for f in files]
            else:
                candidates.append(path)

    if rootdir is None:
        rootdir = path if op.isdir(path) else op.dirname(path)

    paths = []
    for path in candidates:

        if not options.force and not any(l.allow(path)
                                         for _, l in options.linters):
            continue

        if not op.exists(path):
            continue

        paths.append(path)

    if options.concurrent:
        return check_async(paths, options, rootdir)

    errors = []
    for path in paths:
        errors += run(path=path, code=code, rootdir=rootdir, options=options)
    return errors
709245
def exit_config_mode(self, exit_config="exit configuration-mode"):
        """"""
        output = ""
        if self.check_config_mode():
            output = self.send_command_timing(
                exit_config, strip_prompt=False, strip_command=False
            )
            # if 'Exit with uncommitted changes?' in output:
            if "uncommitted changes" in output:
                output += self.send_command_timing(
                    "yes", strip_prompt=False, strip_command=False
                )
            if self.check_config_mode():
                raise ValueError("Failed to exit configuration mode")
        return output
476469
def getExitCode(self, command, env={}, path=None, uid=None, gid=None,
                    usePTY=0, childFDs=None):
        
        deferred = defer.Deferred()
        processProtocol = _SummaryProcessProtocol(deferred)
        self.execute(processProtocol, command, env, path, uid, gid,
                     usePTY, childFDs)
        @deferred.addCallback
        def getStdOut(tuple_):
            _stdout, _stderr, exitCode = tuple_
            return exitCode
        return deferred
976349
def __exitfunction(self):
        '''
        
        '''
        if self._hook.exit_code is None and self._hook.exception is None:
            print("Check did not exit! You should call an exit code method.")
            sys.stdout.flush()
            os._exit(1)
        elif self._hook.exception:
            print("Check failed to run: %s, %s" %
                  (sys.last_type, traceback.format_tb(sys.last_traceback)))
            sys.stdout.flush()
            os._exit(2)
1232521
def exit_code(self) -> Any:
        
        if self._done() or self.is_killed():
            return self._exit_code
        else:
            raise BehaviourNotFinishedException
402702
def _compute_final_exit_code(*codes):
    """"""
    max_code = None
    for code in codes:
      if max_code is None or abs(max_code) < abs(code):
        max_code = code
    return max_code
1053376
def _check(self):
        """"""
        final = self._md_context.digest()
        exp = self._inf._md_expect
        if exp is None:
            return
        if final is None:
            return
        if self._returncode:
            check_returncode(self, '')
        if self._remain != 0:
            raise BadRarFile("Failed the read enough data")
        if final != exp:
            raise BadRarFile("Corrupt file - CRC check failed: %s - exp=%r got=%r" % (
                self._inf.filename, exp, final))
865095
def isempty(path):
    
    cmd = "hadoop fs -test -z %s"
    p = _hadoop_fs_command(cmd % (path))
    p.communicate()
    rcode = p.returncode
    return bool(int(rcode == 0))
1342242
def _check_dir(self, dirname):
        
        if not os.path.exists(dirname):
            print("Directory %s does not exist!" % dirname)
            sys.exit(1)
191737
def _convertNonZeroToFailure(self, res):
        ""
        (stdout, stderr, code) = res
        if code != 0:
            raise EnvironmentError(
                'command failed with exit code %d: %s' % (code, stderr))
        return (stdout, stderr, code)
617287
def check_git_unchanged(filename, yes=False):
    """"""
    if check_staged(filename):
        s = 'There are staged changes in {}, overwrite? [y/n] '.format(filename)
        if yes or input(s) in ('y', 'yes'):
            return
        else:
            raise RuntimeError('There are staged changes in '
                               '{}, aborting.'.format(filename))
    if check_unstaged(filename):
        s = 'There are unstaged changes in {}, overwrite? [y/n] '.format(filename)
        if yes or input(s) in ('y', 'yes'):
            return
        else:
            raise RuntimeError('There are unstaged changes in '
                               '{}, aborting.'.format(filename))
639950
def exit_cleanly(error_number=0):
    
    default = "An Unknown error has occurred!"
    descriptions = \
        {22: 'An improper input error has occurred.  Please see above stmt(s)',
         29: 'An operation failed.  Please see above stmt(s)',
         5: 'An IO Error has occurred.  Pelase see above stmt(s)'}
    try:
        error_number = int(error_number)
    except TypeError:
        stmt = default
        error_number = -1
    if error_number == 0:
        stmt = "No error has been detected!"
    elif not isinstance(error_number, int) and hasattr(errno, error_number):
        error_number = getattr(errno, error_number)
        stmt = descriptions[error_number] if error_number in descriptions \
            else default
    elif error_number in descriptions:
        stmt = descriptions[error_number]
    else:
        stmt = default
    if error_number:
        print("""
%s [--opt [option]]
    With opts:
        working_directory - the full path to the working directory
        operating_system - the full name of the operating system lower case
        version - the version of the operating system

    All of these options must be supplied, and if one is missing or if there is
    no corresponding:
        <working_directory>/*-dist/Docker/<operating_system>/<version>
    Directory, then this script will exit cleanly reporting it as an error.
            """ % sys.argv[0])
    print("(%d) %s" % (error_number, stmt), file=sys.stderr)
    sys.exit(error_number)