Gentoo Archives: gentoo-catalyst

From: Mike Frysinger <vapier@g.o>
To: gentoo-catalyst@l.g.o
Subject: [gentoo-catalyst] [PATCH 4/4] replace os.system with cmd
Date: Fri, 20 May 2016 14:28:01
Message-Id: 1463754466-15028-4-git-send-email-vapier@gentoo.org
In Reply to: [gentoo-catalyst] [PATCH 1/4] use native code in more places for file ops by Mike Frysinger
1 Use the existing cmd() helper for running external programs.
2 ---
3 catalyst/base/stagebase.py | 11 ++++++-----
4 catalyst/fileops.py | 4 ++--
5 2 files changed, 8 insertions(+), 7 deletions(-)
6
7 diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py
8 index f0f3ba9..6695ac4 100644
9 --- a/catalyst/base/stagebase.py
10 +++ b/catalyst/base/stagebase.py
11 @@ -967,16 +967,17 @@ class StageBase(TargetBase, ClearBase, GenBase):
12 if not ismount(target):
13 continue
14
15 - retval=os.system("umount " + target)
16 -
17 - if retval!=0:
18 + try:
19 + cmd(['umount', target])
20 + except CatalystError:
21 log.warning('First attempt to unmount failed: %s', target)
22 log.warning('Killing any pids still running in the chroot')
23
24 self.kill_chroot_pids()
25
26 - retval2 = os.system("umount " + target)
27 - if retval2!=0:
28 + try:
29 + cmd(['umount', target])
30 + except CatalystError:
31 ouch=1
32 log.warning("Couldn't umount bind mount: %s", target)
33
34 diff --git a/catalyst/fileops.py b/catalyst/fileops.py
35 index 4b9e200..6971911 100644
36 --- a/catalyst/fileops.py
37 +++ b/catalyst/fileops.py
38 @@ -22,7 +22,7 @@ from snakeoil.osutils import (ensure_dirs as snakeoil_ensure_dirs,
39 # pylint: enable=unused-import
40
41 from catalyst import log
42 -from catalyst.support import CatalystError
43 +from catalyst.support import (cmd, CatalystError)
44
45
46 def ensure_dirs(path, gid=-1, uid=-1, mode=0o755, minimal=True,
47 @@ -79,7 +79,7 @@ def clear_dir(target, mode=0o755, chg_flags=False, remove=False,
48 mystat = os.stat(target)
49 # There's no easy way to change flags recursively in python
50 if chg_flags and os.uname()[0] == "FreeBSD":
51 - os.system("chflags -R noschg " + target)
52 + cmd(['chflags', '-R', 'noschg', target])
53 log.debug('shutil.rmtree()')
54 shutil.rmtree(target)
55 except Exception:
56 --
57 2.8.2

Replies

Subject Author
Re: [gentoo-catalyst] [PATCH 4/4] replace os.system with cmd Brian Dolbec <dolsen@g.o>