]> git.phdru.name Git - m_lib.git/blob - m_lib/m_shutil.py
Remove wrong copyright lines, fix module docstrings
[m_lib.git] / m_lib / m_shutil.py
1 #! /usr/bin/env python
2 """
3 Shell utilities. Additional to shutil.py (standard library module).
4 """
5
6
7 import os, string
8
9
10 mkhier_error = "m_shutil.mkhier_error"
11
12 def mkhier(path): # Python implementation of UNIX' mkdir -p /path/to/dir
13    if os.path.isdir(path):
14       return # It's Ok to have the directory already created
15
16    if os.path.exists(path):
17       raise mkhier_error, "`%s' is file" % path
18
19    list_dirs = string.split(path, os.sep)
20    #print list_dirs
21    for i in range(0, len(list_dirs)):
22       new_path = string.join(list_dirs[0:i+1], os.sep)
23       if (new_path <> '') and (not os.path.exists(new_path)):
24          #print "Making", new_path
25          os.mkdir(new_path)
26
27
28 def mcd(dir):
29    os.mkdir(dir)
30    os.chdir(dir)
31
32
33 def test():
34    mkhier("I.AM/creating/TEST/dir")
35
36 if __name__ == "__main__":
37    test()