about summary refs log tree commit diff stats
path: root/src/chrtrans
# Copyright (c) 2009, 2010 hut <hut@lavabit.com>
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

"""
This module is an abstract layer over subprocess.Popen

It gives you highlevel control about how processes are run.

Example:
run = Runner(logfunc=print)
run('sleep 2', wait=True)         # waits until the process exists
run(['ls', '--help'], flags='p')  # pipes output to pager
run()                             # prints an error message

List of allowed flags:
s: silent mode. output will be discarded.
d: detach the process.
p: redirect output to the pager
(An uppercase key ensures that a certain flag will not be used.)
"""

import 
Commit message (Collapse)AuthorAgeFilesLines
...
* snapshot of project "lynx", label v2-8-2dev_9Thomas E. Dickey1998-12-132-3/+4
|
* snapshot of project "lynx", label v2-8-2dev_8Thomas E. Dickey1998-12-031-5/+5
|
* snapshot of project "lynx", label v2-8-2dev_5Thomas E. Dickey1998-11-218-9/+12
|
* snapshot of project "lynx", label v2-8-2dev_4Thomas E. Dickey1998-11-1831-8/+170
|
* snapshot of project "lynx", label v2-8-2dev_2Thomas E. Dickey1998-11-1036-1686/+988
|
* snapshot of project "lynx", label v2-8-1dev_4Thomas E. Dickey1998-11-0636-978/+1684
|
* snapshot of project "lynx", label v2-8-1rel_1Thomas E. Dickey1998-10-241-1/+1
|
* snapshot of project "lynx", label v2-8-1pre_11Thomas E. Dickey1998-10-171-18/+28
|
* snapshot of project "lynx", label v2-8-1pre_3Thomas E. Dickey1998-09-274-0/+6
|
* snapshot of project "lynx", label v2-8-1dev_29Thomas E. Dickey1998-09-213-518/+146
| 19-99/+41
|
* snapshot of project "lynx", label v2-7-1ac-0_113Thomas E. Dickey1998-02-0514-1101/+2039
|
* snapshot of project "lynx", label v2-7-1ac-0_111Thomas E. Dickey1998-01-287-20/+18
|
* snapshot of project "lynx", label v2-7-1ac_0-110Thomas E. Dickey1998-01-2214-65/+93
|
* snapshot of project "lynx", label v2-7-1ac_0-106Thomas E. Dickey1998-01-051-1902/+0
|
* snapshot of project "lynx", label v2-7-1ac_0-105Thomas E. Dickey1998-01-0213-201/+2672
|
* snapshot of project "lynx", label v2-7-1ac_0-102Thomas E. Dickey1997-12-183-45/+76
|
* snapshot of project "lynx", label v2-7-1ac_0-95Thomas E. Dickey1997-11-1727-224/+2077
|
* snapshot of project "lynx", label v2-7-1ac_0-93Thomas E. Dickey1997-11-077-25/+135
|
* snapshot of project "lynx", label v2-7-1ac_0-89Thomas E. Dickey1997-10-2716-751/+509
|
* snapshot of project "lynx", label v2-7-1ac_0-84Thomas E. Dickey1997-10-172-1/+100
|
* snapshot of project "lynx", label v2-7-1ac_0-76Thomas E. Dickey1997-10-062-10/+36
|
* snapshot of project "lynx", label v2-7-1ac_0-69Thomas E. Dickey1997-09-191-3/+3
|
* snapshot of project "lynx", label v2-7-1ac_0-68Thomas E. Dickey1997-09-181-11/+9
|
* snapshot of project "lynx", label v2-7-1ac_0-64Thomas E. Dickey1997-09-1210-81/+466
|
* snapshot of project "lynx", label v2-7-1ac_0-55Thomas E. Dickey1997-08-271-0/+6
|
* snapshot of project "lynx", label v2-7-1ac_0-52Thomas E. Dickey1997-08-177-4/+208
|
* snapshot of project "lynx", label v2-7-1ac_0-42Thomas E. Dickey1997-07-274-0/+157
|
* snapshot of project "lynx", label v2-7-1ac_0-36Thomas E. Dickey1997-07-186-426/+662
|
* snapshot of project "lynx", label v2-7-1ac_0-28Thomas E. Dickey1997-05-256-5/+15
|
* snapshot of project "lynx", label v2-7-1ac_0-6Thomas E. Dickey1997-04-1629-0/+12201
uot;No way of determining the action!") # Preconditions context.squash_flags() popen_kws = context.popen_kws # shortcut toggle_ui = True pipe_output = False popen_kws['args'] = action if 'shell' not in popen_kws: popen_kws['shell'] = isinstance(action, str) if 'stdout' not in popen_kws: popen_kws['stdout'] = sys.stdout if 'stderr' not in popen_kws: popen_kws['stderr'] = sys.stderr # Evaluate the flags to determine keywords # for Popen() and other variables if 'p' in context.flags: popen_kws['stdout'] = PIPE popen_kws['stderr'] = PIPE toggle_ui = False pipe_output = True context.wait = False if 's' in context.flags or 'd' in context.flags: for key in ('stdout', 'stderr', 'stdin'): popen_kws[key] = devnull if 'd' in context.flags: toggle_ui = False context.wait = False # Finally, run it if toggle_ui: self._activate_ui(False) try: process = None try: process = Popen(**popen_kws) except: self._log("Failed to run: " + str(action)) else: if context.wait: waitpid_no_intr(process.pid) finally: if toggle_ui: self._activate_ui(True) if pipe_output and process: return self(action='less', app='pager', try_app_first=True, stdin=process.stdout) return process