Back to index

enigmail  1.4.3
Classes | Functions | Variables
pymake.process Namespace Reference

Classes

class  Job
class  PopenJob
class  PythonException
class  PythonJob
class  ParallelContext

Functions

def clinetoargv
def doglobbing
def call
def call_native
def statustoresult
def load_module_recursive
def job_runner
def makedeferrable
def getcontext

Variables

tuple _log = logging.getLogger('pymake.process')
tuple _escapednewlines = re.compile(r'\\\n')
tuple _blacklist = re.compile(r'[$><;[{~`|&()]')
tuple _needsglob = re.compile(r'[\*\?]')
tuple shellwords
 _serialContext = None
 _parallelContext = None

Detailed Description

Skipping shell invocations is good, when possible. This wrapper around subprocess does dirty work of
parsing command lines into argv and making sure that no shell magic is being used.

Function Documentation

def pymake.process.call (   cline,
  env,
  cwd,
  loc,
  cb,
  context,
  echo,
  justprint = False 
)

Definition at line 59 of file process.py.

00059 
00060 def call(cline, env, cwd, loc, cb, context, echo, justprint=False):
00061     #TODO: call this once up-front somewhere and save the result?
00062     shell, msys = util.checkmsyscompat()
00063 
00064     shellreason = None
00065     if msys and cline.startswith('/'):
00066         shellreason = "command starts with /"
00067     else:
00068         argv, badchar = clinetoargv(cline)
00069         if argv is None:
00070             shellreason = "command contains shell-special character '%s'" % (badchar,)
00071         elif len(argv) and argv[0] in shellwords:
00072             shellreason = "command starts with shell primitive '%s'" % (argv[0],)
00073         else:
00074             argv = doglobbing(argv, cwd)
00075 
00076     if shellreason is not None:
00077         _log.debug("%s: using shell: %s: '%s'", loc, shellreason, cline)
00078         if msys:
00079             if len(cline) > 3 and cline[1] == ':' and cline[2] == '/':
00080                 cline = '/' + cline[0] + cline[2:]
00081             cline = [shell, "-c", cline]
00082         context.call(cline, shell=not msys, env=env, cwd=cwd, cb=cb, echo=echo,
00083                      justprint=justprint)
00084         return
00085 
00086     if not len(argv):
00087         cb(res=0)
00088         return
00089 
00090     if argv[0] == command.makepypath:
00091         command.main(argv[1:], env, cwd, cb)
00092         return
00093 
00094     if argv[0:2] == [sys.executable.replace('\\', '/'),
00095                      command.makepypath.replace('\\', '/')]:
00096         command.main(argv[2:], env, cwd, cb)
00097         return
00098 
00099     if argv[0].find('/') != -1:
00100         executable = util.normaljoin(cwd, argv[0])
00101     else:
00102         executable = None
00103 
00104     context.call(argv, executable=executable, shell=False, env=env, cwd=cwd, cb=cb,
00105                  echo=echo, justprint=justprint)

Here is the call graph for this function:

Here is the caller graph for this function:

def pymake.process.call_native (   module,
  method,
  argv,
  env,
  cwd,
  loc,
  cb,
  context,
  echo,
  justprint = False,
  pycommandpath = None 
)

Definition at line 107 of file process.py.

00107 
00108                 pycommandpath=None):
00109     argv = doglobbing(argv, cwd)
00110     context.call_native(module, method, argv, env=env, cwd=cwd, cb=cb,
00111                         echo=echo, justprint=justprint, pycommandpath=pycommandpath)

Here is the call graph for this function:

Here is the caller graph for this function:

def pymake.process.clinetoargv (   cline)
If this command line can safely skip the shell, return an argv array.
@returns argv, badchar

Definition at line 20 of file process.py.

00020 
00021 def clinetoargv(cline):
00022     """
00023     If this command line can safely skip the shell, return an argv array.
00024     @returns argv, badchar
00025     """
00026 
00027     str = _escapednewlines.sub('', cline)
00028     m = _blacklist.search(str)
00029     if m is not None:
00030         return None, m.group(0)
00031 
00032     args = shlex.split(str, comments=True)
00033 
00034     if len(args) and args[0].find('=') != -1:
00035         return None, '='
00036 
00037     return args, None

Here is the caller graph for this function:

def pymake.process.doglobbing (   args,
  cwd 
)
Perform any needed globbing on the argument list passed in

Definition at line 38 of file process.py.

00038 
00039 def doglobbing(args, cwd):
00040     """
00041     Perform any needed globbing on the argument list passed in
00042     """
00043     globbedargs = []
00044     for arg in args:
00045         if _needsglob.search(arg):
00046             globbedargs.extend(glob.glob(os.path.join(cwd, arg)))
00047         else:
00048             globbedargs.append(arg)
00049 
00050     return globbedargs

Here is the caller graph for this function:

def pymake.process.getcontext (   jcount)

Definition at line 355 of file process.py.

00355 
00356 def getcontext(jcount):
00357     global _serialContext, _parallelContext
00358     if jcount == 1:
00359         if _serialContext is None:
00360             _serialContext = ParallelContext(1)
00361         return _serialContext
00362     else:
00363         if _parallelContext is None:
00364             _parallelContext = ParallelContext(jcount)
00365         return _parallelContext
00366 
Run a job. Called in a Process pool.

Definition at line 229 of file process.py.

00229 
00230 def job_runner(job):
00231     """
00232     Run a job. Called in a Process pool.
00233     """
00234     return job.run()

def pymake.process.load_module_recursive (   module,
  path 
)
Emulate the behavior of __import__, but allow
passing a custom path to search for modules.

Definition at line 170 of file process.py.

00170 
00171 def load_module_recursive(module, path):
00172     """
00173     Emulate the behavior of __import__, but allow
00174     passing a custom path to search for modules.
00175     """
00176     bits = module.split('.')
00177     for i, bit in enumerate(bits):
00178         dotname = '.'.join(bits[:i+1])
00179         try:
00180           f, path, desc = imp.find_module(bit, path)
00181           m = imp.load_module(dotname, f, path, desc)
00182           if f is None:
00183               path = m.__path__
00184         except ImportError:
00185             return

Here is the call graph for this function:

Here is the caller graph for this function:

def pymake.process.makedeferrable (   usercb,
  userkwargs 
)

Definition at line 345 of file process.py.

00345 
00346 def makedeferrable(usercb, **userkwargs):
00347     def cb(*args, **kwargs):
00348         kwargs.update(userkwargs)
00349         return usercb(*args, **kwargs)
00350 
00351     return cb

Convert the status returned from waitpid into a prettier numeric result.

Definition at line 112 of file process.py.

00112 
00113 def statustoresult(status):
00114     """
00115     Convert the status returned from waitpid into a prettier numeric result.
00116     """
00117     sig = status & 0xFF
00118     if sig:
00119         return -sig
00120 
00121     return status >>8


Variable Documentation

tuple pymake.process._blacklist = re.compile(r'[$><;[{~`|&()]')

Definition at line 18 of file process.py.

tuple pymake.process._escapednewlines = re.compile(r'\\\n')

Definition at line 17 of file process.py.

tuple pymake.process._log = logging.getLogger('pymake.process')

Definition at line 15 of file process.py.

tuple pymake.process._needsglob = re.compile(r'[\*\?]')

Definition at line 19 of file process.py.

Definition at line 353 of file process.py.

Definition at line 352 of file process.py.

Initial value:
00001 (':', '.', 'break', 'cd', 'continue', 'exec', 'exit', 'export',
00002               'getopts', 'hash', 'pwd', 'readonly', 'return', 'shift', 
00003               'test', 'times', 'trap', 'umask', 'unset', 'alias',
00004               'set', 'bind', 'builtin', 'caller', 'command', 'declare',
00005               'echo', 'enable', 'help', 'let', 'local', 'logout', 
00006               'printf', 'read', 'shopt', 'source', 'type', 'typeset',
00007               'ulimit', 'unalias', 'set')

Definition at line 51 of file process.py.