]> mj.ucw.cz Git - eval.git/blob - t/moe/util.py
Add unicode and file parsing test
[eval.git] / t / moe / util.py
1 #!/usr/bin/env python
2
3 import os
4 import os.path
5 import shutil
6
7 def mkdir_tree(name):
8     try:
9         os.mkdir(name)  
10     except OSError, err:
11         if err.errno == os.errno.ENOENT:
12             head, tail = os.path.split(name)
13             mkdir_tree(head)
14             os.mkdir(name)
15         elif err.errno == os.errno.EEXIST:
16             pass
17         else:
18             raise err
19
20 def link_or_copy(src, dest):
21     try:
22         os.link(src, dest)
23     except OSError:
24         shutil.copyfile(src, dest)
25
26 def remove_tree_contents(dir):
27     for f in os.listdir(dir):
28         name = os.path.join(dir, f)
29         try:
30             os.unlink(name)
31         except OSError, err:
32             if err.errno == os.errno.EISDIR:
33                 shutil.rmtree(os.path.join(dir, f))
34             else:
35                 raise err