* Module wpylib.shell_tools will contain common utilities similar to those

that I have been using in my shell.
* Function added: mcd.
master
wirawan 15 years ago
parent 887ca7e16e
commit 3609a5b95b
  1. 34
      shell_tools.py

@ -0,0 +1,34 @@
# $Id: shell_tools.py,v 1.1 2010-01-08 18:43:06 wirawan Exp $
#
# wpylib.shell_tools
# Created: 20100106
# Wirawan Purwanto
#
# Simple and dirty tools like those I usually use in my shell
# scripts.
#
import os
import subprocess
import sys
def mcd(subdir):
# Assuming we have GNU coreutils' mkdir
cmd = ["mkdir", "-p", subdir]
try:
retcode = subprocess.call(cmd, shell=False)
if retcode == 0:
os.chdir(subdir)
return
print >>sys.stderr, "mcd " + subdir + ": ",
if retcode < 0:
print >>sys.stderr, "mkdir was terminated by signal", -retcode
else:
print >>sys.stderr, "mkdir returned", retcode
raise RuntimeError, "Directory creation failure"
except OSError, e:
print >>sys.stderr, "mcd failed:", e
raise
Loading…
Cancel
Save