From: Mike Frysinger <vapier@gentoo.org>
To: gentoo-catalyst@lists.gentoo.org
Subject: [gentoo-catalyst] [PATCH 3/4] replace ad-hoc implementations of clear_dir
Date: Fri, 20 May 2016 10:27:45 -0400 [thread overview]
Message-ID: <1463754466-15028-3-git-send-email-vapier@gentoo.org> (raw)
In-Reply-To: <1463754466-15028-1-git-send-email-vapier@gentoo.org>
A few places copy & paste the logic we have in the clear_dir func.
Punt them with a simple call to clear_dir.
---
catalyst/base/stagebase.py | 9 +--------
catalyst/targets/netboot2.py | 10 ++--------
catalyst/targets/snapshot.py | 20 ++------------------
3 files changed, 5 insertions(+), 34 deletions(-)
diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py
index 78e5b94..f0f3ba9 100644
--- a/catalyst/base/stagebase.py
+++ b/catalyst/base/stagebase.py
@@ -3,7 +3,6 @@ import os
import imp
import shutil
import sys
-from stat import ST_UID, ST_GID, ST_MODE
from snakeoil import fileutils
@@ -1202,13 +1201,7 @@ class StageBase(TargetBase, ClearBase, GenBase):
log.warning('not a directory or does not exist, skipping "empty" operation: %s', x)
continue
log.info('Emptying directory %s', x)
- # stat the dir, delete the dir, recreate the dir and set
- # the proper perms and ownership
- mystat=os.stat(myemp)
- shutil.rmtree(myemp)
- ensure_dirs(myemp, mode=0o755)
- os.chown(myemp,mystat[ST_UID],mystat[ST_GID])
- os.chmod(myemp,mystat[ST_MODE])
+ clear_dir(myemp)
self.resume.enable("empty")
def remove(self):
diff --git a/catalyst/targets/netboot2.py b/catalyst/targets/netboot2.py
index da856ba..87dada3 100644
--- a/catalyst/targets/netboot2.py
+++ b/catalyst/targets/netboot2.py
@@ -4,12 +4,10 @@ netboot target, version 2
# NOTE: That^^ docstring has influence catalyst-spec(5) man page generation.
import os
-import shutil
-from stat import ST_UID, ST_GID, ST_MODE
from catalyst import log
from catalyst.support import (CatalystError, normpath, cmd)
-from catalyst.fileops import ensure_dirs, clear_path
+from catalyst.fileops import (ensure_dirs, clear_dir, clear_path)
from catalyst.base.stagebase import StageBase
@@ -152,11 +150,7 @@ class netboot2(StageBase):
log.info('Emptying directory %s', x)
# stat the dir, delete the dir, recreate the dir and set
# the proper perms and ownership
- mystat=os.stat(myemp)
- shutil.rmtree(myemp)
- ensure_dirs(myemp, mode=0o755)
- os.chown(myemp,mystat[ST_UID],mystat[ST_GID])
- os.chmod(myemp,mystat[ST_MODE])
+ clear_dir(myemp)
self.resume.enable("empty")
def set_action_sequence(self):
diff --git a/catalyst/targets/snapshot.py b/catalyst/targets/snapshot.py
index 7ba94b2..8a9acdd 100644
--- a/catalyst/targets/snapshot.py
+++ b/catalyst/targets/snapshot.py
@@ -2,17 +2,13 @@
Snapshot target
"""
-import os
-import shutil
-from stat import ST_UID, ST_GID, ST_MODE
-
from DeComp.compress import CompressMap
from catalyst import log
from catalyst.support import normpath, cmd
from catalyst.base.targetbase import TargetBase
from catalyst.base.genbase import GenBase
-from catalyst.fileops import ensure_dirs
+from catalyst.fileops import (clear_dir, ensure_dirs)
class snapshot(TargetBase, GenBase):
@@ -102,16 +98,4 @@ class snapshot(TargetBase, GenBase):
log.info('Cleaning up ...')
def purge(self):
- myemp=self.settings["tmp_path"]
- if os.path.isdir(myemp):
- log.notice('Emptying directory %s', myemp)
- # stat the dir, delete the dir, recreate the dir and set
- # the proper perms and ownership
- mystat=os.stat(myemp)
- # There's no easy way to change flags recursively in python
- if os.uname()[0] == "FreeBSD":
- os.system("chflags -R noschg "+myemp)
- shutil.rmtree(myemp)
- ensure_dirs(myemp, mode=0o755)
- os.chown(myemp,mystat[ST_UID],mystat[ST_GID])
- os.chmod(myemp,mystat[ST_MODE])
+ clear_dir(self.settings['tmp_path'])
--
2.8.2
next prev parent reply other threads:[~2016-05-20 14:27 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-20 14:27 [gentoo-catalyst] [PATCH 1/4] use native code in more places for file ops Mike Frysinger
2016-05-20 14:27 ` [gentoo-catalyst] [PATCH 2/4] cmd: add support for running commands directly Mike Frysinger
2016-05-20 15:48 ` Brian Dolbec
2016-05-20 14:27 ` Mike Frysinger [this message]
2016-05-20 15:49 ` [gentoo-catalyst] [PATCH 3/4] replace ad-hoc implementations of clear_dir Brian Dolbec
2016-05-20 14:27 ` [gentoo-catalyst] [PATCH 4/4] replace os.system with cmd Mike Frysinger
2016-05-20 15:51 ` Brian Dolbec
2016-05-20 15:46 ` [gentoo-catalyst] [PATCH 1/4] use native code in more places for file ops Brian Dolbec
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1463754466-15028-3-git-send-email-vapier@gentoo.org \
--to=vapier@gentoo.org \
--cc=gentoo-catalyst@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox