Add a rm -rf utility function and use it in packaged-staging.bbclass
authorChris Larson <chris_larson@mentor.com>
Tue, 8 Jun 2010 23:14:37 +0000 (16:14 -0700)
committerChris Larson <chris_larson@mentor.com>
Thu, 10 Jun 2010 18:35:00 +0000 (11:35 -0700)
Signed-off-by: Chris Larson <chris_larson@mentor.com>
classes/packaged-staging.bbclass
lib/oe/path.py

index ac5cec2..8a98940 100644 (file)
@@ -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:
index 8902951..a145456 100644 (file)
@@ -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