From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 0861E138262 for ; Sun, 22 May 2016 03:35:00 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id E1352E0882; Sun, 22 May 2016 03:34:56 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id B7330E0881 for ; Sun, 22 May 2016 03:34:55 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id AEAD3340D52 for ; Sun, 22 May 2016 03:34:54 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id A3DA297E for ; Sun, 22 May 2016 03:34:50 +0000 (UTC) From: "Mike Frysinger" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Mike Frysinger" Message-ID: <1463722963.415c65624ff62f5ab139666cd5447bc35e1e9e8b.vapier@gentoo> Subject: [gentoo-commits] proj/catalyst:master commit in: catalyst/base/, catalyst/targets/ X-VCS-Repository: proj/catalyst X-VCS-Files: catalyst/base/stagebase.py catalyst/targets/netboot2.py catalyst/targets/snapshot.py X-VCS-Directories: catalyst/base/ catalyst/targets/ X-VCS-Committer: vapier X-VCS-Committer-Name: Mike Frysinger X-VCS-Revision: 415c65624ff62f5ab139666cd5447bc35e1e9e8b X-VCS-Branch: master Date: Sun, 22 May 2016 03:34:50 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: e5daa830-e9ba-47b2-bfbc-8118bf35e47b X-Archives-Hash: 48bb96012e3c7dbdf7d66fc09e05ca23 commit: 415c65624ff62f5ab139666cd5447bc35e1e9e8b Author: Mike Frysinger gentoo org> AuthorDate: Fri May 20 05:42:43 2016 +0000 Commit: Mike Frysinger gentoo org> CommitDate: Fri May 20 05:42:43 2016 +0000 URL: https://gitweb.gentoo.org/proj/catalyst.git/commit/?id=415c6562 replace ad-hoc implementations of clear_dir 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'])