1 |
--- |
2 |
catalyst/fileops.py | 22 ++++++++++++---------- |
3 |
1 file changed, 12 insertions(+), 10 deletions(-) |
4 |
|
5 |
diff --git a/catalyst/fileops.py b/catalyst/fileops.py |
6 |
index 2aa39f6..8fb2a36 100644 |
7 |
--- a/catalyst/fileops.py |
8 |
+++ b/catalyst/fileops.py |
9 |
@@ -20,6 +20,8 @@ from stat import ST_UID, ST_GID, ST_MODE |
10 |
from snakeoil.osutils import (ensure_dirs as snakeoil_ensure_dirs, |
11 |
pjoin, listdir_files) |
12 |
# pylint: enable=unused-import |
13 |
+ |
14 |
+from catalyst import log |
15 |
from catalyst.support import CatalystError |
16 |
|
17 |
|
18 |
@@ -61,31 +63,31 @@ def clear_dir(target, mode=0o755, chg_flags=False, remove=False): |
19 |
@remove: boolean, passed through to clear_dir() |
20 |
@return boolean |
21 |
''' |
22 |
- #print "fileops.clear_dir()" |
23 |
+ log.debug('start: %s', target) |
24 |
if not target: |
25 |
- #print "fileops.clear_dir(), no target... returning" |
26 |
+ log.debug('no target... returning') |
27 |
return False |
28 |
if os.path.isdir(target): |
29 |
- print "Emptying directory" , target |
30 |
+ log.info('Emptying directory: %s', target) |
31 |
# stat the dir, delete the dir, recreate the dir and set |
32 |
# the proper perms and ownership |
33 |
try: |
34 |
- #print "fileops.clear_dir(), os.stat()" |
35 |
+ log.debug('os.stat()') |
36 |
mystat=os.stat(target) |
37 |
# There's no easy way to change flags recursively in python |
38 |
if chg_flags and os.uname()[0] == "FreeBSD": |
39 |
os.system("chflags -R noschg " + target) |
40 |
- #print "fileops.clear_dir(), shutil.rmtree()" |
41 |
+ log.debug('shutil.rmtree()') |
42 |
shutil.rmtree(target) |
43 |
if not remove: |
44 |
- #print "fileops.clear_dir(), ensure_dirs()" |
45 |
+ log.debug('ensure_dirs()') |
46 |
ensure_dirs(target, mode=mode) |
47 |
os.chown(target, mystat[ST_UID], mystat[ST_GID]) |
48 |
os.chmod(target, mystat[ST_MODE]) |
49 |
- except Exception as e: |
50 |
- print CatalystError("clear_dir(); Exeption: %s" % str(e)) |
51 |
+ except Exception: |
52 |
+ log.error('clear_dir failed', exc_info=True) |
53 |
return False |
54 |
else: |
55 |
- print "fileops.clear_dir(), %s is not a directory" % (target) |
56 |
- #print "fileops.clear_dir(), DONE, returning True" |
57 |
+ log.info('clear_dir failed: %s: is not a directory', target) |
58 |
+ log.debug('DONE, returning True') |
59 |
return True |
60 |
-- |
61 |
2.5.2 |