1
1
import shutil
2
2
from os import makedirs , walk , path
3
+ import sys
4
+ import logging
5
+
6
+
7
+ log = logging .getLogger (__name__ )
3
8
4
9
5
10
def fixpath (malformed_path ):
@@ -11,8 +16,12 @@ def fixpath(malformed_path):
11
16
12
17
13
18
def adddir (path_to_dir ):
14
- makedirs (fixpath (path_to_dir ), 755 )
15
- return
19
+ try :
20
+ makedirs (fixpath (path_to_dir ), 755 )
21
+ except IOError as e :
22
+ print ("ERROR: failed to create directory directory {0}"
23
+ .format (path_to_dir ), e )
24
+ sys .exit (1 )
16
25
17
26
18
27
def copydir (src , dst ):
@@ -21,11 +30,21 @@ def copydir(src, dst):
21
30
:param dst: destination directory. It shouldn't exists.
22
31
:return:
23
32
"""
24
- shutil .copytree (src , dst , symlinks = True , ignore = None )
33
+ try :
34
+ shutil .copytree (src , dst , symlinks = True , ignore = None )
35
+ except IOError as e :
36
+ print ("ERROR: failed to copy directory from {0} to {1}. "
37
+ .format (src , dst ), e )
38
+ sys .exit (1 )
25
39
26
40
27
41
def copyfile (src , dst ):
28
- shutil .copy2 (src , dst )
42
+ try :
43
+ shutil .copy2 (src , dst )
44
+ except IOError as e :
45
+ print ("ERROR: failed to copy file from {0} to {1}. "
46
+ .format (src , dst ), e )
47
+ sys .exit (1 )
29
48
30
49
31
50
def getfilelist (dir_path ):
@@ -35,7 +54,12 @@ def getfilelist(dir_path):
35
54
:return:
36
55
"""
37
56
rez_list = []
38
- for root , dirs , files in walk (dir_path , topdown = False ):
39
- for name in files :
40
- rez_list .append (path .join (root .replace (dir_path , "" ), name ))
57
+ try :
58
+ for root , dirs , files in walk (dir_path , topdown = False ):
59
+ for name in files :
60
+ rez_list .append (path .join (root .replace (dir_path , "" ), name ))
61
+ except IOError as e :
62
+ print ("ERROR: failed to list path: {0}. " .format (dir_path ), e )
63
+ sys .exit (1 )
64
+
41
65
return rez_list
0 commit comments