diff options
author | Greg Ward <gward@python.net> | 2000-08-02 01:37:30 (GMT) |
---|---|---|
committer | Greg Ward <gward@python.net> | 2000-08-02 01:37:30 (GMT) |
commit | 1c16ac360a3fc63bfb1008c3a935907fe9064f26 (patch) | |
tree | 431aae87172ef206edc8a60620cf452b5f299696 /Lib/distutils/util.py | |
parent | 90c74cc4da5b1aa58a37799df16541870ddc4ff7 (diff) | |
download | cpython-1c16ac360a3fc63bfb1008c3a935907fe9064f26.zip cpython-1c16ac360a3fc63bfb1008c3a935907fe9064f26.tar.gz cpython-1c16ac360a3fc63bfb1008c3a935907fe9064f26.tar.bz2 |
Added the 'execute()' function (moved here from cmd.py with minor tweakage).
Diffstat (limited to 'Lib/distutils/util.py')
-rw-r--r-- | Lib/distutils/util.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/Lib/distutils/util.py b/Lib/distutils/util.py index d69626e..37cd4b5 100644 --- a/Lib/distutils/util.py +++ b/Lib/distutils/util.py @@ -223,3 +223,29 @@ def split_quoted (s): return words # split_quoted () + + +def execute (func, args, msg=None, verbose=0, dry_run=0): + """Perform some action that affects the outside world (eg. by writing + to the filesystem). Such actions are special because they are disabled + by the 'dry_run' flag, and announce themselves if 'verbose' is true. + This method takes care of all that bureaucracy for you; all you have to + do is supply the function to call and an argument tuple for it (to + embody the "external action" being performed), and an optional message + to print. + """ + # Generate a message if we weren't passed one + if msg is None: + msg = "%s%s" % (func.__name__, `args`) + if msg[-2:] == ',)': # correct for singleton tuple + msg = msg[0:-2] + ')' + + # Print it if verbosity level is high enough + if verbose: + print msg + + # And do it, as long as we're not in dry-run mode + if not dry_run: + apply(func, args) + +# execute() |