equal
deleted
inserted
replaced
376 run with environment maybe modified, maybe in different dir. |
376 run with environment maybe modified, maybe in different dir. |
377 |
377 |
378 if command fails and onerr is None, return status. if ui object, |
378 if command fails and onerr is None, return status. if ui object, |
379 print error message and return status, else raise onerr object as |
379 print error message and return status, else raise onerr object as |
380 exception.''' |
380 exception.''' |
|
381 def py2shell(val): |
|
382 'convert python object into string that is useful to shell' |
|
383 if val in (None, False): |
|
384 return '0' |
|
385 if val == True: |
|
386 return '1' |
|
387 return str(val) |
381 oldenv = {} |
388 oldenv = {} |
382 for k in environ: |
389 for k in environ: |
383 oldenv[k] = os.environ.get(k) |
390 oldenv[k] = os.environ.get(k) |
384 if cwd is not None: |
391 if cwd is not None: |
385 oldcwd = os.getcwd() |
392 oldcwd = os.getcwd() |
386 try: |
393 try: |
387 for k, v in environ.iteritems(): |
394 for k, v in environ.iteritems(): |
388 os.environ[k] = str(v) |
395 os.environ[k] = py2shell(v) |
389 if cwd is not None and oldcwd != cwd: |
396 if cwd is not None and oldcwd != cwd: |
390 os.chdir(cwd) |
397 os.chdir(cwd) |
391 rc = os.system(cmd) |
398 rc = os.system(cmd) |
392 if rc and onerr: |
399 if rc and onerr: |
393 errmsg = '%s %s' % (os.path.basename(cmd.split(None, 1)[0]), |
400 errmsg = '%s %s' % (os.path.basename(cmd.split(None, 1)[0]), |