-
Notifications
You must be signed in to change notification settings - Fork 168
/
hwloc-compress-dir.in
170 lines (145 loc) · 4.3 KB
/
hwloc-compress-dir.in
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#!/bin/sh
#-*-sh-*-
#
# Copyright © 2013-2021 Inria. All rights reserved.
# See COPYING in top-level directory.
#
HWLOC_VERSION="@HWLOC_VERSION@"
HWLOC_top_builddir="@HWLOC_top_builddir@"
prefix="@prefix@"
exec_prefix="@exec_prefix@"
bindir="@bindir@"
# this will be changed into $bindir/... during make install
localhwlocdiff="$HWLOC_top_builddir/utils/hwloc/hwloc-diff"
localhwlocpatch="$HWLOC_top_builddir/utils/hwloc/hwloc-patch"
verbose=0
reverse=0
error()
{
echo $@ 2>&1
}
usage()
{
echo `basename $0`" [options] <inputdir> <outputdir>"
echo " Compress topologies from <inputdir> into <outputdir>"
echo "Options:"
echo " -R --reverse Uncompress instead of compressing"
echo " -v --verbose Display verbose messages"
echo " --version Report version and exit"
}
while test $# -gt 0 ; do
case "$1" in
-R|--reverse)
reverse=1
;;
-v|--verbose)
verbose=1
;;
--version)
echo `basename $0`" $HWLOC_VERSION"
exit 0
;;
-h|--help)
usage
exit 0
;;
-*)
error "Unrecognized option: $1"
usage
exit 1
;;
*)
break
;;
esac
shift
done
if test $# -lt 2 ; then
usage
exit 1
fi
inputdir="$1"
test x`echo $inputdir | sed -e 's/^\///'` = x$inputdir && inputdir="$PWD/$inputdir"
outputdir="$2"
test x`echo $outputdir | sed -e 's/^\///'` = x$outputdir && outputdir="$PWD/$outputdir"
if ! cd "$outputdir" ; then
echo "Cannot enter output directory $outputdir"
exit 1
fi
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
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
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