def log(self, event, *msg, **opts): """Map log events to external commands Arguments are passed on as environment variables. """ script = self.config('logtoprocess', event) if script: if msg: # try to format the log message given the remaining # arguments try: # Format the message as blackbox does formatted = msg[0] % msg[1:] except (TypeError, KeyError): # Failed to apply the arguments, ignore formatted = msg[0] messages = (formatted, ) + msg[1:] else: messages = msg # positional arguments are listed as MSG[N] keys in the # environment msgpairs = (('MSG{0:d}'.format(i), str(m)) for i, m in enumerate(messages, 1)) # keyword arguments get prefixed with OPT_ and uppercased optpairs = (('OPT_{0}'.format(key.upper()), str(value)) for key, value in opts.iteritems()) env = dict(itertools.chain(procutil.shellenviron().items(), msgpairs, optpairs), EVENT=event, HGPID=str(os.getpid())) runshellcommand(script, env) return super(logtoprocessui, self).log(event, *msg, **opts)
def log(self, ui, event, msg, opts): script = self._scripts[event] env = { b'EVENT': event, b'HGPID': os.getpid(), b'MSG1': msg, } # keyword arguments get prefixed with OPT_ and uppercased env.update( (b'OPT_%s' % key.upper(), value) for key, value in opts.items()) fullenv = procutil.shellenviron(env) procutil.runbgcommand(script, fullenv, shell=True)
def _systembackground(cmd, environ=None, cwd=None): ''' like 'procutil.system', but returns the Popen object directly so we don't have to wait on it. ''' cmd = procutil.quotecommand(cmd) env = procutil.shellenviron(environ) proc = subprocess.Popen(procutil.tonativestr(cmd), shell=True, close_fds=procutil.closefds, env=procutil.tonativeenv(env), cwd=pycompat.rapply(procutil.tonativestr, cwd)) return proc
def log(self, ui, event, msg, opts): script = self._scripts[event] maxmsg = 100000 if len(msg) > maxmsg: # Each env var has a 128KiB limit on linux. msg can be long, in # particular for command event, where it's the full command line. # Prefer truncating the message than raising "Argument list too # long" error. msg = msg[:maxmsg] + b' (truncated)' env = { b'EVENT': event, b'HGPID': os.getpid(), b'MSG1': msg, } # keyword arguments get prefixed with OPT_ and uppercased env.update( (b'OPT_%s' % key.upper(), value) for key, value in opts.items()) fullenv = procutil.shellenviron(env) procutil.runbgcommand(script, fullenv, shell=True)