Gentoo Archives: gentoo-commits

From: Brian Dolbec <dolsen@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/catalyst:master commit in: catalyst/base/
Date: Thu, 26 Feb 2015 20:13:10
Message-Id: 1420091887.80493d8d32cb21d622bb2f514da68ac3106b7c35.dolsen@gentoo
1 commit: 80493d8d32cb21d622bb2f514da68ac3106b7c35
2 Author: Brian Dolbec <dolsen <AT> gentoo <DOT> org>
3 AuthorDate: Sat Jun 1 06:24:46 2013 +0000
4 Commit: Brian Dolbec <dolsen <AT> gentoo <DOT> org>
5 CommitDate: Thu Jan 1 05:58:07 2015 +0000
6 URL: http://sources.gentoo.org/gitweb/?p=proj/catalyst.git;a=commit;h=80493d8d
7
8 Refactor ClearBase code to remove code duplication.
9
10 ---
11 catalyst/base/clearbase.py | 73 ++++++++++++++++++----------------------------
12 1 file changed, 29 insertions(+), 44 deletions(-)
13
14 diff --git a/catalyst/base/clearbase.py b/catalyst/base/clearbase.py
15 index 585d4f2..8462a3c 100644
16 --- a/catalyst/base/clearbase.py
17 +++ b/catalyst/base/clearbase.py
18 @@ -41,60 +41,20 @@ class ClearBase(object):
19
20
21 def clear_chroot(self):
22 - myemp=self.settings["chroot_path"]
23 - if os.path.isdir(myemp):
24 - print "Emptying directory",myemp
25 - """
26 - stat the dir, delete the dir, recreate the dir and set
27 - the proper perms and ownership
28 - """
29 - mystat=os.stat(myemp)
30 - #cmd("rm -rf "+myemp, "Could not remove existing file: "+myemp,env=self.env)
31 - """ There's no easy way to change flags recursively in python """
32 - if os.uname()[0] == "FreeBSD":
33 - os.system("chflags -R noschg "+myemp)
34 - shutil.rmtree(myemp)
35 - ensure_dirs(myemp, mode=0755)
36 - os.chown(myemp,mystat[ST_UID],mystat[ST_GID])
37 - os.chmod(myemp,mystat[ST_MODE])
38 + print 'Clearing the chroot path ...'
39 + self.clear_dir(self.settings["chroot_path"], 0755, True)
40
41
42 def clear_packages(self):
43 if "pkgcache" in self.settings["options"]:
44 print "purging the pkgcache ..."
45 -
46 - myemp=self.settings["pkgcache_path"]
47 - if os.path.isdir(myemp):
48 - print "Emptying directory",myemp
49 - """
50 - stat the dir, delete the dir, recreate the dir and set
51 - the proper perms and ownership
52 - """
53 - mystat=os.stat(myemp)
54 - #cmd("rm -rf "+myemp, "Could not remove existing file: "+myemp,env=self.env)
55 - shutil.rmtree(myemp)
56 - ensure_dirs(myemp, mode=0755)
57 - os.chown(myemp,mystat[ST_UID],mystat[ST_GID])
58 - os.chmod(myemp,mystat[ST_MODE])
59 + self.clear_dir(self.settings["pkgcache_path"])
60
61
62 def clear_kerncache(self):
63 if "kerncache" in self.settings["options"]:
64 print "purging the kerncache ..."
65 -
66 - myemp=self.settings["kerncache_path"]
67 - if os.path.isdir(myemp):
68 - print "Emptying directory",myemp
69 - """
70 - stat the dir, delete the dir, recreate the dir and set
71 - the proper perms and ownership
72 - """
73 - mystat=os.stat(myemp)
74 - #cmd("rm -rf "+myemp, "Could not remove existing file: "+myemp,env=self.env)
75 - shutil.rmtree(myemp)
76 - ensure_dirs(myemp, mode=0755)
77 - os.chown(myemp,mystat[ST_UID],mystat[ST_GID])
78 - os.chmod(myemp,mystat[ST_MODE])
79 + self.clear_dir(self.settings["kerncache_path"])
80
81
82 def purge(self):
83 @@ -113,3 +73,28 @@ class ClearBase(object):
84 print "clearing kerncache ..."
85 self.clear_kerncache()
86
87 +
88 + def clear_dir(self, myemp, mode=0755, chg_flags=False):
89 + '''Universal directory clearing function
90 + '''
91 + if not myemp:
92 + return False
93 + if os.path.isdir(myemp):
94 + print "Emptying directory" , myemp
95 + """
96 + stat the dir, delete the dir, recreate the dir and set
97 + the proper perms and ownership
98 + """
99 + try:
100 + mystat=os.stat(myemp)
101 + """ There's no easy way to change flags recursively in python """
102 + if chg_flags and os.uname()[0] == "FreeBSD":
103 + os.system("chflags -R noschg " + myemp)
104 + shutil.rmtree(myemp)
105 + ensure_dirs(myemp, mode=mode)
106 + os.chown(myemp,mystat[ST_UID],mystat[ST_GID])
107 + os.chmod(myemp,mystat[ST_MODE])
108 + except Exception as e:
109 + print CatalystError("clear_dir(); Exeption: %s" % str(e))
110 + return False
111 + return True