-
Notifications
You must be signed in to change notification settings - Fork 0
/
debian2edam
259 lines (220 loc) · 6.56 KB
/
debian2edam
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
#!/bin/bash -e
# A routine to facilitate the output to STDERR instead of the default STDIN
function STDERR () {
cat - 1>&2
}
# echoindent outputs a series of blanks to STDOUT. An optional
# second argument is echoed after those blanks if present.
function echoindent () {
for i in $(seq 1 $1)
do
echo -n " "
done
if [ "" != "$2" ]; then
echo $2
fi
}
level=0
# helper to properly close an open paranthesis
function closeParenthesis () {
level=$(($level-1))
echoindent $level
echo -n "}"
if [ -n "$1" ]; then
echo "# $1"
else
echo
fi
}
function echoTerm(){
level=$(($level-1))
echoindent $level
echo "{\"uri\": \"$1\", \"term\": \"Pippi Langstrumpf\"}"
}
# Key argument indicating the debian directory from which to retrieve all the
# information
pathToDebian=$1
#verbose="yes"
verbose=""
# Variable keeping usage information
USAGE=<<EOUSAGE
debian2edam [--upload] <path to 'debian' directory>
server=https://
Environment variables:
elixir_cat_username
elixir_cat_password
EOUSAGE
filename=$(basename "$pathToDebian")
if [ "edam" = "$filename" ]; then
pathToDebian=$(dirname "$pathToDebian") # upstream
pathToDebian=$(dirname "$pathToDebian") # debian
fi
if [ -z "$pathToDebian" ]; then
echo "$USAGE" | STDERR
echo "E: Please specify debian directory in which to find EDAM annotation." | STDERR
exit -1
fi
if [ ! -d "$pathToDebian" ]; then
echo "$USAGE" | STDERR
echo "E: Could not find directory '$pathToDebian'" | STDERR
exit -1
fi
if [ ! -r "$pathToDebian/changelog" ]; then
echo "$USAGE" | STDERR
echo "E: Could not find a changelog file expected at '$pathToDebian/changelog'" | STDERR
exit -1
fi
cd $(dirname "$pathToDebian")
edamfile="debian/upstream/edam"
if [ ! -r "$edamfile" ]; then
echo "$USAGE" | STDERR
echo "E: Could not access file '$edamfile' from $(pwd)" | STDERR
exit -1
fi
sourcepackage=$(dpkg-parsechangelog |grep ^Source | sed -e 's/`^Source: //' )
version=$(dpkg-parsechangelog |grep ^Version | cut -f2 -d\ | sed -e 's/-[^-][^-]*//' )
declare -a descriptions
declare -a packages
if [ -n "$debug" ]; then cat debian/control; fi
while read pack; do
p=$(echo "$pack"|sed -e 's/^[^:]*: *//')
echo Package: $p
packages[${#packages[*]}]="$p"
done < <(grep "^Package:" debian/control )
while read desc; do
d=$(echo "$desc"|sed -e 's/^[^:]*: *//')
echo Description: $d
descriptions[${#descriptions[*]}]="$d"
#descriptions[1]="$d"
#descriptions="$d"
done < <(grep "^Description:" debian/control )
#echo "DESCRIPTIONS: ${descriptions[*]}"
#echo "PACKAGES: ${packages[*]}"
#echo "DESCRIPTIONS: $descriptions}"
#echo "PACKAGES: $packages"
if [ ${#packages[*]} != ${#descriptions[*]} ]; then
echo "E: Internal error - expected same number of packages (${#packagesp[*]}) as for their descriptions (${#descriptions[*]})" | STDERR
exit -1
fi
(
if [ -n "$verbose" ]; then
for packageno in $(seq 0 ${#descriptions[*]})
do
echo "# $packageno"
echo Packages[$packageno]: ${packages[$packageno]}
echo Descriptions[$packageno]: ${descriptions[$packageno]}
done
fi
) | STDERR
prevstate="start";
previndent=0
currentscope=""
currenttopic=""
opentopic=0
openfunction=0
openscope=0
indentlen=0
# Core part of the program
# It reads every line of the EDAM file (see end of loop for the redirection)
# and decides what to print to STDOUT.
while IFS='' read -r line
do
if [ -z "$line" ]; then
echo "Read empty line"
continue
fi
if [ -n "$verbose" ]; then
echo "line: '$line'" | STDERR
fi
# retrieve different parts of the description
blanks=$(echo "$line"|sed -e 's/^\( *\)\([^ :]\+\): *\([^ ]\+\).*$/\1/')
type=$(echo "$line"|sed -e 's/^\( *\)\([^ :]\+\): *\([^ ]\+\).*$/\2/')
val=$(echo "$line"|sed -e 's/^\( *\)\([^ :]\+\): *\([^ ]\+\).*$/\3/')
if echo "$val" | grep -q : ; then
echo "W: found colon in ID of line '$line' - transscribing to underscore" | STDERR
val=$(echo "$val"|tr ":" "_")
fi
#echo "Indent='$blanks'"
#echo "Indentlength='$indentlen'"
#echo "Type='$type'"
#echo "Val='$val'"
if [ -n "$currentscope" -a "*" != "$currentscope" -a "summary" != "$currentscope" -a "scope" != "$type" ]; then
echo "I: Wrong scope ($currentscope) - ignored '$line'" | STDERR
continue
fi
indentlen=${#blanks}
if [ "scope" = "$type" ]; then
if [ $openfunction -gt 0 ]; then closeParenthesis "openfunction($openfunction) in scope"; fi
currentscope="$val"
resourcename=$sourcepackage
if [ "*"!=$val -a "summary"!="$val" ];then
resourcename=$val
fi
if [ "summary" != "$val" -a "*" != "$val" ]; then
echo "I: treatment of multiple scopes not yet implemented" | STDERR
else
echo "{"
# Some decent comparison of package names with scope is not implemented
level=$((level+1))
echoindent
echo "Package $resourcename"
echoindent
echo "\"version\": \"$version\","
echoindent
echo "\"description\": \"${descriptions[0]}\","
echoindent
echo "\"topic\": \"{$currenttopic}\""
openscope=1
fi
elif [ "topic" = "$type" ]; then
if [ $openfunction -gt 0 ]; then closeParenthesis "openfunction($openfunction) in topic"; openfunction=0; fi
if [ $openscope -gt 0 ]; then closeParenthesis "openscope($openscope) after loop"; openscope=0; fi
if [ "start" != "$prevstate" ]; then
closeParenthesis "topic with prior state - weird"
fi
currenttopic="$val"
# at some laterimplementation point, bits generated here would be cached and then distributed
# to various lower-level scopes
elif [ "function" = "$type" ]; then
if [ $openfunction -gt 0 ]; then
closeParenthesis "openfunction($openfunction) in function"
openfunction=0
fi
echoindent $level
echo "{function: [ { \"functionName\": ["
echoTerm $val
echo "] }],"
level=$((level+1))
openfunction=1
elif [ "input" = "$type" -o "output" = "$type" ]; then
if [ $prevstate = $type ]; then
echo "},{"
fi
if [ $prevstate = 'function' ]; then
echo "\"$type\": [{"
fi
echoindent $level
echo "($type $val)"
else
echo "W: unknown type '$type' - ignored" | STDERR
fi
prevstate=$type
#echo "indentlen='$indentlen'"
done < $edamfile
if [ $openfunction -gt 0 ]; then
closeParenthesis "openfunction($openfunction) after loop"
openfunction=0
fi
if [ $openscope -gt 0 ]; then
#echo "I: treatment of multiple scopes not yet implemented"|STDERR
closeParenthesis "openscope($openscope) after loop"
openscope=0
fi
#echo "indentlen='$indentlen'" | STDERR
if [ $opentopic -gt 0 ]; then
opentopic=0
fi
#for i in $(seq $(($indentlen-$openfunction-$openscope-$opentopic)) -1 1)
#do
# closeParenthesis "indent $i"
#done