hwloc-compress-dir 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. #!/bin/sh
  2. #-*-sh-*-
  3. #
  4. # Copyright © 2013-2021 Inria. All rights reserved.
  5. # See COPYING in top-level directory.
  6. #
  7. HWLOC_VERSION="2.9.3"
  8. prefix="/d/bld/libhwloc_1694532365898/_h_env/Library"
  9. exec_prefix="${prefix}"
  10. bindir="${exec_prefix}/bin"
  11. # this will be changed into $bindir/... during make install
  12. localhwlocdiff="$bindir/hwloc-diff"
  13. localhwlocpatch="$bindir/hwloc-patch"
  14. verbose=0
  15. reverse=0
  16. error()
  17. {
  18. echo $@ 2>&1
  19. }
  20. usage()
  21. {
  22. echo `basename $0`" [options] <inputdir> <outputdir>"
  23. echo " Compress topologies from <inputdir> into <outputdir>"
  24. echo "Options:"
  25. echo " -R --reverse Uncompress instead of compressing"
  26. echo " -v --verbose Display verbose messages"
  27. echo " --version Report version and exit"
  28. echo " -h --help Show this usage"
  29. }
  30. while test $# -gt 0 ; do
  31. case "$1" in
  32. -R|--reverse)
  33. reverse=1
  34. ;;
  35. -v|--verbose)
  36. verbose=1
  37. ;;
  38. --version)
  39. echo `basename $0`" $HWLOC_VERSION"
  40. exit 0
  41. ;;
  42. -h|--help)
  43. usage
  44. exit 0
  45. ;;
  46. -*)
  47. error "Unrecognized option: $1"
  48. usage
  49. exit 1
  50. ;;
  51. *)
  52. break
  53. ;;
  54. esac
  55. shift
  56. done
  57. if test $# -lt 2 ; then
  58. usage
  59. exit 1
  60. fi
  61. inputdir="$1"
  62. test x`echo $inputdir | sed -e 's/^\///'` = x$inputdir && inputdir="$PWD/$inputdir"
  63. outputdir="$2"
  64. test x`echo $outputdir | sed -e 's/^\///'` = x$outputdir && outputdir="$PWD/$outputdir"
  65. if ! cd "$outputdir" ; then
  66. echo "Cannot enter output directory $outputdir"
  67. exit 1
  68. fi
  69. if test x$reverse = x0; then
  70. # compress
  71. alreadycompressed=0
  72. alreadynoncompressed=0
  73. newlycompressed=0
  74. newlynoncompressed=0
  75. inputs=`ls -1 "$inputdir"`
  76. for input in $inputs ; do
  77. name=`echo $input | sed -e 's/.xml$//'`
  78. if test "x${name}.xml" != "x$input"; then
  79. test x$verbose = x1 && echo "Ignoring non-XML file $input"
  80. continue
  81. fi
  82. if test -f "$outputdir/${name}.xml" ; then
  83. test x$verbose = x1 && echo "$name already non-compressed, skipping"
  84. alreadynoncompressed=`expr $alreadynoncompressed + 1`
  85. continue
  86. fi
  87. if test -f "$outputdir/${name}.diff.xml" ; then
  88. test x$verbose = x1 && echo "$name already compressed, skipping"
  89. alreadycompressed=`expr $alreadycompressed + 1`
  90. continue
  91. fi
  92. found=
  93. outputs=`ls -1 "$outputdir"`
  94. for output in $outputs ; do
  95. outputname=`echo $output | sed -e 's/.xml$//' | sed -e 's/.diff$//'`
  96. test -f "${outputdir}/${outputname}.diff.xml" && continue
  97. if $localhwlocdiff "$outputdir/${outputname}.xml" "$inputdir/${name}.xml" "$outputdir/${name}.diff.xml" >/dev/null 2>/dev/null; then
  98. echo "Compressed $name on top of $outputname"
  99. newlycompressed=`expr $newlycompressed + 1`
  100. found=1
  101. break
  102. fi
  103. done
  104. if test x$found = x ; then
  105. echo "Could not compress $name, keeping non-compressed"
  106. newlynoncompressed=`expr $newlynoncompressed + 1`
  107. cp "$inputdir/${name}.xml" "$outputdir/${name}.xml"
  108. fi
  109. done
  110. echo "Compressed $newlycompressed new topologies ($alreadycompressed were already compressed)"
  111. echo "Kept $newlynoncompressed new topologies non-compressed ($alreadynoncompressed were already non-compressed)"
  112. else
  113. # uncompress
  114. newlyuncompressed=0
  115. newlynoncompressed=0
  116. alreadyuncompressed=0
  117. inputs=`ls -1 "$inputdir"`
  118. for input in $inputs ; do
  119. name=`echo $input | sed -e 's/.xml$//' | sed -e 's/.diff$//'`
  120. if test "x${name}.xml" != "x$input" -a "x${name}.diff.xml" != "x$input"; then
  121. test x$verbose = x1 && echo "Ignoring non-XML and non-diff-XML file $input"
  122. continue
  123. fi
  124. if test -f "$outputdir/${name}.xml" ; then
  125. test x$verbose = x1 && echo "$name already uncompressed, skipping"
  126. alreadyuncompressed=`expr $alreadyuncompressed + 1`
  127. continue
  128. fi
  129. if test "x${name}.xml" = "x$input"; then
  130. # non-compressed
  131. cp "$inputdir/${name}.xml" "$outputdir/${name}.xml"
  132. echo "Copied $name, wasn't compressed"
  133. newlynoncompressed=`expr $newlynoncompressed + 1`
  134. else
  135. # compressed
  136. if (cd $outputdir && $localhwlocpatch refname "$inputdir/${name}.diff.xml" "${name}.xml"); then
  137. echo "Uncompressed $name"
  138. newlyuncompressed=`expr $newlyuncompressed + 1`
  139. else
  140. echo "Failed to uncompress $inputdir/${name}.diff.xml" 1>&2
  141. fi
  142. fi
  143. done
  144. echo "Uncompressed $newlyuncompressed new topologies, copied $newlynoncompressed non-compressed topologies ($alreadyuncompressed were already uncompressed)"
  145. fi