]> xenbits.xensource.com Git - people/andrewcoop/hwloc.git/commitdiff
hwloc-compress-dir: allow to uncompress with -R
authorBrice Goglin <Brice.Goglin@inria.fr>
Thu, 17 Oct 2013 14:40:10 +0000 (16:40 +0200)
committerBrice Goglin <Brice.Goglin@inria.fr>
Thu, 17 Oct 2013 14:40:14 +0000 (16:40 +0200)
Modify the test case a bit because the input XMLs weren't totally perfect.

utils/hwloc-compress-dir.1in
utils/hwloc-compress-dir.in
utils/test-hwloc-compress-dir.input.tar.gz
utils/test-hwloc-compress-dir.output.tar.gz
utils/test-hwloc-compress-dir.sh.in

index 982178d12800509e222eefe00161d6f2f06f5492..ea678766d94e3f78f1e7530a70bd2927d6cc4fcf 100644 (file)
@@ -20,6 +20,9 @@ hwloc-compress-dir \- Compress a directory of XML topologies
 .\" **************************
 .SH OPTIONS
 .TP
+\fB\-R \-\-reverse\fR
+Uncompress a previously compressed directory.
+.TP
 \fB\-v \-\-verbose\fR
 Display verbose messages.
 .
index 5712c31aef4818b6f35d5c9c1859ee85700f926d..cb9b4b554c217ac6d9329b0b3635824f3bcbfd0d 100755 (executable)
@@ -10,10 +10,12 @@ HWLOC_top_builddir="@HWLOC_top_builddir@"
 prefix="@prefix@"
 exec_prefix="@exec_prefix@"
 bindir="@bindir@"
-# this will be changed into $bindir/lstopo during make install
+# this will be changed into $bindir/... during make install
 localhwlocdiff="$HWLOC_top_builddir/utils/hwloc-diff"
+localhwlocpatch="$HWLOC_top_builddir/utils/hwloc-patch"
 
 verbose=0
+reverse=0
 
 error()
 {
@@ -25,11 +27,15 @@ usage()
        echo "$0 [options] <inputdir> <outputdir>"
        echo "  Compress topologies from <inputdir> into <outputdir>"
        echo "Options:"
-       echo "  -v --verbose            Display verbose messages"
+       echo "  -R --reverse        Uncompress instead of compressing"
+       echo "  -v --verbose        Display verbose messages"
 }
 
 while test $# -gt 2 ; do
        case "$1" in
+       -R|--reverse)
+               reverse=1
+               ;;
        -v|--verbose)
                verbose=1
                ;;
@@ -61,50 +67,95 @@ if ! cd "$outputdir" ; then
     exit 1
 fi
 
-alreadycompressed=0
-alreadynoncompressed=0
-newlycompressed=0
-newlynoncompressed=0
-
-inputs=`ls -1 "$inputdir"`
-for input in $inputs ; do
-    name=`echo $input | sed -e 's/.xml$//'`
-
-    if test "x${name}.xml" != "x$input"; then
-       test x$verbose = x1 && echo "Ignoring non-XML file $input"
-       continue
-    fi
-    if test -f "$outputdir/${name}.xml" ; then
-       test x$verbose = x1 && echo "$name already non-compressed, skipping"
-       alreadynoncompressed=`expr $alreadynoncompressed + 1`
-       continue
-    fi
-    if test -f  "$outputdir/${name}.diff.xml" ; then
-       test x$verbose = x1 && echo "$name already compressed, skipping"
-       alreadycompressed=`expr $alreadycompressed + 1`
-       continue
-    fi
-
-    found=
-    outputs=`ls -1 "$outputdir"`
-    for output in $outputs ; do
-       outputname=`echo $output | sed -e 's/.xml$//' | sed -e 's/.diff$//'`
-       test -f "${outputdir}/${outputname}.diff.xml" && continue
-
-       if $localhwlocdiff "$outputdir/${outputname}.xml" "$inputdir/${name}.xml" "$outputdir/${name}.diff.xml" >/dev/null 2>/dev/null; then
-           echo "Compressed $name on top of $outputname"
-           newlycompressed=`expr $newlycompressed + 1`
-           found=1
-           break
+if test x$reverse = x0; then
+    # compress
+
+    alreadycompressed=0
+    alreadynoncompressed=0
+    newlycompressed=0
+    newlynoncompressed=0
+
+    inputs=`ls -1 "$inputdir"`
+    for input in $inputs ; do
+       name=`echo $input | sed -e 's/.xml$//'`
+
+       if test "x${name}.xml" != "x$input"; then
+           test x$verbose = x1 && echo "Ignoring non-XML file $input"
+           continue
+       fi
+       if test -f "$outputdir/${name}.xml" ; then
+           test x$verbose = x1 && echo "$name already non-compressed, skipping"
+           alreadynoncompressed=`expr $alreadynoncompressed + 1`
+           continue
+       fi
+       if test -f  "$outputdir/${name}.diff.xml" ; then
+           test x$verbose = x1 && echo "$name already compressed, skipping"
+           alreadycompressed=`expr $alreadycompressed + 1`
+           continue
+       fi
+
+       found=
+       outputs=`ls -1 "$outputdir"`
+       for output in $outputs ; do
+           outputname=`echo $output | sed -e 's/.xml$//' | sed -e 's/.diff$//'`
+           test -f "${outputdir}/${outputname}.diff.xml" && continue
+
+           if $localhwlocdiff "$outputdir/${outputname}.xml" "$inputdir/${name}.xml" "$outputdir/${name}.diff.xml" >/dev/null 2>/dev/null; then
+               echo "Compressed $name on top of $outputname"
+               newlycompressed=`expr $newlycompressed + 1`
+               found=1
+               break
+           fi
+       done
+
+       if test x$found = x ; then
+           echo "Could not compress $name, keeping non-compressed"
+           newlynoncompressed=`expr $newlynoncompressed + 1`
+           cp "$inputdir/${name}.xml" "$outputdir/${name}.xml"
        fi
     done
 
-    if test x$found = x ; then
-       echo "Could not compress $name, keeping non-compressed"
-       newlynoncompressed=`expr $newlynoncompressed + 1`
-       cp "$inputdir/${name}.xml" "$outputdir/${name}.xml"
-    fi
-done
+    echo "Compressed $newlycompressed new topologies ($alreadycompressed were already compressed)"
+    echo "Kept $newlynoncompressed new topologies non-compressed ($alreadynoncompressed were already non-compressed)"
+
+else
+    # uncompress
+
+    newlyuncompressed=0
+    newlynoncompressed=0
+    alreadyuncompressed=0
 
-echo "Compressed $newlycompressed new topologies ($alreadycompressed were already compressed)"
-echo "Kept $newlynoncompressed new topologies non-compressed ($alreadynoncompressed were already non-compressed)"
+    inputs=`ls -1 "$inputdir"`
+    for input in $inputs ; do
+
+       name=`echo $input | sed -e 's/.xml$//' | sed -e 's/.diff$//'`
+
+       if test "x${name}.xml" != "x$input" -a "x${name}.diff.xml" != "x$input"; then
+           test x$verbose = x1 && echo "Ignoring non-XML and non-diff-XML file $input"
+           continue
+       fi
+       if test -f "$outputdir/${name}.xml" ; then
+           test x$verbose = x1 && echo "$name already uncompressed, skipping"
+           alreadyuncompressed=`expr $alreadyuncompressed + 1`
+           continue
+       fi
+
+       if test "x${name}.xml" = "x$input"; then
+           # non-compressed
+           cp "$inputdir/${name}.xml" "$outputdir/${name}.xml"
+           echo "Copied $name, wasn't compressed"
+           newlynoncompressed=`expr $newlynoncompressed + 1`
+       else
+           # compressed
+           if (cd $outputdir && $localhwlocpatch refname "$inputdir/${name}.diff.xml" "${name}.xml"); then
+               echo "Uncompressed $name"
+               newlyuncompressed=`expr $newlyuncompressed + 1`
+           else
+               echo "Failed to uncompress $inputdir/${name}.diff.xml" 1>&2
+           fi
+       fi
+    done
+
+    echo "Uncompressed $newlyuncompressed new topologies, copied $newlynoncompressed non-compressed topologies ($alreadyuncompressed were already uncompressed)"
+
+fi
index 2d70a72ba3d759799eaf4b33dd636b20389b9ea6..5e34c7830bd4191dea2f9d75774aadedab75082f 100644 (file)
Binary files a/utils/test-hwloc-compress-dir.input.tar.gz and b/utils/test-hwloc-compress-dir.input.tar.gz differ
index 697590efc29e7403def30f3f8e74aa6f82de554f..6678428d3fa5f6d4abdb2759644bff81de39497f 100644 (file)
Binary files a/utils/test-hwloc-compress-dir.output.tar.gz and b/utils/test-hwloc-compress-dir.output.tar.gz differ
index 578f13236e8a34f56b2eb34d207eeed20a841530..748e89181ba1b6c5f1835b2b31459e6d7dedccf4 100755 (executable)
@@ -36,9 +36,14 @@ set -e
 (cd "$tmp" && gunzip -c $HWLOC_top_srcdir/utils/test-hwloc-compress-dir.input.tar.gz | tar xf -)
 (cd "$tmp" && gunzip -c $HWLOC_top_srcdir/utils/test-hwloc-compress-dir.output.tar.gz | tar xf -)
 (cd "$tmp" && mkdir test-hwloc-compress-dir.newoutput)
+(cd "$tmp" && mkdir test-hwloc-compress-dir.newoutput2)
 
 $compress "$tmp/test-hwloc-compress-dir.input" "$tmp/test-hwloc-compress-dir.newoutput"
 
 diff @HWLOC_DIFF_U@ -r "$tmp/test-hwloc-compress-dir.output" "$tmp/test-hwloc-compress-dir.newoutput"
 
+$compress -R "$tmp/test-hwloc-compress-dir.newoutput" "$tmp/test-hwloc-compress-dir.newoutput2"
+
+diff @HWLOC_DIFF_U@ -r "$tmp/test-hwloc-compress-dir.input" "$tmp/test-hwloc-compress-dir.newoutput2"
+
 rm -rf "$tmp"