-
Notifications
You must be signed in to change notification settings - Fork 12
/
configure.sh
executable file
·47 lines (45 loc) · 1.42 KB
/
configure.sh
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
#!/bin/bash
if [ "$#" -ne 1 ];then
echo "Must have only one argument, either --dev or --release."
exit
fi
EXT=py
cd osc_tui
if [ "$1" == "--dev" ];then
# All imports of files from the projects have to be direct.
# no more "from osc_tui import ...".
for i in *; do
if [ "${i}" != "${i%.${EXT}}" ];then
# Replace all "from osc_tui " by "".
# Write to a tmp file.
sed 's/from osc_tui //g' "$i" > "$i"tmp
# Remove the old file.
rm "$i"
# Move the tmp file instead.
mv "$i"tmp "$i"
fi
done
elif [ "$1" == "--release" ];then
# All imports have to come from osc_tui.
# So we add "from osc_tui before all imports from the projects."
for i in *; do
if [ "${i}" != "${i%.${EXT}}" ];then
# Get a list of all directs imports. Not beginning by "from".
imports=$(grep -v "from" $i | grep import | awk '{print $2}')
count=0
for import in $imports
do
# For each import, if it is an osc_tui's python file,
# we do the replacement job.
if test -f "$import".py; then
sed "s/^import "$import"$/from osc_tui import "$import"/g" "$i" > "$i"tmp
rm "$i"
mv "$i"tmp "$i"
fi
done
fi
done
else
echo "Must have only one argument, either --dev or --release."
exit
fi