-
Notifications
You must be signed in to change notification settings - Fork 3
/
slacheckattr
120 lines (103 loc) · 2.94 KB
/
slacheckattr
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
#!/bin/bash
# mais quand il y a des options ça décale...
# echo "$0 $1.sla <$2 $3=$4> ($5)"
#
# use : slacheckattr slafile tag attribute value [comment]
# Checks the the value of some attribute for a specified tag in scribus file
#
# todo : update value of an attribute with slasetattr
. shellcolors
action='donttouchsla'
while [ "$stopoptions" = "" ]
do
case $1 in
"-h" | "-?" )
shift
echo Usage : slacheckattr [-h] [-v] [-all] slafile tag attribute value [comment]
echo Action : looks in \'slafile\'.SLA for \'tag\'\'s \'attribute\' value
echo and issues a warning begining with \'comment\' when the found value is different than \'value\'.
echo Options :
echo -h, -? : display this help
echo -v : verbose
echo -all : all 'tag' tags should be checked and have the same stated attribute value.
echo "(-all option is required to check PAGE attributes, since there are many PAGEs in a document.)"
echo -get : echoes the found value
echo "-set : will set tags in the sla file to the required value in case they are wrong (.bak are created)"
exit
;;
"-v")
shift
verbose=oui
;;
"-all")
shift
all=oui
;;
"-get")
shift
get=oui
;;
"-set")
shift
action='-set'
;;
*) stopoptions=true ;;
esac
done
if [ $# -lt 3 ]
then
echo -e "${ESC_error} in slacheckattr : missing document, tag or attribute parameter\(s\). See with -h option first.$ESC_normal"
exit
fi
if [ "$4" = "" ] && [ "$get" = "" ]
then
echo -e "${ESC_error} in slacheckattr : missing value parameter\(s\). See with -h option first.$ESC_normal"
exit
fi
# ext=${filename##*\.} donne l'extension si on voulait gérer $1 "avec ou sans" extension SLA
if [ ! -f "$1.sla" ]
then
echo -e "${ESC_error} in slacheckattr : file \"$3\" doesn't exist$ESC_normal"
exit
fi
# found=`xmllint --xpath "//$2/@$3" "$1.sla" | sed -e 's/^ *//' -e 's/ *$//'`
found=`xmllint --xpath "//$2/@$3" "$1.sla" | strtrim`
expected="$3=\"$4\""
if [ "$verbose" = "oui" ]
then
echo \* In $1.sla, check whether \<$2 $expected
echo \* xmllint renvoie `xmllint --xpath "//$2/@$3" "$1.sla"`
echo \* Found : $found
fi
wrong=false
if [ "$found" = "" ]
then
echo -e "${ESC_error}\<$2 $3=\"$4\" not found in $1.sla \(xmllint renvoie `xmllint --xpath "//$2/@$3" $1.sla`\)$ESC_normal"
exit
elif [ "$all" = "oui" ]
then
for one in $found
do
if [ "$verbose" = "oui" ]
then echo found : $one
fi
if [ $one != $expected ]
then
echo -e "${ESC_error}$3 NOT OK ! In $1.sla, found \<$2 $one\>$ESC_normal"
wrong="true"
fi
done
if [ $wrong = "true" ]
then
echo -e "${ESC_error} (expected value is $expected)$ESC_normal"
fi
elif [ "$found" != "$expected" ]
then
echo -e "${ESC_error}$3 NOT OK ! In $1.sla, found <$2 `xmllint --xpath "//$2/@$3" "$1.sla"`\> (expected value for $3 is $4)$ESC_normal"
wrong=true
fi
if [ "$action" = "-set" -a "$wrong" = "true" ]
then
echo -e "${ESC_warning}SLA file will be altered so it checks config${ESC_normal}"
slasetattr "$1" "$2" "$3" "$4"
fi