[oe-commits] Chris Larson : Add a rm -rf utility function and use it in packaged-staging .bbclass

git version control git at git.openembedded.org
Thu Jun 10 18:35:15 UTC 2010


Module: openembedded.git
Branch: org.openembedded.dev
Commit: 2959eb8c60df3b7ea1833238f9eac05cdafe1c06
URL:    http://gitweb.openembedded.net/?p=openembedded.git&a=commit;h=2959eb8c60df3b7ea1833238f9eac05cdafe1c06

Author: Chris Larson <chris_larson at mentor.com>
Date:   Tue Jun  8 16:14:37 2010 -0700

Add a rm -rf utility function and use it in packaged-staging.bbclass

Signed-off-by: Chris Larson <chris_larson at mentor.com>

---

 classes/packaged-staging.bbclass |   33 +++++++++++----------------------
 lib/oe/path.py                   |   11 +++++++++++
 2 files changed, 22 insertions(+), 22 deletions(-)

diff --git a/classes/packaged-staging.bbclass b/classes/packaged-staging.bbclass
index ac5cec2..8a98940 100644
--- a/classes/packaged-staging.bbclass
+++ b/classes/packaged-staging.bbclass
@@ -28,16 +28,6 @@ PSTAGE_NATIVEDEPENDS = "\
 
 BB_STAMP_WHITELIST = "${PSTAGE_NATIVEDEPENDS}"
 
-def _package_unlink (f):
-    import os, errno
-    try:
-	os.unlink(f)
-	return True
-    except OSError, e:
-	if e.errno == errno.ENOENT:
-	    return False
-	raise
-
 python () {
     pstage_allowed = True
 
@@ -106,7 +96,7 @@ def pstage_manualclean(srcname, destvarname, d):
 			if (file == "staging.lock"):
 				continue
 			filepath = os.path.join(walkroot, file).replace(src, dest)
-			_package_unlink(filepath)
+			oe.path.remove(filepath)
 
 def pstage_set_pkgmanager(d):
     path = bb.data.getVar("PATH", d, 1)
@@ -148,10 +138,10 @@ do_clean_prepend() {
 	pstage_cleanpackage(removepkg, d)
 
 	stagepkg = bb.data.expand("${PSTAGE_PKG}", d)
-	bb.note("Removing staging package %s" % base_path_out(stagepkg, d))
-	# Add a wildcard to the end of stagepkg to also get its md5
-    # if it's a fetched package
-	os.system('rm -rf ' + stagepkg + '*')
+	if os.path.exists(stagepkg):
+		bb.note("Removing staging package %s" % base_path_out(stagepkg, d))
+	oe.path.remove(stagepkg)
+	oe.path.remove(stagepkg + ".md5")
 }
 
 staging_helper () {
@@ -270,10 +260,9 @@ python packagestage_scenefunc () {
         # Remove the stamps and files we added above
         # FIXME - we should really only remove the stamps we added
 	for fname in glob.glob(stamp + '.*'):
-	    _package_unlink(fname)
-
-        os.system(bb.data.expand("rm -rf ${WORKDIR}/tstage", d))
+	    oe.path.remove(fname)
 
+        oe.path.remove(bb.data.expand("${WORKDIR}/tstage", d))
         if stageok:
             bb.note("Staging package found, using it for %s." % file)
             installcmd = bb.data.getVar("PSTAGE_INSTALL_CMD", d, 1)
@@ -305,9 +294,9 @@ python packagedstage_stampfixing_eventhandler() {
                     # We're targetting a task which was skipped with packaged staging
                     # so we need to remove the autogenerated stamps.
                     for task in taskscovered:
-                        dir = "%s.do_%s" % (e.stampPrefix[fn], task)
-			_package_unlink(dir)
-		    _package_unlink(stamp)
+                        covered = "%s.do_%s" % (e.stampPrefix[fn], task)
+			oe.path.remove(covered)
+		    oe.path.remove(stamp)
 }
 
 populate_sysroot_preamble () {
@@ -417,7 +406,7 @@ python staging_package_libtoolhack () {
             fixmefd = open(fixmefn,"r")
             fixmefiles = fixmefd.readlines()
             fixmefd.close()
-            os.system('rm -f ' + fixmefn)
+            oe.path.remove(fixmefn)
             for file in fixmefiles:
                 os.system("sed -i -e s:FIXMESTAGINGDIR:%s:g %s" % (staging, tmpdir + '/' + file))
         except IOError:
diff --git a/lib/oe/path.py b/lib/oe/path.py
index 8902951..a145456 100644
--- a/lib/oe/path.py
+++ b/lib/oe/path.py
@@ -42,3 +42,14 @@ def format_display(path, metadata):
         return path
     else:
         return rel
+
+def remove(path):
+    """Equivalent to rm -f or rm -rf"""
+    import os, errno, shutil
+    try:
+        os.unlink(path)
+    except OSError, exc:
+        if exc.errno == errno.EISDIR:
+            shutil.rmtree(path)
+        elif exc.errno != errno.ENOENT:
+            raise





More information about the Openembedded-commits mailing list